@@ -11,7 +11,9 @@ import { LOG } from './logger';
11
11
12
12
// this method is called when your extension is activated
13
13
// 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
+
15
17
LOG . info ( 'Activating Kotlin language server...' ) ;
16
18
let barItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
17
19
context . subscriptions . push ( barItem ) ;
@@ -77,9 +79,51 @@ export async function activate(context: vscode.ExtensionContext) {
77
79
}
78
80
79
81
// 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
+ }
81
125
82
- function findJavaExecutable ( rawBinname : string ) {
126
+ function findJavaExecutable ( rawBinname : string ) : string {
83
127
let binname = correctBinname ( rawBinname ) ;
84
128
85
129
// First search java.home setting
@@ -124,15 +168,15 @@ function findJavaExecutable(rawBinname: string) {
124
168
return binname ;
125
169
}
126
170
127
- function correctBinname ( binname : string ) {
171
+ function correctBinname ( binname : string ) : string {
128
172
return binname + ( ( process . platform === 'win32' ) ? '.exe' : '' ) ;
129
173
}
130
174
131
- function correctScriptName ( binname : string ) {
175
+ function correctScriptName ( binname : string ) : string {
132
176
return binname + ( ( process . platform === 'win32' ) ? '.bat' : '' ) ;
133
177
}
134
178
135
- function findJavaExecutableInJavaHome ( javaHome : string , binname : string ) {
179
+ function findJavaExecutableInJavaHome ( javaHome : string , binname : string ) : string {
136
180
let workspaces = javaHome . split ( path . delimiter ) ;
137
181
138
182
for ( let i = 0 ; i < workspaces . length ; i ++ ) {
0 commit comments