Skip to content

Commit 9341a86

Browse files
Integrate rust-analyzer
- add support for rust LSP implementation rust-analyzer - align rust icons more with existing NB icons - show hint if rust analyser is not configured
1 parent 6008635 commit 9341a86

37 files changed

Lines changed: 1704 additions & 32 deletions

ide/lsp.client/licenseinfo.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@
2121
-->
2222
<licenseinfo>
2323
<fileset>
24+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/attribute.png</file>
25+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/class.png</file>
26+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/color.gif</file>
27+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/constant.png</file>
28+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/constructor.png</file>
29+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/empty.png</file>
30+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/enummember.png</file>
31+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/enum.png</file>
32+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/event.png</file>
33+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/field.png</file>
34+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/file.png</file>
35+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/folder.gif</file>
36+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/function.png</file>
37+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/interface.png</file>
38+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/keyword.png</file>
39+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/method.png</file>
40+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/module.png</file>
41+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/operator.png</file>
42+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/property.png</file>
43+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/reference.png</file>
44+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/snippet.png</file>
45+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/struct.png</file>
46+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/text.png</file>
47+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/typeparameter.gif</file>
48+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/unit.png</file>
49+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/value.png</file>
50+
<file>src/org/netbeans/modules/lsp/client/bindings/icons/variable.gif</file>
2451
<file>src/org/netbeans/modules/lsp/client/resources/error_16.png</file>
2552
<file>src/org/netbeans/modules/lsp/client/resources/warning_16.png</file>
2653
<license ref="Apache-2.0-ASF" />

rust/rust.grammar/licenseinfo.xml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@
2020
2121
-->
2222
<licenseinfo>
23-
<!-- These are generated files by the antlr compiler.
2423
<fileset>
25-
<file>src/org/netbeans/modules/rust/grammar/antlr4/RustLexer.interp</file>
26-
<file>src/org/netbeans/modules/rust/grammar/antlr4/RustParser.interp</file>
27-
<file>src/org/netbeans/modules/rust/grammar/antlr4/RustParser.tokens</file>
28-
<file>src/org/netbeans/modules/rust/grammar/antlr4/RustLexer.tokens</file>
29-
<license ref="Apache-2.0-ASF" />
30-
<comment type="COMMENT_UNSUPPORTED" />
31-
</fileset>
32-
-->
33-
<fileset>
34-
<file>src/org/netbeans/modules/rust/grammar/structure/resources/structure-macro.png</file>
35-
<file>src/org/netbeans/modules/rust/grammar/structure/resources/structure-enum.png</file>
36-
<file>src/org/netbeans/modules/rust/grammar/structure/resources/structure-struct.png</file>
37-
<file>src/org/netbeans/modules/rust/grammar/structure/resources/structure-impl.png</file>
38-
<file>src/org/netbeans/modules/rust/grammar/structure/resources/structure-function.png</file>
39-
<file>src/org/netbeans/modules/rust/grammar/structure/resources/structure-module.png</file>
24+
<file>src/org/netbeans/modules/rust/grammar/structure/resources/enum.png</file>
25+
<file>src/org/netbeans/modules/rust/grammar/structure/resources/function.png</file>
26+
<file>src/org/netbeans/modules/rust/grammar/structure/resources/interface.png</file>
27+
<file>src/org/netbeans/modules/rust/grammar/structure/resources/module.png</file>
28+
<file>src/org/netbeans/modules/rust/grammar/structure/resources/snippet.png</file>
29+
<file>src/org/netbeans/modules/rust/grammar/structure/resources/struct.png</file>
30+
<file>src/org/netbeans/modules/rust/grammar/structure/resources/trait.png</file>
4031
<license ref="Apache-2.0-ASF" />
4132
<comment type="COMMENT_UNSUPPORTED" />
4233
</fileset>

rust/rust.grammar/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
javac.source=1.8
18+
javac.release=21
1919
javac.compilerargs=-Xlint -Xlint:-serial
2020
build.generated.sources.dir=${build.dir}/generated-sources

