diff --git a/ide/c.google.gson/build.xml b/ide/c.google.gson/build.xml new file mode 100644 index 000000000000..85cd7c905428 --- /dev/null +++ b/ide/c.google.gson/build.xml @@ -0,0 +1,25 @@ + + + + + + \ No newline at end of file diff --git a/ide/c.google.gson/external/binaries-list b/ide/c.google.gson/external/binaries-list new file mode 100644 index 000000000000..2a9ea93cf0f3 --- /dev/null +++ b/ide/c.google.gson/external/binaries-list @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +751F548C85FA49F330CECBB1875893F971B33C4E com.google.code.gson:gson:2.7 diff --git a/ide/c.google.gson/external/gson-2.7-license.txt b/ide/c.google.gson/external/gson-2.7-license.txt new file mode 100644 index 000000000000..d8c388518b46 --- /dev/null +++ b/ide/c.google.gson/external/gson-2.7-license.txt @@ -0,0 +1,207 @@ +Name: GSon +Description: JSon serialization/deserialization library +Origin: GitHub +Version: 2.7 +License: Apache-2.0 + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ide/c.google.gson/manifest.mf b/ide/c.google.gson/manifest.mf new file mode 100644 index 000000000000..d7be9782ae3a --- /dev/null +++ b/ide/c.google.gson/manifest.mf @@ -0,0 +1 @@ +OpenIDE-Module: com.google.gson diff --git a/ide/c.google.gson/nbproject/project.properties b/ide/c.google.gson/nbproject/project.properties new file mode 100644 index 000000000000..3711b8b23300 --- /dev/null +++ b/ide/c.google.gson/nbproject/project.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +release.external/gson-2.7.jar=modules/com-google-gson.jar +is.autoload=true +nbm.module.author=Jan Lahoda diff --git a/ide/c.google.gson/nbproject/project.xml b/ide/c.google.gson/nbproject/project.xml new file mode 100644 index 000000000000..6a98f49b13b2 --- /dev/null +++ b/ide/c.google.gson/nbproject/project.xml @@ -0,0 +1,35 @@ + + + + org.netbeans.modules.apisupport.project + + + com.google.gson + + + + com-google-gson.jar + external/gson-2.7.jar + + + + \ No newline at end of file diff --git a/ide/lsp.client/arch.xml b/ide/lsp.client/arch.xml new file mode 100644 index 000000000000..5e8e91c72cad --- /dev/null +++ b/ide/lsp.client/arch.xml @@ -0,0 +1,1109 @@ + + + +]> + + + + &api-questions; + + + + +

+ A client for the Language Server Protocol. + Language servers can be registered + using org.netbeans.modules.lsp.client.spi.LanguageServerProvider. + +

+
+ + + + + +

+ Manual tests. +

+
+ + + + + +

+ Unclear. +

+
+ + + + + +

+ + To implement a plugin that binds a language server to NetBeans, implement + org.netbeans.modules.lsp.client.spi.LanguageServerProvider and register it + to MimeLookup using @MimeRegistration. + +

+
+ + + + + +

+ A client for the Language Server Protocol. Servers can either be connected to + it manually, or using a plugin. +

+
+ + + + + + + + + + + + +

+ No. +

+
+ + + + + +

+ Yes. +

+
+ + + + + +

+ Implements the Language Server Protocol. + The implementation is not complete at this time. +

+
+ + + + + +

+ Coexistence is not likely. No settings. +

+
+ + + + + +

+ JRE 8+ +

+
+ + + + + +

+ JRE +

+
+ + + + + + + + + + + + +

+ The LSP4J library, which itself depends on Guava and GSon. +

+
+ + + + + +

+ Any supported platform. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ This module encloses the LSP4J library. +

+
+ + + + + +

+ Yes. +

+
+ + + + + +

+ Yes. +

+
+ + + + + +

+ Both places. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ Not directly from this module, but clients of this SPI are expected to launch + a process as a language server. It is up to them to ensure this works on all + platforms. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ The SPI can be called from any thread, except AWT Event Dispatch Thread. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ The Language Server Protocol. +

+
+ + + + + +

+ Yes, Lookup and MimeLookup. +

+
+ + + + + +

+ Yes. A NavigatorPanel.DynamicRegistration is registered to the global Lookup. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ Possibly yes, stopping any remote running servers. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ Not known. +

+
+ + + + + +

+ Excessive memory consumption is not expected. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ Clients of this module are expected to start a language server that will run + for a long time. +

+
+ + + + + +

+ The performance of the attached language server and the throughput and latency + of the communication channel affect the performance of the language support. +

+
+ + + + + +

+ No enforcement. +

+
+ + + + + +

