Skip to content

Commit 34126d8

Browse files
committed
fix: use same indentation rules as JS/TS
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 3df18e8 commit 34126d8

File tree

2 files changed

+135
-49
lines changed

2 files changed

+135
-49
lines changed

language-support/java/language-configuration.json

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,139 @@
8888
"<",
8989
">"
9090
]
91+
],
92+
"autoCloseBefore": ";:.,=}])>` \n\t",
93+
"folding": {
94+
"markers": {
95+
"start": "^\\s*//\\s*#?region\\b",
96+
"end": "^\\s*//\\s*#?endregion\\b"
97+
}
98+
},
99+
"wordPattern": {
100+
"pattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)"
101+
},
102+
"indentationRules": {
103+
"decreaseIndentPattern": {
104+
"pattern": "^((?!.*?\\/\\*).*\\*/)?\\s*[\\)\\}\\]].*$"
105+
},
106+
"increaseIndentPattern": {
107+
"pattern": "^((?!\\/\\/).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$"
108+
},
109+
"unIndentedLinePattern": {
110+
"pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$|^(\\t|[ ])*[ ]\\*/\\s*$|^(\\t|[ ])*[ ]\\*([ ]([^\\*]|\\*(?!/))*)?$"
111+
},
112+
"indentNextLinePattern": {
113+
"pattern": "^((.*=>\\s*)|((.*[^\\w]+|\\s*)((if|while|for)\\s*\\(.*\\)\\s*|else\\s*)))$"
114+
}
115+
},
116+
"onEnterRules": [
117+
{
118+
"beforeText": {
119+
"pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
120+
},
121+
"afterText": {
122+
"pattern": "^\\s*\\*/$"
123+
},
124+
"action": {
125+
"indent": "indentOutdent",
126+
"appendText": " * "
127+
}
128+
},
129+
{
130+
"beforeText": {
131+
"pattern": "^\\s*/\\*\\*(?!/)([^\\*]|\\*(?!/))*$"
132+
},
133+
"action": {
134+
"indent": "none",
135+
"appendText": " * "
136+
}
137+
},
138+
{
139+
"beforeText": {
140+
"pattern": "^(\\t|[ ])*[ ]\\*([ ]([^\\*]|\\*(?!/))*)?$"
141+
},
142+
"previousLineText": {
143+
"pattern": "(?=^(\\s*(/\\*\\*|\\*)).*)(?=(?!(\\s*\\*/)))"
144+
},
145+
"action": {
146+
"indent": "none",
147+
"appendText": "* "
148+
}
149+
},
150+
{
151+
"beforeText": {
152+
"pattern": "^(\\t|[ ])*[ ]\\*/\\s*$"
153+
},
154+
"action": {
155+
"indent": "none",
156+
"removeText": 1
157+
}
158+
},
159+
{
160+
"beforeText": {
161+
"pattern": "^(\\t|[ ])*[ ]\\*[^/]*\\*/\\s*$"
162+
},
163+
"action": {
164+
"indent": "none",
165+
"removeText": 1
166+
}
167+
},
168+
{
169+
"beforeText": {
170+
"pattern": "^\\s*(\\bcase\\s.+:|\\bdefault:)$"
171+
},
172+
"afterText": {
173+
"pattern": "^(?!\\s*(\\bcase\\b|\\bdefault\\b))"
174+
},
175+
"action": {
176+
"indent": "indent"
177+
}
178+
},
179+
{
180+
"previousLineText": "^\\s*(((else ?)?if|for|while)\\s*\\(.*\\)\\s*|else\\s*)$",
181+
"beforeText": "^\\s+([^{i\\s]|i(?!f\\b))",
182+
"action": {
183+
"indent": "outdent"
184+
}
185+
},
186+
{
187+
"beforeText": "^.*\\([^\\)]*$",
188+
"afterText": "^\\s*\\).*$",
189+
"action": {
190+
"indent": "indentOutdent",
191+
"appendText": "\t"
192+
}
193+
},
194+
{
195+
"beforeText": "^.*\\{[^\\}]*$",
196+
"afterText": "^\\s*\\}.*$",
197+
"action": {
198+
"indent": "indentOutdent",
199+
"appendText": "\t"
200+
}
201+
},
202+
{
203+
"beforeText": "^.*\\[[^\\]]*$",
204+
"afterText": "^\\s*\\].*$",
205+
"action": {
206+
"indent": "indentOutdent",
207+
"appendText": "\t"
208+
}
209+
},
210+
{
211+
"beforeText": "(?<!\\\\|\\w:)\\/\\/\\s*\\S",
212+
"afterText": "^(?!\\s*$).+",
213+
"action": {
214+
"indent": "none",
215+
"appendText": "// "
216+
}
217+
},
218+
{
219+
"beforeText": "^\\s*\\/\\/\\/(.*)?$",
220+
"action": {
221+
"indent": "none",
222+
"appendText": "/// "
223+
}
224+
}
91225
]
92226
}

