@@ -20,7 +20,7 @@ import {
2020 ExecuteCommandRequest ,
2121} from 'vscode-languageclient/node' ;
2222
23- export let defaultClient : LuaClient ;
23+ export let defaultClient : LuaClient | null ;
2424
2525function registerCustomCommands ( context : ExtensionContext ) {
2626 context . subscriptions . push ( Commands . registerCommand ( 'lua.config' , ( changes ) => {
@@ -30,7 +30,8 @@ function registerCustomCommands(context: ExtensionContext) {
3030 const config = Workspace . getConfiguration ( undefined , Uri . parse ( data . uri ) ) ;
3131
3232 if ( data . action === 'add' ) {
33- const value : unknown [ ] = config . get ( data . key ) ;
33+ const value = config . get ( data . key ) ;
34+ if ( ! Array . isArray ( value ) ) throw new Error ( `${ data . key } is not an Array!` ) ;
3435 value . push ( data . value ) ;
3536 config . update ( data . key , value , data . global ) ;
3637 continue ;
@@ -48,13 +49,13 @@ function registerCustomCommands(context: ExtensionContext) {
4849 continue ;
4950 }
5051 }
51- } ) )
52+ } ) ) ;
5253
5354 context . subscriptions . push ( Commands . registerCommand ( 'lua.exportDocument' , async ( ) => {
5455 if ( ! defaultClient ) {
5556 return ;
56- } ;
57- let outputs = await vscode . window . showOpenDialog ( {
57+ }
58+ const outputs = await vscode . window . showOpenDialog ( {
5859 defaultUri : vscode . Uri . joinPath (
5960 context . extensionUri ,
6061 'server' ,
@@ -65,15 +66,15 @@ function registerCustomCommands(context: ExtensionContext) {
6566 canSelectFolders : true ,
6667 canSelectMany : false ,
6768 } ) ;
68- let output = outputs ?. [ 0 ] ;
69+ const output = outputs ?. [ 0 ] ;
6970 if ( ! output ) {
7071 return ;
71- } ;
72+ }
7273 defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
7374 command : 'lua.exportDocument' ,
7475 arguments : [ output . toString ( ) ] ,
75- } )
76- } ) )
76+ } ) ;
77+ } ) ) ;
7778}
7879
7980class LuaClient {
@@ -100,9 +101,11 @@ class LuaClient {
100101 } ;
101102
102103 const config = Workspace . getConfiguration ( undefined , vscode . workspace . workspaceFolders ?. [ 0 ] ) ;
103- const commandParam : string [ ] = config . get ( "Lua.misc.parameters" ) ;
104+ const commandParam = config . get ( "Lua.misc.parameters" ) ;
104105 const command = await this . getCommand ( config ) ;
105106
107+ if ( ! Array . isArray ( commandParam ) ) throw new Error ( "Lua.misc.parameters must be an Array!" ) ;
108+
106109 const serverOptions : ServerOptions = {
107110 command : command ,
108111 args : commandParam ,
@@ -122,16 +125,17 @@ class LuaClient {
122125 }
123126
124127 private async getCommand ( config : vscode . WorkspaceConfiguration ) {
125- const executablePath : string = config . get ( "Lua.misc.executablePath" ) ;
128+ const executablePath = config . get ( "Lua.misc.executablePath" ) ;
129+
130+ if ( typeof executablePath !== "string" ) throw new Error ( "Lua.misc.executablePath must be a string!" ) ;
126131
127132 if ( executablePath && executablePath !== "" ) {
128133 return executablePath ;
129134 }
130135
131136 const platform : string = os . platform ( ) ;
132137 let command : string ;
133- let platform : string = os . platform ( ) ;
134- let binDir : string ;
138+ let binDir : string | undefined ;
135139
136140 if ( ( await fs . promises . stat ( this . context . asAbsolutePath ( 'server/bin' ) ) ) . isDirectory ( ) ) {
137141 binDir = 'bin' ;
@@ -225,16 +229,15 @@ export function activate(context: ExtensionContext) {
225229 defaultClient . start ( ) ;
226230 return ;
227231 } else {
228- getConfig ( "Lua.runtime.version" , document . uri ) . then ( ( version ) => {
229- let x = version ;
232+ getConfig ( "Lua.runtime.version" , document . uri ) . then ( ( ) => {
230233 setConfig ( [
231234 {
232235 action : "set" ,
233236 key : "Lua.runtime.version" ,
234237 value : "Lua 5.4" ,
235- uri : document . uri ,
238+ uri : document . uri . toString ( ) ,
236239 }
237- ] )
240+ ] ) ;
238241 } ) ;
239242 }
240243 }
@@ -262,38 +265,38 @@ type ConfigChange = {
262265 action : "set" ,
263266 key : string ,
264267 value : LSPAny ,
265- uri : vscode . Uri ,
268+ uri : string ,
266269 global ?: boolean ,
267270} | {
268271 action : "add" ,
269272 key : string ,
270273 value : LSPAny ,
271- uri : vscode . Uri ,
274+ uri : string ,
272275 global ?: boolean ,
273276} | {
274277 action : "prop" ,
275278 key : string ,
276279 prop : string ;
277280 value : LSPAny ,
278- uri : vscode . Uri ,
281+ uri : string ,
279282 global ?: boolean ,
280283}
281284
282285export async function setConfig ( changes : ConfigChange [ ] ) : Promise < boolean > {
283286 if ( ! defaultClient ) {
284287 return false ;
285288 }
286- let params = [ ] ;
289+ const params : ConfigChange [ ] = [ ] ;
287290 for ( const change of changes ) {
288291 params . push ( {
289292 action : change . action ,
290- prop : ( change . action == "prop" ) ? change . prop : undefined ,
293+ prop : ( change . action === "prop" ) ? change . prop : undefined as never ,
291294 key : change . key ,
292295 value : change . value ,
293296 uri : change . uri . toString ( ) ,
294297 global : change . global ,
295- } )
296- } ;
298+ } ) ;
299+ }
297300 await defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
298301 command : 'lua.setConfig' ,
299302 arguments : params ,
@@ -305,7 +308,7 @@ export async function getConfig(key: string, uri: vscode.Uri): Promise<LSPAny> {
305308 if ( ! defaultClient ) {
306309 return undefined ;
307310 }
308- let result = await defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
311+ const result = await defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
309312 command : 'lua.getConfig' ,
310313 arguments : [ {
311314 uri : uri . toString ( ) ,
0 commit comments