+ A listeners that listens on all editors is installed on startup. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ Yes, to convert a user-provided String to a FileObject. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ +
diff --git a/ide/lsp.client/build.xml b/ide/lsp.client/build.xml new file mode 100644 index 000000000000..4e726a2fcdce --- /dev/null +++ b/ide/lsp.client/build.xml @@ -0,0 +1,25 @@ + + + + Builds, tests, and runs the project org.netbeans.modules.lsp.client + + diff --git a/ide/lsp.client/external/binaries-list b/ide/lsp.client/external/binaries-list new file mode 100644 index 000000000000..248d43aea260 --- /dev/null +++ b/ide/lsp.client/external/binaries-list @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +90E34B7C7E0257E3993CA5A939AE94F889D31340 org.eclipse.lsp4j:org.eclipse.lsp4j:0.4.1 +467F27E91FD694C05EB663532F2EDE0404025AFE org.eclipse.lsp4j:org.eclipse.lsp4j.generator:0.4.1 +F3F93F50BBEB7D58B50E6FFCA615CBFC76491846 org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.4.1 +56459301B64C92BBBB6E13988B91CDBE1FC6264E org.eclipse.xtend:org.eclipse.xtend.lib:2.14.0 +F2FCA7A70C8A29374E79487417CEFB5F51A84867 org.eclipse.xtend:org.eclipse.xtend.lib.macro:2.14.0 +C40FFE7E5E6244DD094AE95009AA45072C629254 org.eclipse.xtext:org.eclipse.xtext.xbase.lib:2.14.0 diff --git a/ide/lsp.client/external/lsp4j-0.4.1-license.txt b/ide/lsp.client/external/lsp4j-0.4.1-license.txt new file mode 100644 index 000000000000..8129cb7f4e7a --- /dev/null +++ b/ide/lsp.client/external/lsp4j-0.4.1-license.txt @@ -0,0 +1,73 @@ +Name: Eclipse Language Server Protocol Library +Origin: Eclipse +Version: 0.4.1 +License: EPL-v10 +URL: http://www.eclipse.org/ +Description: Eclipse Language Server Protocol Library +Files: org.eclipse.lsp4j-0.4.1.jar org.eclipse.lsp4j.generator-0.4.1.jar org.eclipse.lsp4j.jsonrpc-0.4.1.jar + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: + +i) changes to the Program, and +ii) additions to the Program; + +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. +"Program" means the Contributions distributed in accordance with this Agreement. +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. + +Contributors may not remove or alter any copyright notices contained within the Program. +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. diff --git a/ide/lsp.client/external/xtend-2.14.0-license.txt b/ide/lsp.client/external/xtend-2.14.0-license.txt new file mode 100644 index 000000000000..21580782981a --- /dev/null +++ b/ide/lsp.client/external/xtend-2.14.0-license.txt @@ -0,0 +1,73 @@ +Name: Eclipse Xtend library +Origin: Eclipse +Version: 2.14.0 +License: EPL-v10 +URL: http://www.eclipse.org/ +Description: Eclipse Xtend library +Files: org.eclipse.xtend.lib-2.14.0.jar org.eclipse.xtend.lib.macro-2.14.0.jar org.eclipse.xtext.xbase.lib-2.14.0.jar + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: + +i) changes to the Program, and +ii) additions to the Program; + +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. +"Program" means the Contributions distributed in accordance with this Agreement. +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. + +Contributors may not remove or alter any copyright notices contained within the Program. +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. diff --git a/ide/lsp.client/manifest.mf b/ide/lsp.client/manifest.mf new file mode 100644 index 000000000000..0a64463565f7 --- /dev/null +++ b/ide/lsp.client/manifest.mf @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +AutoUpdate-Show-In-Client: true +OpenIDE-Module: org.netbeans.modules.lsp.client/0 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/lsp/client/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/ide/lsp.client/nbproject/project.properties b/ide/lsp.client/nbproject/project.properties new file mode 100644 index 000000000000..1118a9114b35 --- /dev/null +++ b/ide/lsp.client/nbproject/project.properties @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +javac.source=1.8 +javac.compilerargs=-Xlint -Xlint:-serial +javadoc.arch=${basedir}/arch.xml +release.external/org.eclipse.lsp4j-0.4.1.jar=modules/ext/org.eclipse.lsp4j-0.4.1.jar +release.external/org.eclipse.lsp4j.generator-0.4.1.jar=modules/ext/org.eclipse.lsp4j.generator-0.4.1.jar +release.external/org.eclipse.lsp4j.jsonrpc-0.4.1.jar=modules/ext/org.eclipse.lsp4j.jsonrpc-0.4.1.jar +release.external/org.eclipse.xtend.lib-2.14.0.jar=modules/ext/org.eclipse.xtend.lib-2.14.0.jar +release.external/org.eclipse.xtend.lib.macro-2.14.0.jar=modules/ext/org.eclipse.xtend.lib.macro-2.14.0.jar +release.external/org.eclipse.xtext.xbase.lib-2.14.0.jar=modules/ext/org.eclipse.xtext.xbase.lib-2.14.0.jar diff --git a/ide/lsp.client/nbproject/project.xml b/ide/lsp.client/nbproject/project.xml new file mode 100644 index 000000000000..c032598892b0 --- /dev/null +++ b/ide/lsp.client/nbproject/project.xml @@ -0,0 +1,252 @@ + + + + org.netbeans.modules.apisupport.project + + + org.netbeans.modules.lsp.client + + + com.google.gson + + + + 2.7 + + + + com.google.guava + + + + 15.0 + + + + org.netbeans.api.annotations.common + + + + 1 + 1.30 + + + + org.netbeans.api.progress + + + + 1 + 1.50 + + + + org.netbeans.modules.editor + + + + 3 + 1.90 + + + + org.netbeans.modules.editor.completion + + + + 1 + 1.47 + + + + org.netbeans.modules.editor.document + + + + 1.12 + + + + org.netbeans.modules.editor.lib + + + + 3 + 4.10 + + + + org.netbeans.modules.editor.lib2 + + + + 1 + 2.20 + + + + org.netbeans.modules.editor.mimelookup + + + + 1 + 1.43 + + + + org.netbeans.modules.projectapi + + + + 1 + 1.70 + + + + org.netbeans.spi.editor.hints + + + + 0 + 1.45 + + + + org.netbeans.spi.navigator + + + + 1 + 1.40 + + + + org.openide.awt + + + + 7.70 + + + + org.openide.dialogs + + + + 7.45 + + + + org.openide.explorer + + + + 6.65 + + + + org.openide.filesystems + + + + 9.13 + + + + org.openide.modules + + + + 7.51 + + + + org.openide.nodes + + + + 7.48 + + + + org.openide.text + + + + 6.70 + + + + org.openide.util + + + + 9.10 + + + + org.openide.util.lookup + + + + 8.36 + + + + org.openide.util.ui + + + + 9.10 + + + + + org.netbeans.modules.lsp.client.spi + + + ext/org.eclipse.lsp4j-0.4.1.jar + external/org.eclipse.lsp4j-0.4.1.jar + + + ext/org.eclipse.xtend.lib.macro-2.14.0.jar + external/org.eclipse.xtend.lib.macro-2.14.0.jar + + + ext/org.eclipse.lsp4j.generator-0.4.1.jar + external/org.eclipse.lsp4j.generator-0.4.1.jar + + + ext/org.eclipse.xtend.lib-2.14.0.jar + external/org.eclipse.xtend.lib-2.14.0.jar + + + ext/org.eclipse.xtext.xbase.lib-2.14.0.jar + external/org.eclipse.xtext.xbase.lib-2.14.0.jar + + + ext/org.eclipse.lsp4j.jsonrpc-0.4.1.jar + external/org.eclipse.lsp4j.jsonrpc-0.4.1.jar + + + + diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/Bundle.properties b/ide/lsp.client/src/org/netbeans/modules/lsp/client/Bundle.properties new file mode 100644 index 000000000000..f30f87ad1c91 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/Bundle.properties @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +OpenIDE-Module-Name=LSP Client +ConnectToLanguageServerParameters.jLabel1.text=Root: +ConnectToLanguageServerParameters.jLabel2.text=Port: +ConnectToLanguageServerParameters.jLabel3.text=Extensions: +ConnectToLanguageServerParameters.port.text= +ConnectToLanguageServerParameters.extensions.text= +ConnectToLanguageServerParameters.root.text= diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServer.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServer.java new file mode 100644 index 000000000000..a32d0fab3f58 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServer.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import org.openide.*; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle.Messages; + +@ActionID( + category = "Tools", + id = "org.netbeans.modules.lsp.client.ConnectToLanguageServer" +) +@ActionRegistration( + displayName = "#CTL_ConnectToLanguageServer" +) +@Messages("CTL_ConnectToLanguageServer=Connect to Language Server") +public final class ConnectToLanguageServer implements ActionListener { + + @Override + @Messages({"ERR_CanFindRoot=Can't find the specified root directory", + "ERR_InvalidPort=The specified port is invalid" + }) + public void actionPerformed(ActionEvent e) { + ConnectToLanguageServerParameters params = new ConnectToLanguageServerParameters(); + DialogDescriptor dd = new DialogDescriptor(params, "Connect to Language Server", true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, null); + + if (DialogDisplayer.getDefault().notify(dd) == DialogDescriptor.OK_OPTION) { + params.confirm(); + FileObject root = FileUtil.toFileObject(new File(params.getRoot())); + + if (root == null) { + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(Bundle.ERR_CanFindRoot(), NotifyDescriptor.ERROR_MESSAGE)); + return ; + } + + int port; + + try { + port = Integer.parseInt(params.getPort()); + } catch (NumberFormatException ex) { + DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(Bundle.ERR_InvalidPort(), NotifyDescriptor.ERROR_MESSAGE)); + return ; + } + + LSPBindings.addBindings(root, port, params.getExtensions().split(",")); + } + } +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServerParameters.form b/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServerParameters.form new file mode 100644 index 000000000000..e127e2dea316 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServerParameters.form @@ -0,0 +1,125 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServerParameters.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServerParameters.java new file mode 100644 index 000000000000..ff0a410fda87 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/ConnectToLanguageServerParameters.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client; + +import java.util.prefs.Preferences; +import javax.swing.JTextField; +import org.openide.util.NbPreferences; + +/** + * + * @author lahvac + */ +public class ConnectToLanguageServerParameters extends javax.swing.JPanel { + + private static final String KEY_ROOT = "root"; + private static final String KEY_PORT = "port"; + private static final String KEY_EXTENSIONS = "extensions"; + private final Preferences settings; + + public ConnectToLanguageServerParameters() { + initComponents(); + Preferences prefs = NbPreferences.forModule(ConnectToLanguageServerParameters.class); + settings = prefs.node("connect"); + root.setText(settings.get(KEY_ROOT, "")); + port.setText(settings.get(KEY_PORT, "")); + extensions.setText(settings.get(KEY_EXTENSIONS, "")); + } + + public void confirm() { + settings.put(KEY_ROOT, root.getText()); + settings.put(KEY_PORT, port.getText()); + settings.put(KEY_EXTENSIONS, extensions.getText()); + } + + public String getExtensions() { + return extensions.getText(); + } + + public String getPort() { + return port.getText(); + } + + public String getRoot() { + return root.getText(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + root = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + port = new javax.swing.JTextField(); + jLabel3 = new javax.swing.JLabel(); + extensions = new javax.swing.JTextField(); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ConnectToLanguageServerParameters.class, "ConnectToLanguageServerParameters.jLabel1.text")); // NOI18N + + root.setText(org.openide.util.NbBundle.getMessage(ConnectToLanguageServerParameters.class, "ConnectToLanguageServerParameters.root.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(ConnectToLanguageServerParameters.class, "ConnectToLanguageServerParameters.jLabel2.text")); // NOI18N + + port.setText(org.openide.util.NbBundle.getMessage(ConnectToLanguageServerParameters.class, "ConnectToLanguageServerParameters.port.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(ConnectToLanguageServerParameters.class, "ConnectToLanguageServerParameters.jLabel3.text")); // NOI18N + + extensions.setText(org.openide.util.NbBundle.getMessage(ConnectToLanguageServerParameters.class, "ConnectToLanguageServerParameters.extensions.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)) + .addComponent(jLabel3)) + .addGap(20, 20, 20) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(root, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE) + .addComponent(port) + .addComponent(extensions)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(root, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(extensions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTextField extensions; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JTextField port; + private javax.swing.JTextField root; + // End of variables declaration//GEN-END:variables +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/LSPBindings.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LSPBindings.java new file mode 100644 index 000000000000..345541ec9712 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LSPBindings.java @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.Socket; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.WeakHashMap; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import org.eclipse.lsp4j.InitializeParams; +import org.eclipse.lsp4j.InitializeResult; +import org.eclipse.lsp4j.jsonrpc.Launcher; +import org.eclipse.lsp4j.launch.LSPLauncher; +import org.eclipse.lsp4j.services.LanguageServer; +import org.eclipse.lsp4j.services.TextDocumentService; +import org.eclipse.lsp4j.services.WorkspaceService; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.progress.*; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.modules.lsp.client.bindings.LanguageClientImpl; +import org.netbeans.modules.lsp.client.spi.LanguageServerProvider; +import org.netbeans.modules.lsp.client.spi.LanguageServerProvider.LanguageServerDescription; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle.Messages; +import org.openide.util.RequestProcessor; +import org.openide.util.lookup.Lookups; + +/** + * + * @author lahvac + */ +public class LSPBindings { + + private static final RequestProcessor WORKER = new RequestProcessor(LanguageClientImpl.class.getName(), 1, false, false); + private static final int DELAY = 500; + + private static final Map> project2MimeType2Server = new WeakHashMap<>(); + private static final Map> workspace2Extension2Server = new HashMap<>(); + private final Map> backgroundTasks = new WeakHashMap<>(); + + public static LSPBindings getBindings(FileObject file) { + for (Entry> e : workspace2Extension2Server.entrySet()) { + if (FileUtil.isParentOf(e.getKey(), file)) { + LSPBindings bindings = e.getValue().get(file.getExt()); + + if (bindings != null) { + return bindings; + } + + break; + } + } + Project prj = FileOwnerQuery.getOwner(file); + + if (prj == null) + return null; + + String mimeType = FileUtil.getMIMEType(file); + + LSPBindings bindings = + project2MimeType2Server.computeIfAbsent(prj, p -> new HashMap<>()) + .computeIfAbsent(mimeType, mt -> { + for (LanguageServerProvider provider : MimeLookup.getLookup(mimeType).lookupAll(LanguageServerProvider.class)) { + LanguageServerDescription desc = provider.startServer(Lookups.singleton(prj)); + + if (desc != null) { + try { + LanguageClientImpl lci = new LanguageClientImpl(); + InputStream in = LanguageServerProviderAccessor.getINSTANCE().getInputStream(desc); + OutputStream out = LanguageServerProviderAccessor.getINSTANCE().getOutputStream(desc); + Launcher launcher = LSPLauncher.createClientLauncher(lci, in, out); + launcher.startListening(); + LanguageServer server = launcher.getRemoteProxy(); + InitializeParams initParams = new InitializeParams(); + initParams.setRootUri(prj.getProjectDirectory().toURI().toString()); //XXX: what if a different root is expected???? + initParams.setRootPath(FileUtil.toFile(prj.getProjectDirectory()).getAbsolutePath()); //some servers still expect root path + initParams.setProcessId(0); + InitializeResult result = server.initialize(initParams).get(); + LSPBindings b = new LSPBindings(server, result); + lci.setBindings(b); + return b; + } catch (InterruptedException | ExecutionException ex) { + LOG.log(Level.FINE, null, ex); + } + } + } + return new LSPBindings(null, null); + }); + + return bindings.server != null ? bindings : null; + } + private static final Logger LOG = Logger.getLogger(LSPBindings.class.getName()); + + @Messages("LBL_Connecting=Connecting to language server") + public static void addBindings(FileObject root, int port, String... extensions) { + BaseProgressUtils.showProgressDialogAndRun(() -> { + try { + Socket s = new Socket(InetAddress.getLocalHost(), port); + LanguageClientImpl lc = new LanguageClientImpl(); + InputStream in = s.getInputStream(); + OutputStream out = s.getOutputStream(); + Launcher launcher = LSPLauncher.createClientLauncher(lc, in, new OutputStream() { + @Override + public void write(int w) throws IOException { + out.write(w); + if (w == '\n') + out.flush(); + } + }); + launcher.startListening(); + LanguageServer server = launcher.getRemoteProxy(); + + InitializeParams initParams = new InitializeParams(); + initParams.setRootUri(root.toURI().toString()); + initParams.setProcessId(0); + InitializeResult result = server.initialize(initParams).get(); + LSPBindings bindings = new LSPBindings(server, result); + + lc.setBindings(bindings); + + workspace2Extension2Server.put(root, Arrays.stream(extensions).collect(Collectors.toMap(k -> k, v -> bindings))); + } catch (InterruptedException | ExecutionException | IOException ex) { + Exceptions.printStackTrace(ex); + } + }, Bundle.LBL_Connecting()); + } + + private final LanguageServer server; + private final InitializeResult initResult; + + private LSPBindings(LanguageServer server, InitializeResult initResult) { + this.server = server; + this.initResult = initResult; + } + + public TextDocumentService getTextDocumentService() { + return server.getTextDocumentService(); + } + + public WorkspaceService getWorkspaceService() { + return server.getWorkspaceService(); + } + + public InitializeResult getInitResult() { + //XXX: defenzive copy? + return initResult; + } + + public static void addBackgroundTask(FileObject file, BackgroundTask task) { + LSPBindings bindings = getBindings(file); + + if (bindings == null) + return ; + + RequestProcessor.Task req = WORKER.create(() -> task.run(bindings, file)); + + bindings.backgroundTasks.computeIfAbsent(file, f -> new LinkedHashMap<>()).put(task, req); + bindings.scheduleBackgroundTask(req); + } + + public static void removeBackgroundTask(FileObject file, BackgroundTask task) { + LSPBindings bindings = getBindings(file); + + if (bindings == null) + return ; + + RequestProcessor.Task req = bindings.backgroundTasks.computeIfAbsent(file, f -> new LinkedHashMap<>()).remove(task); + + if (req != null) { + req.cancel(); + } + } + + public void runOnBackground(Runnable r) { + WORKER.post(r); + } + + public void scheduleBackgroundTask(RequestProcessor.Task req) { + WORKER.post(req, DELAY); + } + + public void scheduleBackgroundTasks(FileObject file) { + backgroundTasks.computeIfAbsent(file, f -> new IdentityHashMap<>()).values().stream().forEach(this::scheduleBackgroundTask); + } + + public interface BackgroundTask { + public void run(LSPBindings bindings, FileObject file); + } +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/LanguageServerProviderAccessor.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LanguageServerProviderAccessor.java new file mode 100644 index 000000000000..42d7234de498 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LanguageServerProviderAccessor.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client; + +import java.io.InputStream; +import java.io.OutputStream; +import org.netbeans.modules.lsp.client.spi.LanguageServerProvider.LanguageServerDescription; +import org.openide.util.Exceptions; + +/** + * + * @author lahvac + */ +public abstract class LanguageServerProviderAccessor { + + public static synchronized LanguageServerProviderAccessor getINSTANCE () { + if (INSTANCE == null) { + try { + Class.forName(LanguageServerDescription.class.getName(), true, LanguageServerDescription.class.getClassLoader()); //NOI18N + assert INSTANCE != null; + } catch (ClassNotFoundException e) { + Exceptions.printStackTrace(e); + } + } + return INSTANCE; + } + + public static void setINSTANCE (LanguageServerProviderAccessor instance) { + assert instance != null; + INSTANCE = instance; + } + + private static volatile LanguageServerProviderAccessor INSTANCE; + + public abstract InputStream getInputStream(LanguageServerDescription desc); + public abstract OutputStream getOutputStream(LanguageServerDescription desc); + public abstract Process getProcess(LanguageServerDescription desc); +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CodeActions.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CodeActions.java new file mode 100644 index 000000000000..8e7e07116f00 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CodeActions.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.bindings; + +import java.net.URI; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; +import javax.swing.text.BadLocationException; +import javax.swing.text.JTextComponent; +import org.eclipse.lsp4j.CodeActionContext; +import org.eclipse.lsp4j.CodeActionParams; +import org.eclipse.lsp4j.Command; +import org.eclipse.lsp4j.ExecuteCommandParams; +import org.eclipse.lsp4j.Range; +import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.modules.editor.NbEditorUtilities; +import org.netbeans.modules.lsp.client.LSPBindings; +import org.netbeans.spi.editor.codegen.CodeGenerator; +import org.openide.filesystems.FileObject; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; + +/** + * + * @author lahvac + */ +@MimeRegistration(mimeType="", service=CodeGenerator.Factory.class) +public class CodeActions implements CodeGenerator.Factory { + + @Override + public List create(Lookup context) { + JTextComponent component = context.lookup(JTextComponent.class); + if (component == null) { + return Collections.emptyList(); + } + FileObject file = NbEditorUtilities.getFileObject(component.getDocument()); + if (file == null) { + return Collections.emptyList(); + } + LSPBindings server = LSPBindings.getBindings(file); + if (server == null) { + return Collections.emptyList(); + } + URI uri = file.toURI(); + try { + List commands = + server.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(uri.toString()), + new Range(Utils.createPosition(component.getDocument(), component.getSelectionStart()), + Utils.createPosition(component.getDocument(), component.getSelectionEnd())), + new CodeActionContext(Collections.emptyList()))).get(); + return commands.stream().map(cmd -> new CodeGenerator() { + @Override + public String getDisplayName() { + return cmd.getTitle(); + } + + @Override + public void invoke() { + try { + server.getWorkspaceService().executeCommand(new ExecuteCommandParams(cmd.getCommand(), cmd.getArguments())).get(); + } catch (InterruptedException | ExecutionException ex) { + Exceptions.printStackTrace(ex); + } + } + }).collect(Collectors.toList()); + } catch (BadLocationException | InterruptedException | ExecutionException ex) { + Exceptions.printStackTrace(ex); + return Collections.emptyList(); + } + } + +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CompletionProviderImpl.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CompletionProviderImpl.java new file mode 100644 index 000000000000..61d016f06a32 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CompletionProviderImpl.java @@ -0,0 +1,193 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.bindings; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.event.KeyEvent; +import java.net.URI; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import javax.swing.text.StyledDocument; +import org.eclipse.lsp4j.CompletionItem; +import org.eclipse.lsp4j.CompletionItemKind; +import org.eclipse.lsp4j.CompletionList; +import org.eclipse.lsp4j.CompletionParams; +import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.eclipse.lsp4j.TextEdit; +import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.editor.BaseDocument; +import org.netbeans.editor.Utilities; +import org.netbeans.modules.editor.NbEditorUtilities; +import org.netbeans.modules.lsp.client.LSPBindings; +import org.netbeans.spi.editor.completion.CompletionProvider; +import org.netbeans.spi.editor.completion.CompletionResultSet; +import org.netbeans.spi.editor.completion.CompletionTask; +import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery; +import org.netbeans.spi.editor.completion.support.AsyncCompletionTask; +import org.netbeans.spi.editor.completion.support.CompletionUtilities; +import org.openide.filesystems.FileObject; +import org.openide.text.NbDocument; +import org.openide.util.Exceptions; +import org.openide.util.ImageUtilities; + +/** + * + * @author lahvac + */ +@MimeRegistration(mimeType="", service=CompletionProvider.class) +public class CompletionProviderImpl implements CompletionProvider { + + @Override + public CompletionTask createTask(int queryType, JTextComponent component) { + return new AsyncCompletionTask(new AsyncCompletionQuery() { + @Override + protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) { + try { + FileObject file = NbEditorUtilities.getFileObject(doc); + if (file == null) { + //TODO: beep + return ; + } + LSPBindings server = LSPBindings.getBindings(file); + if (server == null) { + return ; + } + URI uri = file.toURI(); + CompletionParams params; + params = new CompletionParams(new TextDocumentIdentifier(uri.toString()), + Utils.createPosition(doc, caretOffset)); + CountDownLatch l = new CountDownLatch(1); + //TODO: Location or Location[] + Either, CompletionList> completionResult = server.getTextDocumentService().completion(params).get(); + List items; + boolean incomplete; + if (completionResult.isLeft()) { + items = completionResult.getLeft(); + incomplete = true; + } else { + items = completionResult.getRight().getItems(); + incomplete = completionResult.getRight().isIncomplete(); + } + for (CompletionItem i : items) { + String insert = i.getInsertText() != null ? i.getInsertText() : i.getLabel(); + CompletionItemKind kind = i.getKind(); + Icon ic = Icons.getCompletionIcon(kind); + ImageIcon icon = new ImageIcon(ImageUtilities.icon2Image(ic)); + resultSet.addItem(new org.netbeans.spi.editor.completion.CompletionItem() { + @Override + public void defaultAction(JTextComponent jtc) { + Document doc = jtc.getDocument(); + TextEdit te = i.getTextEdit(); + if (te != null) { + int start = Utils.getOffset(doc, te.getRange().getStart()); + int end = Utils.getOffset(doc, te.getRange().getEnd()); + NbDocument.runAtomic((StyledDocument) doc, () -> { + try { + doc.remove(start, end - start); + doc.insertString(start, te.getNewText(), null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + }); + } else { + String toAdd = i.getInsertText(); + if (toAdd == null) { + toAdd = i.getLabel(); + } + try { + int offset = jtc.getCaretPosition(); + String ident = Utilities.getIdentifier((BaseDocument) doc, offset); + doc.insertString(offset, toAdd.substring(ident != null ? ident.length() : 0), null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + } + + @Override + public void processKeyEvent(KeyEvent ke) { + } + + @Override + public int getPreferredWidth(Graphics grphcs, Font font) { + return CompletionUtilities.getPreferredWidth(insert, null, grphcs, font); + } + + @Override + public void render(Graphics grphcs, Font font, Color color, Color color1, int i, int i1, boolean bln) { + CompletionUtilities.renderHtml(icon, insert, null, grphcs, font, color, i, i1, bln); + } + + @Override + public CompletionTask createDocumentationTask() { + return null; + } + + @Override + public CompletionTask createToolTipTask() { + return null; + } + + @Override + public boolean instantSubstitution(JTextComponent jtc) { + return false; + } + + @Override + public int getSortPriority() { + return 100; + } + + @Override + public CharSequence getSortText() { + return i.getSortText(); + } + + @Override + public CharSequence getInsertPrefix() { + return insert; + } + }); + } + } catch (BadLocationException | InterruptedException ex) { + Exceptions.printStackTrace(ex); + } catch (ExecutionException ex) { + Exceptions.printStackTrace(ex); + } finally { + resultSet.finish(); + } + } + }, component); + } + + @Override + public int getAutoQueryTypes(JTextComponent component, String typedText) { + return 0; //TODO: implement trigger characters, if any? + } + +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java new file mode 100644 index 000000000000..4c79aa152200 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java @@ -0,0 +1,136 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.bindings; + +import java.net.MalformedURLException; +import java.net.URI; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import javax.swing.SwingUtilities; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.eclipse.lsp4j.Location; +import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.eclipse.lsp4j.TextDocumentPositionParams; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.editor.BaseDocument; +import org.netbeans.editor.Utilities; +import org.netbeans.lib.editor.hyperlink.spi.HyperlinkProviderExt; +import org.netbeans.lib.editor.hyperlink.spi.HyperlinkType; +import org.netbeans.modules.editor.NbEditorUtilities; +import org.netbeans.modules.lsp.client.LSPBindings; +import org.openide.cookies.LineCookie; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.URLMapper; +import org.openide.text.Line; +import org.openide.text.Line.ShowOpenType; +import org.openide.text.Line.ShowVisibilityType; +import org.openide.util.Exceptions; + +/** + * + * @author lahvac + */ +@MimeRegistration(mimeType="", service=HyperlinkProviderExt.class) +public class HyperlinkProviderImpl implements HyperlinkProviderExt { + + @Override + public Set getSupportedHyperlinkTypes() { + return EnumSet.of(HyperlinkType.GO_TO_DECLARATION); + } + + @Override + public boolean isHyperlinkPoint(Document doc, int offset, HyperlinkType type) { + return getHyperlinkSpan(doc, offset, type) != null; + } + + @Override + public int[] getHyperlinkSpan(Document doc, int offset, HyperlinkType type) { + try { + //XXX: not really using the server, are we? + return Utilities.getIdentifierBlock((BaseDocument) doc, offset); + } catch (BadLocationException ex) { + return null; + } + } + + @Override + public void performClickAction(Document doc, int offset, HyperlinkType type) { + FileObject file = NbEditorUtilities.getFileObject(doc); + if (file == null) { + //TODO: beep + return ; + } + LSPBindings server = LSPBindings.getBindings(file); + if (server == null) { + return ; + } + URI uri = file.toURI(); + try { + TextDocumentPositionParams params; + params = new TextDocumentPositionParams(new TextDocumentIdentifier(uri.toString()), + Utils.createPosition(doc, offset)); + //TODO: Location or Location[] + CompletableFuture> def = server.getTextDocumentService().definition(params); + def.handleAsync((locations, exception) -> { + if (exception != null) { + exception.printStackTrace(); + } + if (locations != null && locations.size() == 1) { //TODO: what to do when there are multiple locations? + try { + URI target = URI.create(locations.get(0).getUri()); + FileObject targetFile = URLMapper.findFileObject(target.toURL()); + + if (targetFile != null) { + LineCookie lc = targetFile.getLookup().lookup(LineCookie.class); + + //TODO: expecting lc != null! + + Line line = lc.getLineSet().getCurrent(locations.get(0).getRange().getStart().getLine()); + + SwingUtilities.invokeLater(() -> + line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, locations.get(0).getRange().getStart().getCharacter()) + ); + } else { + //TODO: beep + } + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } + } + return null; + }).get(); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } catch (InterruptedException ex) { + Exceptions.printStackTrace(ex); + } catch (ExecutionException ex) { + Exceptions.printStackTrace(ex); + } + } + + @Override + public String getTooltipText(Document doc, int offset, HyperlinkType type) { + return null; + } + +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/Icons.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/Icons.java new file mode 100644 index 000000000000..d2543341da38 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/Icons.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.netbeans.modules.lsp.client.bindings; + +import java.awt.Image; +import java.util.Locale; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import org.eclipse.lsp4j.CompletionItemKind; +import org.eclipse.lsp4j.SymbolKind; +import org.openide.util.ImageUtilities; + +/** + * Based on: + * java.source/src/org/netbeans/modules/java/ui/Icons.java + * @author Petr Hrebejk + */ +public final class Icons { + + private static final String ICON_BASE = "org/netbeans/modules/lsp/client/bindings/icons/"; + private static final String GIF_EXTENSION = ".gif"; + private static final String PNG_EXTENSION = ".png"; + + private Icons() { + } + + public static Icon getCompletionIcon(CompletionItemKind completionKind) { + Image img = null; + + if (completionKind != null) { + img = ImageUtilities.loadImage(ICON_BASE + completionKind.name().toLowerCase(Locale.US) + PNG_EXTENSION); + + if (img == null) { + img = ImageUtilities.loadImage(ICON_BASE + completionKind.name().toLowerCase(Locale.US) + GIF_EXTENSION); + } + } + + if (img == null) { + img = ImageUtilities.loadImage(ICON_BASE + "variable" + GIF_EXTENSION); + } + + return img == null ? null : new ImageIcon (img); + + } + + public static String getSymbolIconBase(SymbolKind symbolKind) { + for (String variant : new String[] { + ICON_BASE + symbolKind.name().toLowerCase(Locale.US) + PNG_EXTENSION, + ICON_BASE + symbolKind.name().toLowerCase(Locale.US) + GIF_EXTENSION, + ICON_BASE + "variable" + GIF_EXTENSION + }) { + if (ImageUtilities.loadImage(variant) != null) + return variant; + } + return null; + } +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/LanguageClientImpl.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/LanguageClientImpl.java new file mode 100644 index 000000000000..4ed1fd5ed0fd --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/LanguageClientImpl.java @@ -0,0 +1,252 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.bindings; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.StyledDocument; +import org.eclipse.lsp4j.ApplyWorkspaceEditParams; +import org.eclipse.lsp4j.ApplyWorkspaceEditResponse; +import org.eclipse.lsp4j.CodeActionContext; +import org.eclipse.lsp4j.CodeActionParams; +import org.eclipse.lsp4j.Command; +import org.eclipse.lsp4j.Diagnostic; +import org.eclipse.lsp4j.DiagnosticSeverity; +import org.eclipse.lsp4j.ExecuteCommandParams; +import org.eclipse.lsp4j.MessageActionItem; +import org.eclipse.lsp4j.MessageParams; +import org.eclipse.lsp4j.PublishDiagnosticsParams; +import org.eclipse.lsp4j.ShowMessageRequestParams; +import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.eclipse.lsp4j.TextEdit; +import org.eclipse.lsp4j.WorkspaceEdit; +import org.eclipse.lsp4j.services.LanguageClient; +import org.netbeans.modules.lsp.client.LSPBindings; +import org.netbeans.spi.editor.hints.ChangeInfo; +import org.netbeans.spi.editor.hints.ErrorDescription; +import org.netbeans.spi.editor.hints.ErrorDescriptionFactory; +import org.netbeans.spi.editor.hints.Fix; +import org.netbeans.spi.editor.hints.HintsController; +import org.netbeans.spi.editor.hints.LazyFixList; +import org.netbeans.spi.editor.hints.Severity; +import org.openide.cookies.EditorCookie; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.URLMapper; +import org.openide.text.NbDocument; +import org.openide.util.Exceptions; + +/** + * + * @author lahvac + */ +public class LanguageClientImpl implements LanguageClient { + + private static final Logger LOG = Logger.getLogger(LanguageClientImpl.class.getName()); + + private LSPBindings bindings; + + public void setBindings(LSPBindings bindings) { + this.bindings = bindings; + } + + @Override + public void telemetryEvent(Object arg0) { + System.err.println("telemetry: " + arg0); + } + + @Override + public void publishDiagnostics(PublishDiagnosticsParams pdp) { + try { + FileObject file = URLMapper.findFileObject(new URI(pdp.getUri()).toURL()); + EditorCookie ec = file.getLookup().lookup(EditorCookie.class); + Document doc = ec != null ? ec.getDocument() : null; + if (doc == null) + return ; //ignore... + List diags = pdp.getDiagnostics().stream().map(d -> + ErrorDescriptionFactory.createErrorDescription(severityMap.get(d.getSeverity()), d.getMessage(), new DiagnosticFixList(pdp.getUri(), d), file, Utils.getOffset(doc, d.getRange().getStart()), Utils.getOffset(doc, d.getRange().getEnd())) + ).collect(Collectors.toList()); + HintsController.setErrors(doc, LanguageClientImpl.class.getName(), diags); + } catch (URISyntaxException | MalformedURLException ex) { + LOG.log(Level.FINE, null, ex); + } + } + + private static final Map severityMap = new EnumMap<>(DiagnosticSeverity.class); + + static { + severityMap.put(DiagnosticSeverity.Error, Severity.ERROR); + severityMap.put(DiagnosticSeverity.Hint, Severity.HINT); + severityMap.put(DiagnosticSeverity.Information, Severity.HINT); + severityMap.put(DiagnosticSeverity.Warning, Severity.HINT); + } + + @Override + public CompletableFuture applyEdit(ApplyWorkspaceEditParams params) { + WorkspaceEdit edit = params.getEdit(); + for (Entry> e : edit.getChanges().entrySet()) { + try { + FileObject file = URLMapper.findFileObject(new URI(e.getKey()).toURL()); + EditorCookie ec = file.getLookup().lookup(EditorCookie.class); + Document doc = ec != null ? ec.openDocument() : null; + if (doc == null) { + continue; + } + NbDocument.runAtomic((StyledDocument) doc, () -> { + e.getValue() + .stream() + .sorted((te1, te2) -> te1.getRange().getEnd().getLine() == te2.getRange().getEnd().getLine() ? te1.getRange().getEnd().getCharacter() - te2.getRange().getEnd().getCharacter() : te1.getRange().getEnd().getLine() - te2.getRange().getEnd().getLine()) + .forEach(te -> { + try { + int start = Utils.getOffset(doc, te.getRange().getStart()); + int end = Utils.getOffset(doc, te.getRange().getEnd()); + doc.remove(start, end - start); + doc.insertString(start, te.getNewText(), null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + }); + }); + } catch (URISyntaxException | IOException ex) { + Exceptions.printStackTrace(ex); + } + } + return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true)); + } + + @Override + public void showMessage(MessageParams arg0) { + System.err.println("showMessage: " + arg0); + } + + @Override + public CompletableFuture showMessageRequest(ShowMessageRequestParams arg0) { + System.err.println("showMessageRequest"); + return null; //??? + } + + @Override + public void logMessage(MessageParams arg0) { + System.err.println("logMessage: " + arg0); + } + + private final class DiagnosticFixList implements LazyFixList { + + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + private final String fileUri; + private final Diagnostic diagnostic; + private List fixes; + private boolean computing; + private boolean computed; + + public DiagnosticFixList(String fileUri, Diagnostic diagnostic) { + this.fileUri = fileUri; + this.diagnostic = diagnostic; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + @Override + public boolean probablyContainsFixes() { + return true; + } + + @Override + public synchronized List getFixes() { + if (!computing && !computed) { + computing = true; + bindings.runOnBackground(() -> { + try { + List commands = + bindings.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(fileUri), + diagnostic.getRange(), + new CodeActionContext(Collections.singletonList(diagnostic)))).get(); + List fixes = commands.stream() + .map(cmd -> new CommandBasedFix(cmd)) + .collect(Collectors.toList()); + synchronized (this) { + this.fixes = Collections.unmodifiableList(fixes); + this.computed = true; + this.computing = false; + } + pcs.firePropertyChange(PROP_COMPUTED, null, null); + pcs.firePropertyChange(PROP_FIXES, null, null); + } catch (InterruptedException | ExecutionException ex) { + Exceptions.printStackTrace(ex); + } + }); + } + return fixes; + } + + @Override + public synchronized boolean isComputed() { + return computed; + } + + private class CommandBasedFix implements Fix { + + private final Command cmd; + + public CommandBasedFix(Command cmd) { + this.cmd = cmd; + } + + @Override + public String getText() { + return cmd.getTitle(); + } + + @Override + public ChangeInfo implement() throws Exception { + try { + bindings.getWorkspaceService().executeCommand(new ExecuteCommandParams(cmd.getCommand(), cmd.getArguments())).get(); + } catch (InterruptedException | ExecutionException ex) { + Exceptions.printStackTrace(ex); + } + + return null; + } + } + + } +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java new file mode 100644 index 000000000000..bbc12f31419e --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.bindings; + +import java.awt.BorderLayout; +import java.net.MalformedURLException; +import java.net.URI; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.swing.JComponent; +import javax.swing.JPanel; +import org.eclipse.lsp4j.DocumentSymbolParams; +import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.netbeans.modules.lsp.client.LSPBindings; +import org.netbeans.modules.lsp.client.LSPBindings.BackgroundTask; +import org.netbeans.spi.navigator.NavigatorPanel; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.view.BeanTreeView; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.URLMapper; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; +import org.openide.util.NbBundle.Messages; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author lahvac + */ +public class NavigatorPanelImpl extends Children.Keys implements NavigatorPanel, BackgroundTask, LookupListener { + + private static final NavigatorPanelImpl INSTANCE = new NavigatorPanelImpl(); + + private final ExplorerManager manager; + private JComponent view; + private Lookup.Result result; + private FileObject file; + + public NavigatorPanelImpl() { + manager = new ExplorerManager(); + manager.setRootContext(new AbstractNode(this)); + } + + @Override + @Messages("DN_Symbols=Symbols") + public String getDisplayName() { + return Bundle.DN_Symbols(); + } + + @Override + public String getDisplayHint() { + return "symbols"; + } + + @Override + public JComponent getComponent() { + if (view == null) { + class View extends JPanel implements ExplorerManager.Provider { + + public View() { + setLayout(new BorderLayout()); + BeanTreeView btv = new BeanTreeView(); + add(btv, BorderLayout.CENTER); + + btv.setRootVisible(false); + } + + @Override + public ExplorerManager getExplorerManager() { + return manager; + } + } + view = new View(); + } + return view; + } + + @Override + public void panelActivated(Lookup context) { + result = context.lookupResult(FileObject.class); + result.addLookupListener(this); + updateFile(); + } + + @Override + public void panelDeactivated() { + result.removeLookupListener(this); + result = null; + updateFile(); + } + + private void updateFile() { + if (file != null) { + LSPBindings.removeBackgroundTask(file, this); + setKeys(Collections.emptyList()); + file = null; + } + Collection files = result != null ? result.allInstances() : Collections.emptyList(); + file = files.isEmpty() ? null : files.iterator().next(); + if (file != null) { + LSPBindings.addBackgroundTask(file, this); + } + } + + @Override + public Lookup getLookup() { + return Lookup.EMPTY; + } + + @Override + public void run(LSPBindings bindings, FileObject file) { + if (file.equals(this.file)) { + try { + List symbols = bindings.getTextDocumentService().documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(file.toURI().toString()))).get(); + + setKeys(symbols); + } catch (InterruptedException | ExecutionException ex) { + Exceptions.printStackTrace(ex); + } + } else { + System.err.println("!!!"); + } + } + + @Override + protected Node[] createNodes(SymbolInformation sym) { + AbstractNode n = new AbstractNode(LEAF); + n.setDisplayName(sym.getName()); + n.setIconBaseWithExtension(Icons.getSymbolIconBase(sym.getKind())); + return new Node[] {n}; + } + + @Override + public void resultChanged(LookupEvent arg0) { + updateFile(); + } + + @ServiceProvider(service=DynamicRegistration.class) + public static final class DynamicRegistrationImpl implements DynamicRegistration { + + @Override + public Collection panelsFor(URI uri) { + try { + FileObject file = URLMapper.findFileObject(uri.toURL()); + if (file != null) { + return LSPBindings.getBindings(file) != null ? Collections.singletonList(INSTANCE) : Collections.emptyList(); + } else { + return Collections.emptyList(); + } + } catch (MalformedURLException ex) { + //ignore + return Collections.emptyList(); + } + } + + } +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/TextDocumentSyncServerCapabilityHandler.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/TextDocumentSyncServerCapabilityHandler.java new file mode 100644 index 000000000000..c08a3b900779 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/TextDocumentSyncServerCapabilityHandler.java @@ -0,0 +1,155 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.bindings; + +import java.util.Arrays; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Set; +import javax.swing.SwingUtilities; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import org.eclipse.lsp4j.DidChangeTextDocumentParams; +import org.eclipse.lsp4j.DidOpenTextDocumentParams; +import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.Range; +import org.eclipse.lsp4j.TextDocumentContentChangeEvent; +import org.eclipse.lsp4j.TextDocumentItem; +import org.eclipse.lsp4j.VersionedTextDocumentIdentifier; +import org.netbeans.api.editor.EditorRegistry; +import org.netbeans.editor.BaseDocumentEvent; +import org.netbeans.modules.editor.*; +import org.netbeans.modules.lsp.client.LSPBindings; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.modules.OnStart; +import org.openide.util.Exceptions; + +/** TODO: asynchronous + * TODO: follow the synchronization options + * TODO: close + * + * @author lahvac + */ +public class TextDocumentSyncServerCapabilityHandler { + + private final Set lastOpened = Collections.newSetFromMap(new IdentityHashMap<>()); + + private void handleChange() { + assert SwingUtilities.isEventDispatchThread(); + Set currentOpened = Collections.newSetFromMap(new IdentityHashMap<>()); + currentOpened.addAll(EditorRegistry.componentList()); + Set newOpened = Collections.newSetFromMap(new IdentityHashMap<>()); + newOpened.addAll(currentOpened); + newOpened.removeAll(lastOpened); + Set newClosed = Collections.newSetFromMap(new IdentityHashMap<>()); + newClosed.addAll(lastOpened); + newClosed.removeAll(newOpened); + lastOpened.removeAll(newClosed); + lastOpened.addAll(newOpened); + + for (JTextComponent opened : newOpened) { + FileObject file = NbEditorUtilities.getFileObject(opened.getDocument()); + + if (file == null) + continue; //ignore + + LSPBindings server = LSPBindings.getBindings(file); + + if (server == null) + continue; //ignore + + try { + //XXX: should construct events outside of AWT + TextDocumentItem textDocumentItem = new TextDocumentItem(file.toURI().toString(), + FileUtil.getMIMEType(file), + 0, + opened.getDocument().getText(0, opened.getDocument().getLength())); //XXX: should do in render! + + server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(textDocumentItem)); + server.scheduleBackgroundTasks(file); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + + Document doc = opened.getDocument(); + + doc.addDocumentListener(new DocumentListener() { //XXX: listener + int version; //XXX: proper versioning! + @Override + public void insertUpdate(DocumentEvent e) { + try { + fireEvent(e.getOffset(), e.getDocument().getText(e.getOffset(), e.getLength()), ""); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + @Override + public void removeUpdate(DocumentEvent e) { + fireEvent(e.getOffset(), "", ((BaseDocumentEvent) e).getText()); + } + private void fireEvent(int start, String newText, String oldText) { + try { + Position startPos = Utils.createPosition(doc, start); + int additionalLines = 0; + int additionalChars = 0; + for (char c : oldText.toCharArray()) { + if (c == '\n') { + additionalLines++; + additionalChars = 0; + } else { + additionalChars++; + } + } + Position endPos = new Position(startPos.getLine() + additionalLines, + startPos.getCharacter() + additionalChars); + TextDocumentContentChangeEvent event; + event = new TextDocumentContentChangeEvent(new Range(startPos, + endPos), + oldText.length(), + newText); + VersionedTextDocumentIdentifier di = new VersionedTextDocumentIdentifier(++version); + di.setUri(file.toURI().toString()); + server.getTextDocumentService().didChange(new DidChangeTextDocumentParams(di, Arrays.asList(event))); + server.scheduleBackgroundTasks(file); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + @Override + public void changedUpdate(DocumentEvent e) {} + }); + } + } + + @OnStart + public static class Init implements Runnable { + + @Override + public void run() { + TextDocumentSyncServerCapabilityHandler h = new TextDocumentSyncServerCapabilityHandler(); + EditorRegistry.addPropertyChangeListener(evt -> h.handleChange()); + SwingUtilities.invokeLater(() -> h.handleChange()); + } + + } +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/Utils.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/Utils.java new file mode 100644 index 000000000000..ca0c7d9ff325 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/Utils.java @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.bindings; + +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.eclipse.lsp4j.Position; +import org.netbeans.api.editor.document.LineDocument; +import org.netbeans.api.editor.document.LineDocumentUtils; + +/** + * + * @author lahvac + */ +public class Utils { + + public static Position createPosition(Document doc, int offset) throws BadLocationException { + return new Position(LineDocumentUtils.getLineIndex((LineDocument) doc, offset), + offset - LineDocumentUtils.getLineStart((LineDocument) doc, offset)); + } + + public static int getOffset(Document doc, Position pos) { + return LineDocumentUtils.getLineStartFromIndex((LineDocument) doc, pos.getLine()) + pos.getCharacter(); + } +} diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/attribute.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/attribute.png new file mode 100644 index 000000000000..610dbab206e3 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/attribute.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/class.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/class.png new file mode 100644 index 000000000000..220e6f385e0a Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/class.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/color.gif b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/color.gif new file mode 100644 index 000000000000..670335626375 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/color.gif differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/constant.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/constant.png new file mode 100644 index 000000000000..aa01646d6920 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/constant.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/constructor.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/constructor.png new file mode 100644 index 000000000000..fd95f9d19736 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/constructor.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/enum.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/enum.png new file mode 100644 index 000000000000..f54c89b9cfb4 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/enum.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/enummember.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/enummember.png new file mode 100644 index 000000000000..06a86fb1d9c2 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/enummember.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/event.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/event.png new file mode 100644 index 000000000000..cf556834a884 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/event.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/field.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/field.png new file mode 100644 index 000000000000..06a86fb1d9c2 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/field.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/file.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/file.png new file mode 100644 index 000000000000..712725a5749a Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/file.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/folder.gif b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/folder.gif new file mode 100644 index 000000000000..bc77c8d13e25 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/folder.gif differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/function.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/function.png new file mode 100644 index 000000000000..7be8a378a374 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/function.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/interface.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/interface.png new file mode 100644 index 000000000000..ae582f77a865 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/interface.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/keyword.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/keyword.png new file mode 100644 index 000000000000..beca697f9279 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/keyword.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/method.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/method.png new file mode 100644 index 000000000000..7be8a378a374 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/method.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/module.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/module.png new file mode 100644 index 000000000000..505f4b7f8123 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/module.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/operator.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/operator.png new file mode 100644 index 000000000000..7be8a378a374 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/operator.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/property.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/property.png new file mode 100644 index 000000000000..06a86fb1d9c2 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/property.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/reference.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/reference.png new file mode 100644 index 000000000000..290ae366617d Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/reference.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/snippet.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/snippet.png new file mode 100644 index 000000000000..b56c19cee5d5 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/snippet.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/struct.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/struct.png new file mode 100644 index 000000000000..220e6f385e0a Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/struct.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/text.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/text.png new file mode 100644 index 000000000000..b56c19cee5d5 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/text.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/typeparameter.gif b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/typeparameter.gif new file mode 100644 index 000000000000..50971fb74a60 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/typeparameter.gif differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/unit.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/unit.png new file mode 100644 index 000000000000..505f4b7f8123 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/unit.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/value.png b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/value.png new file mode 100644 index 000000000000..8c18e6b4a8cf Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/value.png differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/variable.gif b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/variable.gif new file mode 100644 index 000000000000..50971fb74a60 Binary files /dev/null and b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/icons/variable.gif differ diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/spi/LanguageServerProvider.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/spi/LanguageServerProvider.java new file mode 100644 index 000000000000..52826170d129 --- /dev/null +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/spi/LanguageServerProvider.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.lsp.client.spi; + +import java.io.InputStream; +import java.io.OutputStream; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; +import org.netbeans.modules.lsp.client.LanguageServerProviderAccessor; +import org.openide.util.Lookup; + +/** + * Possibly start a language server. Should be installed in the Mime Lookup for the + * given mime type that is handled by the given server. + * + * @author lahvac + */ +public interface LanguageServerProvider { + /**Possibly start a language server. {@code lookup} contains additional + * information. May return null, meaning no server was started. + * + * @param lookup additional information + * @return a description of the running language server handling requests for + * the given mime type, or null if not handled. + */ + public @CheckForNull LanguageServerDescription startServer(@NonNull Lookup lookup); + + /** + * A description of a running language server. + */ + public static final class LanguageServerDescription { + + /** + * Create the description of a running language server. + * + * @param in the InputStream that should be used to communicate with the server + * @param out the OutputStream that should be used to communicate with the server + * @param process the process of the running language server, or null if none. + * @return an instance of LanguageServerDescription + */ + public static @NonNull LanguageServerDescription create(@NonNull InputStream in, @NonNull OutputStream out, @NullAllowed Process process) { + return new LanguageServerDescription(in, out, process); + } + + private final InputStream in; + private final OutputStream out; + private final Process process; + + private LanguageServerDescription(InputStream in, OutputStream out, Process process) { + this.in = in; + this.out = out; + this.process = process; + } + + static { + LanguageServerProviderAccessor.setINSTANCE(new LanguageServerProviderAccessor() { + @Override + public InputStream getInputStream(LanguageServerDescription desc) { + return desc.in; + } + + @Override + public OutputStream getOutputStream(LanguageServerDescription desc) { + return desc.out; + } + + @Override + public Process getProcess(LanguageServerDescription desc) { + return desc.process; + } + }); + } + + } +} diff --git a/ide/spi.navigator/apichanges.xml b/ide/spi.navigator/apichanges.xml index 777ba8a29194..89832a219c0a 100644 --- a/ide/spi.navigator/apichanges.xml +++ b/ide/spi.navigator/apichanges.xml @@ -83,6 +83,21 @@ is the proper place. + + + Added SPI interface NavigatorPanel.DynamicRegistration + + + + + +

