Skip to content

Commit 21afd6e

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

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';
@@ -169,8 +169,6 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
169169

170170
Telemetry.startTelemetry(context);
171171

172-
enableJavadocSymbols();
173-
174172
registerOutOfMemoryDetection(storagePath);
175173

176174
cleanJavaWorkspaceStorage();
@@ -814,52 +812,6 @@ export async function getActiveLanguageClient(): Promise<LanguageClient | undefi
814812
return languageClient;
815813
}
816814

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

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

0 commit comments

Comments
 (0)