rust/rust.grammar/nbproject/project.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
<specification-version>1.20</specification-version>
6262
</run-dependency>
6363
</dependency>
64+
<dependency>
65+
<code-name-base>org.netbeans.modules.editor</code-name-base>
66+
<build-prerequisite/>
67+
<compile-dependency/>
68+
<run-dependency>
69+
<release-version>3</release-version>
70+
<specification-version>1.119</specification-version>
71+
</run-dependency>
72+
</dependency>
6473
<dependency>
6574
<code-name-base>org.netbeans.modules.editor.fold</code-name-base>
6675
<build-prerequisite/>
@@ -70,6 +79,15 @@
7079
<specification-version>1.65</specification-version>
7180
</run-dependency>
7281
</dependency>
82+
<dependency>
83+
<code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
84+
<build-prerequisite/>
85+
<compile-dependency/>
86+
<run-dependency>
87+
<release-version>1</release-version>
88+
<specification-version>2.52</specification-version>
89+
</run-dependency>
90+
</dependency>
7391
<dependency>
7492
<code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
7593
<build-prerequisite/>
@@ -96,6 +114,24 @@
96114
<specification-version>1.1</specification-version>
97115
</run-dependency>
98116
</dependency>
117+
<dependency>
118+
<code-name-base>org.netbeans.modules.lsp.client</code-name-base>
119+
<build-prerequisite/>
120+
<compile-dependency/>
121+
<run-dependency>
122+
<release-version>0</release-version>
123+
<specification-version>1.24</specification-version>
124+
</run-dependency>
125+
</dependency>
126+
<dependency>
127+
<code-name-base>org.netbeans.modules.options.api</code-name-base>
128+
<build-prerequisite/>
129+
<compile-dependency/>
130+
<run-dependency>
131+
<release-version>1</release-version>
132+
<specification-version>1.77</specification-version>
133+
</run-dependency>
134+
</dependency>
99135
<dependency>
100136
<code-name-base>org.netbeans.modules.parsing.api</code-name-base>
101137
<build-prerequisite/>
@@ -105,6 +141,23 @@
105141
<specification-version>9.27</specification-version>
106142
</run-dependency>
107143
</dependency>
144+
<dependency>
145+
<code-name-base>org.netbeans.modules.rust.options</code-name-base>
146+
<build-prerequisite/>
147+
<compile-dependency/>
148+
<run-dependency>
149+
<specification-version>1.11</specification-version>
150+
</run-dependency>
151+
</dependency>
152+
<dependency>
153+
<code-name-base>org.netbeans.spi.editor.hints</code-name-base>
154+
<build-prerequisite/>
155+
<compile-dependency/>
156+
<run-dependency>
157+
<release-version>0</release-version>
158+
<specification-version>1.74</specification-version>
159+
</run-dependency>
160+
</dependency>
108161
<dependency>
109162
<code-name-base>org.openide.filesystems</code-name-base>
110163
<build-prerequisite/>
@@ -113,6 +166,14 @@
113166
<specification-version>9.33</specification-version>
114167
</run-dependency>
115168
</dependency>
169+
<dependency>
170+
<code-name-base>org.openide.modules</code-name-base>
171+
<build-prerequisite/>
172+
<compile-dependency/>
173+
<run-dependency>
174+
<specification-version>7.79</specification-version>
175+
</run-dependency>
176+
</dependency>
116177
<dependency>
117178
<code-name-base>org.openide.util</code-name-base>
118179
<build-prerequisite/>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.rust.grammar;
20+
21+
import java.net.URL;
22+
import java.util.Collection;
23+
import java.util.logging.Logger;
24+
import org.netbeans.modules.rust.options.api.RustAnalyzerOptions;
25+
import org.openide.filesystems.Repository.LayerProvider;
26+
import org.openide.util.lookup.ServiceProvider;
27+
28+
/**
29+
* The rust.grammer module can provide services directly or using rust-analyzer
30+
* (the rust lsp). If the user configured rust-analyzer, that should get
31+
* priority as it also can provide code completion and improved structure
32+
* scanning.
33+
*
34+
* For this to work, the normal NetBeans behavior to generate layer entries from
35+
* annotations (MimeRegistration of LSP, LanguageRegistration) has to be
36+
* customized as the two options can't coexist completely.
37+
*
38+
* Therefore the layer entries from org.netbeans.modules.rust.grammar.RustLanguageConfig
39+
* and org.netbeans.modules.rust.grammar.lsp.RustLSP are removed from the
40+
* generated-layer.xml (build/classes/META-INF/generated-layer.xml), the
41+
* annotations are commented out and the entries from the generated layer are
42+
* checked whether they were created by one of the mentioned classes (see XML
43+
* comments for reference) and are distributed into:
44+
*
45+
* - layer.xml holds everything that applies to both LSP and non-LSP mode
46+
* - lsp-layer.xml holds everything specific to the LSP
47+
* - non-lsp-layer.xml hold everything specific to the non-LSP run
48+
*
49+
* `layer.xml` is loaded by the module system unconditionally. The two variants
50+
* `lsp-layer.xml` and `non-lsp-layer.xml` are loaded using this class.
51+
*/
52+
@ServiceProvider(service = LayerProvider.class)
53+
public class LayerProviderImpl extends LayerProvider {
54+
55+
private static final Logger LOG = Logger.getLogger(LayerProviderImpl.class.getName());
56+
57+
@Override
58+
protected void registerLayers(Collection<? super URL> context) {
59+
URL layerUrl;
60+
if (RustAnalyzerOptions.getRustAnalyzerLocation(false, false) != null) {
61+
layerUrl = LayerProviderImpl.class.getResource("lsp-layer.xml");
62+
} else {
63+
layerUrl = LayerProviderImpl.class.getResource("non-lsp-layer.xml");
64+
}
65+
context.add(layerUrl);
66+
}
67+
}

