Skip to content

Commit 2ebb57e

Browse files
committed
Set language configuration
1 parent 1bda874 commit 2ebb57e

3 files changed

Lines changed: 123 additions & 36 deletions

File tree

‎language-configuration.json‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"comments": {
3+
"lineComment": "//",
4+
"blockComment": [
5+
"/*",
6+
"*/"
7+
]
8+
},
9+
"brackets": [
10+
[
11+
"{",
12+
"}"
13+
],
14+
[
15+
"[",
16+
"]"
17+
],
18+
[
19+
"(",
20+
")"
21+
]
22+
],
23+
"autoClosingPairs": [
24+
[
25+
"{",
26+
"}"
27+
],
28+
[
29+
"[",
30+
"]"
31+
],
32+
[
33+
"(",
34+
")"
35+
],
36+
[
37+
"\"",
38+
"\""
39+
],
40+
[
41+
"'",
42+
"'"
43+
],
44+
{
45+
"open": "/**",
46+
"close": " */",
47+
"notIn": [
48+
"string"
49+
]
50+
}
51+
],
52+
"surroundingPairs": [
53+
[
54+
"{",
55+
"}"
56+
],
57+
[
58+
"[",
59+
"]"
60+
],
61+
[
62+
"(",
63+
")"
64+
],
65+
[
66+
"\"",
67+
"\""
68+
],
69+
[
70+
"'",
71+
"'"
72+
],
73+
[
74+
"<",
75+
">"
76+
]
77+
]
78+
}

‎lib/extension.ts‎

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,7 @@ export function activate(context: ExtensionContext) {
5858
serverOptions = visualVmConfig(context);
5959
}
6060

61-
// Copied from typescript
62-
languages.setLanguageConfiguration('java', {
63-
indentationRules: {
64-
// ^(.*\*/)?\s*\}.*$
65-
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
66-
// ^.*\{[^}"']*$
67-
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/,
68-
indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/
69-
},
70-
onEnterRules: [
71-
{
72-
// e.g. /** | */
73-
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
74-
afterText: /^\s*\*\/$/,
75-
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
76-
}, {
77-
// e.g. /** ...|
78-
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
79-
action: { indentAction: IndentAction.None, appendText: ' * ' }
80-
}, {
81-
// e.g. * ...|
82-
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
83-
action: { indentAction: IndentAction.None, appendText: '* ' }
84-
}, {
85-
// e.g. */|
86-
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
87-
action: { indentAction: IndentAction.None, removeText: 1 }
88-
},
89-
{
90-
// e.g. *-----*/|
91-
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
92-
action: { indentAction: IndentAction.None, removeText: 1 }
93-
}
94-
]
95-
})
61+
enableJavadocSymbols();
9662

9763
// Create the language client and start the client.
9864
let client = new LanguageClient('java', 'Java Language Server', serverOptions, clientOptions);
@@ -424,4 +390,46 @@ function findJavaExecutableInJavaHome(javaHome: string, binname: string) {
424390
}
425391

426392
return null;
393+
}
394+
395+
function enableJavadocSymbols() {
396+
// Let's enable Javadoc symbols autocompletion, shamelessly copied from MIT licensed code at
397+
// https://github.com/Microsoft/vscode/blob/9d611d4dfd5a4a101b5201b8c9e21af97f06e7a7/extensions/typescript/src/typescriptMain.ts#L186
398+
languages.setLanguageConfiguration('java', {
399+
indentationRules: {
400+
// ^(.*\*/)?\s*\}.*$
401+
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
402+
// ^.*\{[^}"']*$
403+
increaseIndentPattern: /^.*\{[^}"']*$/
404+
},
405+
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
406+
onEnterRules: [
407+
{
408+
// e.g. /** | */
409+
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
410+
afterText: /^\s*\*\/$/,
411+
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
412+
},
413+
{
414+
// e.g. /** ...|
415+
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
416+
action: { indentAction: IndentAction.None, appendText: ' * ' }
417+
},
418+
{
419+
// e.g. * ...|
420+
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
421+
action: { indentAction: IndentAction.None, appendText: '* ' }
422+
},
423+
{
424+
// e.g. */|
425+
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
426+
action: { indentAction: IndentAction.None, removeText: 1 }
427+
},
428+
{
429+
// e.g. *-----*/|
430+
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
431+
action: { indentAction: IndentAction.None, removeText: 1 }
432+
}
433+
]
434+
});
427435
}

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
],
3636
"aliases": [
3737
"Java"
38-
]
38+
],
39+
"configuration": "./language-configuration.json"
3940
},
4041
{
4142
"id": "java.hover"

0 commit comments

Comments
 (0)