src/extension.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as path from 'path';
99
import * as semver from 'semver';
1010
import {
1111
CodeActionContext, commands, CompletionItem, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions,
12-
IndentAction, InputBoxOptions, languages, Location, MarkdownString, RelativePattern,
12+
InputBoxOptions, Location, MarkdownString, RelativePattern,
1313
SnippetString, SnippetTextEdit, TextDocument, TextEditorRevealType, UIKind, Uri, version, ViewColumn, window, workspace, WorkspaceConfiguration
1414
} from 'vscode';
1515
import { CancellationToken, CodeActionParams, CodeActionRequest, CodeActionResolveRequest, Command, CompletionRequest, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn } from 'vscode-languageclient';
@@ -171,8 +171,6 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
171171

172172
Telemetry.startTelemetry(context);
173173

174-
enableJavadocSymbols();
175-
176174
registerOutOfMemoryDetection(storagePath);
177175

178176
cleanJavaWorkspaceStorage();
@@ -816,52 +814,6 @@ export async function getActiveLanguageClient(): Promise<LanguageClient | undefi
816814
return languageClient;
817815
}
818816

819-
function enableJavadocSymbols() {
820-
// Let's enable Javadoc symbols autocompletion, shamelessly copied from MIT licensed code at
821-
// https://github.com/Microsoft/vscode/blob/9d611d4dfd5a4a101b5201b8c9e21af97f06e7a7/extensions/typescript/src/typescriptMain.ts#L186
822-
languages.setLanguageConfiguration('java', {
823-
indentationRules: {
824-
// ^(.*\*/)?\s*\}.*$
825-
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
826-
// ^.*\{[^}"']*$
827-
increaseIndentPattern: /^.*\{[^}"']*$/
828-
},
829-
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
830-
onEnterRules: [
831-
{
832-
// e.g. /** | */ or /* | */
833-
beforeText: /^\s*\/\*\*?(?!\/)([^\*]|\*(?!\/))*$/,
834-
afterText: /^\s*\*\/$/,
835-
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
836-
},
837-
{
838-
// e.g. /** ...|
839-
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
840-
action: { indentAction: IndentAction.None, appendText: ' * ' }
841-
},
842-
{
843-
// e.g. * ...|
844-
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
845-
action: { indentAction: IndentAction.None, appendText: '* ' }
846-
},
847-
{
848-
// e.g. */|
849-
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
850-
action: { indentAction: IndentAction.None, removeText: 1 }
851-
},
852-
{
853-
// e.g. *-----*/|
854-
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
855-
action: { indentAction: IndentAction.None, removeText: 1 }
856-
},
857-
{
858-
// e.g. /// ...| (Markdown javadoc)
859-
beforeText: /^\s*\/\/\/(.*)?$/,
860-
action: { indentAction: IndentAction.None, appendText: '/// ' }
861-
}
862-
]
863-
});
864-
}
865817

866818
export function getTempWorkspace() {
867819
return path.resolve(os.tmpdir(), `vscodesws_${makeRandomHexString(5)}`);

0 commit comments

Comments
 (0)