Skip to content

Commit 4e46844

Browse files
committed
Added new indentation rules for multi-line comments
1 parent 322594f commit 4e46844

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

vscode-extension-src/extension.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { LOG } from './logger';
1111

1212
// this method is called when your extension is activated
1313
// your extension is activated the very first time the command is executed
14-
export async function activate(context: vscode.ExtensionContext) {
14+
export async function activate(context: vscode.ExtensionContext): Promise<void> {
15+
configureLanguage();
16+
1517
LOG.info('Activating Kotlin language server...');
1618
let barItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
1719
context.subscriptions.push(barItem);
@@ -77,9 +79,51 @@ export async function activate(context: vscode.ExtensionContext) {
7779
}
7880

7981
// this method is called when your extension is deactivated
80-
export function deactivate() {}
82+
export function deactivate(): void {}
83+
84+
function configureLanguage(): void {
85+
// Source: https://github.com/Microsoft/vscode/blob/9d611d4dfd5a4a101b5201b8c9e21af97f06e7a7/extensions/typescript/src/typescriptMain.ts#L186
86+
// License: https://github.com/Microsoft/vscode/blob/9d611d4dfd5a4a101b5201b8c9e21af97f06e7a7/extensions/typescript/OSSREADME.json
87+
vscode.languages.setLanguageConfiguration("kotlin", {
88+
indentationRules: {
89+
// ^(.*\*/)?\s*\}.*$
90+
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
91+
// ^.*\{[^}"']*$
92+
increaseIndentPattern: /^.*\{[^}"']*$/
93+
},
94+
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
95+
onEnterRules: [
96+
{
97+
// e.g. /** | */
98+
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
99+
afterText: /^\s*\*\/$/,
100+
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: ' * ' }
101+
},
102+
{
103+
// e.g. /** ...|
104+
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
105+
action: { indentAction: vscode.IndentAction.None, appendText: ' * ' }
106+
},
107+
{
108+
// e.g. * ...|
109+
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
110+
action: { indentAction: vscode.IndentAction.None, appendText: '* ' }
111+
},
112+
{
113+
// e.g. */|
114+
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
115+
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
116+
},
117+
{
118+
// e.g. *-----*/|
119+
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
120+
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
121+
}
122+
]
123+
});
124+
}
81125

82-
function findJavaExecutable(rawBinname: string) {
126+
function findJavaExecutable(rawBinname: string): string {
83127
let binname = correctBinname(rawBinname);
84128

85129
// First search java.home setting
@@ -124,15 +168,15 @@ function findJavaExecutable(rawBinname: string) {
124168
return binname;
125169
}
126170

127-
function correctBinname(binname: string) {
171+
function correctBinname(binname: string): string {
128172
return binname + ((process.platform === 'win32') ? '.exe' : '');
129173
}
130174

131-
function correctScriptName(binname: string) {
175+
function correctScriptName(binname: string): string {
132176
return binname + ((process.platform === 'win32') ? '.bat' : '');
133177
}
134178

135-
function findJavaExecutableInJavaHome(javaHome: string, binname: string) {
179+
function findJavaExecutableInJavaHome(javaHome: string, binname: string): string {
136180
let workspaces = javaHome.split(path.delimiter);
137181

138182
for (let i = 0; i < workspaces.length; i++) {

0 commit comments

Comments
 (0)