rust/rust.grammar/src/org/netbeans/modules/rust/grammar/RustLanguageConfig.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import org.netbeans.modules.csl.api.DeclarationFinder;
2424
import org.netbeans.modules.csl.api.StructureScanner;
2525
import org.netbeans.modules.csl.spi.DefaultLanguageConfig;
26-
import org.netbeans.modules.csl.spi.LanguageRegistration;
2726
import org.netbeans.modules.parsing.spi.Parser;
27+
import org.netbeans.modules.rust.options.api.RustAnalyzerOptions;
2828

29-
/**
30-
*
31-
*/
32-
@LanguageRegistration(mimeType = "text/x-rust", useMultiview = true)
29+
// See LayerProviderImpl for information about layer handling and when this
30+
// needs to be uncommented
31+
//
32+
//@LanguageRegistration(mimeType = "text/x-rust", useMultiview = true)
3333
public class RustLanguageConfig extends DefaultLanguageConfig {
3434

3535
private static final Language<RustTokenID> RUST_LANGUAGE = new RustLanguage().language();
@@ -46,12 +46,12 @@ public String getDisplayName() {
4646

4747
@Override
4848
public StructureScanner getStructureScanner() {
49-
return new RustStructureScanner();
49+
return RustAnalyzerOptions.getRustAnalyzerLocation(false, false) == null ? new RustStructureScanner() : null;
5050
}
5151

5252
@Override
5353
public boolean hasStructureScanner() {
54-
return true;
54+
return RustAnalyzerOptions.getRustAnalyzerLocation(false, false) == null;
5555
}
5656

5757
@Override
@@ -66,7 +66,7 @@ public String getLineCommentPrefix() {
6666

6767
@Override
6868
public DeclarationFinder getDeclarationFinder() {
69-
return new RustDeclarationFinder();
69+
return RustAnalyzerOptions.getRustAnalyzerLocation(false, false) == null ? new RustDeclarationFinder() : null;
7070
}
7171

7272
}

0 commit comments

Comments
 (0)