+ Added SPI interface NavigatorPanel.DynamicRegistration to + allow dynamic registration of NavigatorPanels. +

+
+ +
Added SPI interface NavigatorPanelWithToolbar diff --git a/ide/spi.navigator/manifest.mf b/ide/spi.navigator/manifest.mf index 65c1eef3621b..74b9b2608c09 100644 --- a/ide/spi.navigator/manifest.mf +++ b/ide/spi.navigator/manifest.mf @@ -2,4 +2,4 @@ Manifest-version: 1.0 OpenIDE-Module: org.netbeans.spi.navigator/1 OpenIDE-Module-Layer: org/netbeans/modules/navigator/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/navigator/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.40 +OpenIDE-Module-Specification-Version: 1.41 diff --git a/ide/spi.navigator/nbproject/project.properties b/ide/spi.navigator/nbproject/project.properties index 0f4503e8078e..1e6086064420 100644 --- a/ide/spi.navigator/nbproject/project.properties +++ b/ide/spi.navigator/nbproject/project.properties @@ -18,7 +18,7 @@ is.autoload=true javac.compilerargs=-Xlint:unchecked -javac.source=1.6 +javac.source=1.8 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/ide/spi.navigator/nbproject/project.xml b/ide/spi.navigator/nbproject/project.xml index e0e894d9cce1..d1a6e7431e99 100644 --- a/ide/spi.navigator/nbproject/project.xml +++ b/ide/spi.navigator/nbproject/project.xml @@ -25,6 +25,15 @@ org.netbeans.spi.navigator + + org.netbeans.api.annotations.common + + + + 1 + 1.30 + + org.openide.awt @@ -58,7 +67,7 @@ - org.openide.util.ui + org.openide.util @@ -66,19 +75,19 @@ - org.openide.util + org.openide.util.lookup - 9.3 + 8.0 - org.openide.util.lookup + org.openide.util.ui - 8.0 + 9.3 diff --git a/ide/spi.navigator/src/org/netbeans/modules/navigator/NavigatorController.java b/ide/spi.navigator/src/org/netbeans/modules/navigator/NavigatorController.java index f9b1f9ad3034..e6e2b6c14ff0 100644 --- a/ide/spi.navigator/src/org/netbeans/modules/navigator/NavigatorController.java +++ b/ide/spi.navigator/src/org/netbeans/modules/navigator/NavigatorController.java @@ -555,7 +555,7 @@ private List obtainProviders(Collection nodes, N // search in global lookup first, they had preference for (NavigatorLookupHint curHint : lkpHints) { - Collection providers = ProviderRegistry.getInstance().getProviders(curHint.getContentType()); + Collection providers = ProviderRegistry.getInstance().getProviders(curHint.getContentType(), null); if (providers != null && !providers.isEmpty()) { if (result == null) { result = new ArrayList(providers.size() * lkpHints.size()); @@ -590,7 +590,7 @@ private List obtainProviders(Collection nodes, N } String contentType = fo.getMIMEType(); - Collection providers = ProviderRegistry.getInstance().getProviders(contentType); + Collection providers = ProviderRegistry.getInstance().getProviders(contentType, fo); if (providers == null || providers.isEmpty()) { fileResult = null; break; diff --git a/ide/spi.navigator/src/org/netbeans/modules/navigator/ProviderRegistry.java b/ide/spi.navigator/src/org/netbeans/modules/navigator/ProviderRegistry.java index 1917bdf3ffa6..6c85b30b57a5 100644 --- a/ide/spi.navigator/src/org/netbeans/modules/navigator/ProviderRegistry.java +++ b/ide/spi.navigator/src/org/netbeans/modules/navigator/ProviderRegistry.java @@ -19,10 +19,19 @@ package org.netbeans.modules.navigator; +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; +import java.net.URI; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.WeakHashMap; +import java.util.stream.Collectors; import org.netbeans.spi.navigator.NavigatorPanel; +import org.netbeans.spi.navigator.NavigatorPanel.DynamicRegistration; +import org.openide.filesystems.FileObject; import org.openide.util.Lookup; import org.openide.util.lookup.Lookups; @@ -49,6 +58,7 @@ class ProviderRegistry { * no providers. This ensures no useless repetitive searches. */ private Map> contentTypes2Providers; + private Map>> file2Providers; /** Singleton, no external instantiation */ @@ -71,7 +81,7 @@ public static ProviderRegistry getInstance () { * @return Collection of providers, which implements NavigatorPanel interface. * Never return null, only empty List if no provider exists for given content type. */ - public Collection getProviders (String contentType) { + public Collection getProviders (String contentType, FileObject file) { if (contentTypes2Providers == null) { contentTypes2Providers = new HashMap>(15); } @@ -81,8 +91,24 @@ public Collection getProviders (String contentType) { result = loadProviders(contentType); contentTypes2Providers.put(contentType, result); } - - return result; + if (file != null) { + if (file2Providers == null) { + file2Providers = new WeakHashMap<>(); + } + URI uri = file.toURI(); + Reference> fileResultRef = file2Providers.computeIfAbsent(file, f -> + new SoftReference<>(Lookup.getDefault().lookupAll(DynamicRegistration.class).stream().flatMap(reg -> reg.panelsFor(uri).stream()).collect(Collectors.toList())) + ); + Collection fileResult = fileResultRef != null ? fileResultRef.get() : null; + if (result == null) return fileResult; + if (fileResult == null) return result; + List panels = new ArrayList<>(); + panels.addAll(result); + panels.addAll(fileResult); + return panels; + } else { + return result; + } } /******* private stuff ***********/ diff --git a/ide/spi.navigator/src/org/netbeans/spi/navigator/NavigatorPanel.java b/ide/spi.navigator/src/org/netbeans/spi/navigator/NavigatorPanel.java index 8f248e8170a5..01b5fea4fffa 100644 --- a/ide/spi.navigator/src/org/netbeans/spi/navigator/NavigatorPanel.java +++ b/ide/spi.navigator/src/org/netbeans/spi/navigator/NavigatorPanel.java @@ -23,7 +23,13 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.net.URI; +import java.util.Collection; import javax.swing.JComponent; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; +import org.openide.filesystems.FileObject; import org.openide.util.Lookup; /** Navigation related view description. @@ -138,4 +144,21 @@ public interface NavigatorPanel { Registration[] value(); } + /** + * Dynamically create panels for files. Register in the global lookup. + * + * @since 1.41 + */ + interface DynamicRegistration { + + /** + * Dynamically create {@code NavigatorPanel}s for the given file. + * + * @param file for which the panels should be created + * @return a collection of {@code NavigatorPanel}s for the given file + * null is allowed + */ + public @CheckForNull Collection panelsFor(@NonNull URI file); + } + } diff --git a/ide/spi.navigator/test/unit/src/org/netbeans/modules/navigator/ProviderRegistryTest.java b/ide/spi.navigator/test/unit/src/org/netbeans/modules/navigator/ProviderRegistryTest.java index fd03cc7472fb..6528367c0f1a 100644 --- a/ide/spi.navigator/test/unit/src/org/netbeans/modules/navigator/ProviderRegistryTest.java +++ b/ide/spi.navigator/test/unit/src/org/netbeans/modules/navigator/ProviderRegistryTest.java @@ -19,11 +19,18 @@ package org.netbeans.modules.navigator; +import java.net.URI; import java.util.Collection; +import java.util.Collections; import javax.swing.JComponent; import org.netbeans.junit.NbTestCase; import org.netbeans.spi.navigator.NavigatorPanel; +import org.netbeans.spi.navigator.NavigatorPanel.DynamicRegistration; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; /** @@ -46,13 +53,13 @@ public void testGetProviders () throws Exception { ProviderRegistry providerReg = ProviderRegistry.getInstance(); System.out.println("Asking for non-existent type..."); - assertEquals(0, providerReg.getProviders("image/non_existent_type").size()); + assertEquals(0, providerReg.getProviders("image/non_existent_type", null).size()); System.out.println("Asking for non-existent class..."); - assertEquals(0, providerReg.getProviders("text/plain").size()); + assertEquals(0, providerReg.getProviders("text/plain", null).size()); System.out.println("Asking for valid type and provider..."); - Collection result = providerReg.getProviders(MARVELOUS_DATA_TYPE); + Collection result = providerReg.getProviders(MARVELOUS_DATA_TYPE, null); assertEquals(1, result.size()); NavigatorPanel np = result.iterator().next(); assertTrue(np instanceof MarvelousDataTypeProvider); @@ -60,6 +67,33 @@ public void testGetProviders () throws Exception { assertEquals(MARVELOUS_DATA_TYPE_NAME, provider.getDisplayName()); } + public void testDynamicGetProviders () throws Exception { + UnitTestUtils.prepareTest(new String [] { "/org/netbeans/modules/navigator/resources/testGetProvidersLayer.xml" }); + FileObject root = FileUtil.createMemoryFileSystem().getRoot(); + FileObject file1 = root.createData("1"); + FileObject file2 = root.createData("2"); + Lookup checkingProvider = Lookups.singleton(new DynamicRegistration() { + @Override + public Collection panelsFor(URI file) { + return file1.toURI().equals(file) ? Collections.singletonList(new MarvelousDataTypeProvider()) + : Collections.emptyList(); + } + }); + Lookups.executeWith(new ProxyLookup(Lookup.getDefault(), checkingProvider), () -> { + ProviderRegistry providerReg = ProviderRegistry.getInstance(); + + System.out.println("Asking for masked out file..."); + assertEquals(0, providerReg.getProviders("image/non_existent_type", file2).size()); + + System.out.println("Asking for valid file..."); + Collection result = providerReg.getProviders("image/non_existent_type", file1); + assertEquals(1, result.size()); + NavigatorPanel np = result.iterator().next(); + assertTrue(np instanceof MarvelousDataTypeProvider); + MarvelousDataTypeProvider provider = (MarvelousDataTypeProvider)np; + assertEquals(MARVELOUS_DATA_TYPE_NAME, provider.getDisplayName()); + }); + } /** Dummy navigator panel provider, just to test right loading and instantiating * for certain data type diff --git a/nbbuild/cluster.properties b/nbbuild/cluster.properties index c336941944f5..deefb6d3f537 100644 --- a/nbbuild/cluster.properties +++ b/nbbuild/cluster.properties @@ -287,6 +287,7 @@ nb.cluster.ide=\ bugtracking.bridge,\ bugtracking.commons,\ bugzilla,\ + c.google.gson,\ c.google.guava,\ c.googlecode.javaewah.JavaEWAH,\ c.jcraft.jsch,\ @@ -410,6 +411,7 @@ nb.cluster.ide=\ libs.xerces,\ localhistory,\ localtasks,\ + lsp.client,\ mercurial,\ mylyn.util,\ notifications,\