Skip to content

Commit 8f0803d

Browse files
authored
Merge pull request #418 from Achal1607/javavscode-375
added user configuration for setting up code completion commit characters
2 parents d4ef549 + 3c91d72 commit 8f0803d

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
patches/dev-dependency-licenses.diff
7272
patches/nb-telemetry.diff
7373
patches/change-method-parameters-refactoring-qualified-names.diff
74+
patches/javavscode-375.diff
7475
</string>
7576
<filterchain>
7677
<tokenfilter delimoutput=" ">

patches/javavscode-375.diff

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
2+
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
3+
@@ -19,6 +19,7 @@
4+
package org.netbeans.modules.java.lsp.server.protocol;
5+
6+
import com.google.gson.Gson;
7+
+import com.google.gson.JsonArray;
8+
import com.google.gson.JsonElement;
9+
import com.google.gson.JsonObject;
10+
import com.google.gson.JsonPrimitive;
11+
@@ -292,6 +293,8 @@
12+
private static final String NETBEANS_JAVADOC_LOAD_TIMEOUT = "javadoc.load.timeout";// NOI18N
13+
private static final String NETBEANS_COMPLETION_WARNING_TIME = "completion.warning.time";// NOI18N
14+
private static final String NETBEANS_JAVA_ON_SAVE_ORGANIZE_IMPORTS = "java.onSave.organizeImports";// NOI18N
15+
+ private static final String NETBEANS_CODE_COMPLETION_COMMIT_CHARS = "java.completion.commit.chars";// NOI18N
16+
+
17+
private static final String URL = "url";// NOI18N
18+
private static final String INDEX = "index";// NOI18N
19+
20+
@@ -368,6 +371,7 @@
21+
AtomicReference<Sampler> samplerRef = new AtomicReference<>();
22+
AtomicLong samplingStart = new AtomicLong();
23+
AtomicLong samplingWarningLength = new AtomicLong(DEFAULT_COMPLETION_WARNING_LENGTH);
24+
+ AtomicReference<List<String>> codeCompletionCommitChars = new AtomicReference<>(List.of());
25+
long completionStart = System.currentTimeMillis();
26+
COMPLETION_SAMPLER_WORKER.post(() -> {
27+
if (!done.get()) {
28+
@@ -412,7 +416,10 @@
29+
ConfigurationItem completionWarningLength = new ConfigurationItem();
30+
completionWarningLength.setScopeUri(uri);
31+
completionWarningLength.setSection(client.getNbCodeCapabilities().getConfigurationPrefix() + NETBEANS_COMPLETION_WARNING_TIME);
32+
- return client.configuration(new ConfigurationParams(Arrays.asList(conf, completionWarningLength))).thenApply(c -> {
33+
+ ConfigurationItem commitCharacterConfig = new ConfigurationItem();
34+
+ commitCharacterConfig.setScopeUri(uri);
35+
+ commitCharacterConfig.setSection(client.getNbCodeCapabilities().getConfigurationPrefix() + NETBEANS_CODE_COMPLETION_COMMIT_CHARS);
36+
+ return client.configuration(new ConfigurationParams(Arrays.asList(conf, completionWarningLength, commitCharacterConfig))).thenApply(c -> {
37+
if (c != null && !c.isEmpty()) {
38+
if (c.get(0) instanceof JsonPrimitive) {
39+
JsonPrimitive javadocTimeSetting = (JsonPrimitive) c.get(0);
40+
@@ -424,7 +431,11 @@
41+
42+
samplingWarningLength.set(samplingWarningsLengthSetting.getAsLong());
43+
}
44+
+ if(c.get(2) instanceof JsonArray){
45+
+ JsonArray commitCharsJsonArray = (JsonArray) c.get(2);
46+
+ codeCompletionCommitChars.set(commitCharsJsonArray.asList().stream().map(ch -> ch.toString()).collect(Collectors.toList()));
47+
}
48+
+ }
49+
final int caret = Utils.getOffset(doc, params.getPosition());
50+
List<CompletionItem> items = new ArrayList<>();
51+
Completion.Context context = params.getContext() != null
52+
@@ -486,8 +497,8 @@
53+
}).collect(Collectors.toList()));
54+
}
55+
}
56+
- if (completion.getCommitCharacters() != null) {
57+
- item.setCommitCharacters(completion.getCommitCharacters().stream().map(ch -> ch.toString()).collect(Collectors.toList()));
58+
+ if (codeCompletionCommitChars.get() != null) {
59+
+ item.setCommitCharacters(codeCompletionCommitChars.get());
60+
}
61+
lastCompletions.add(completion);
62+
item.setData(new CompletionData(uri, index.getAndIncrement()));

vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@
250250
"tags": [
251251
"telemetry"
252252
]
253+
},
254+
"jdk.java.completion.commit.chars": {
255+
"type": "array",
256+
"default": [],
257+
"description": "%jdk.configuration.java.completion.commit.chars%"
253258
}
254259
}
255260
},

vscode/package.nls.ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"jdk.debugger.configuration.attach.listen.description": "接続するデバッグ対象をリスニング",
6565
"jdk.debugger.configuration.attach.timeout.description": "接続を待つ間のタイムアウト",
6666
"jdk.debugger.configuration.completion.warning.time.description": "When code completion takes longer than this specified time (in milliseconds), there will be a warning produced (-1 to disable)",
67+
"jdk.configuration.java.completion.commit.chars": "Specifies the characters that trigger accepting a code completion suggestion. For example, to accept suggestions when typing a dot (.), set this to [\".\"]",
6768
"jdk.initialConfigurations.launchJavaApp.name": "Javaアプリケーションの起動",
6869
"jdk.configurationSnippets.name": "Javaアプリケーションの起動",
6970
"jdk.configurationSnippets.label": "Java+: Javaアプリケーションの起動",

vscode/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"jdk.debugger.configuration.attach.listen.description": "Listen for the debuggee to attach",
6565
"jdk.debugger.configuration.attach.timeout.description": "Timeout while waiting to attach",
6666
"jdk.debugger.configuration.completion.warning.time.description": "When code completion takes longer than this specified time (in milliseconds), there will be a warning produced (-1 to disable)",
67+
"jdk.configuration.java.completion.commit.chars": "Specifies the characters that trigger accepting a code completion suggestion. For example, to accept suggestions when typing a dot (.), set this to [\".\"]",
6768
"jdk.initialConfigurations.launchJavaApp.name": "Launch Java App",
6869
"jdk.configurationSnippets.name": "Launch Java App",
6970
"jdk.configurationSnippets.label": "Java+: Launch Java Application",

vscode/package.nls.zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"jdk.debugger.configuration.attach.listen.description": "监听要附加的被调试程序",
6565
"jdk.debugger.configuration.attach.timeout.description": "等待附加操作时的超时",
6666
"jdk.debugger.configuration.completion.warning.time.description": "When code completion takes longer than this specified time (in milliseconds), there will be a warning produced (-1 to disable)",
67+
"jdk.configuration.java.completion.commit.chars": "Specifies the characters that trigger accepting a code completion suggestion. For example, to accept suggestions when typing a dot (.), set this to [\".\"]",
6768
"jdk.initialConfigurations.launchJavaApp.name": "启动 Java 应用程序",
6869
"jdk.configurationSnippets.name": "启动 Java 应用程序",
6970
"jdk.configurationSnippets.label": "Java+:启动 Java 应用程序",

0 commit comments

Comments
 (0)