@@ -25,7 +25,7 @@ export let defaultClient: LuaClient | null;
2525
2626function registerCustomCommands ( context : ExtensionContext ) {
2727 context . subscriptions . push ( Commands . registerCommand ( 'lua.config' , ( changes ) => {
28- const propMap : Map < string , Map < string , unknown > > = new Map ( ) ;
28+ const propMap : Record < string , Record < string , unknown > > = { } ;
2929
3030 for ( const data of changes ) {
3131 const config = Workspace . getConfiguration ( undefined , Uri . parse ( data . uri ) ) ;
@@ -43,7 +43,10 @@ function registerCustomCommands(context: ExtensionContext) {
4343 }
4444 if ( data . action === 'prop' ) {
4545 if ( ! propMap [ data . key ] ) {
46- propMap [ data . key ] = config . get ( data . key ) ;
46+ let prop = config . get ( data . key ) ;
47+ if ( typeof prop === 'object' && prop !== null ) {
48+ propMap [ data . key ] = prop as Record < string , unknown > ;
49+ }
4750 }
4851 propMap [ data . key ] [ data . prop ] = data . value ;
4952 config . update ( data . key , propMap [ data . key ] , data . global ) ;
@@ -71,14 +74,14 @@ function registerCustomCommands(context: ExtensionContext) {
7174 if ( ! output ) {
7275 return ;
7376 }
74- defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
77+ defaultClient . client ? .sendRequest ( ExecuteCommandRequest . type , {
7578 command : 'lua.exportDocument' ,
7679 arguments : [ output . toString ( ) ] ,
7780 } ) ;
7881 } ) ) ;
7982
8083 context . subscriptions . push ( Commands . registerCommand ( 'lua.reloadFFIMeta' , async ( ) => {
81- defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
84+ defaultClient ? .client ? .sendRequest ( ExecuteCommandRequest . type , {
8285 command : 'lua.reloadFFIMeta' ,
8386 } )
8487 } ) )
@@ -100,7 +103,7 @@ export const createClient = (context: ExtensionContext) => {
100103}
101104
102105class LuaClient extends Disposable {
103- public client : LanguageClient ;
106+ public client : LanguageClient | undefined ;
104107 private disposables = new Array < Disposable > ( ) ;
105108 constructor (
106109 private context : ExtensionContext ,
@@ -241,14 +244,14 @@ class LuaClient extends Disposable {
241244 }
242245
243246 async stop ( ) {
244- this . client . stop ( ) ;
247+ this . client ? .stop ( ) ;
245248 for ( const disposable of this . disposables ) {
246249 disposable . dispose ( ) ;
247250 }
248251 }
249252
250253 statusBar ( ) {
251- const client = this . client ;
254+ const client = this . client ! ;
252255 const bar = window . createStatusBarItem ( vscode . StatusBarAlignment . Right ) ;
253256 bar . text = "Lua" ;
254257 bar . command = "Lua.statusBar" ;
@@ -278,6 +281,9 @@ class LuaClient extends Disposable {
278281 }
279282
280283 onCommand ( ) {
284+ if ( ! this . client ) {
285+ return ;
286+ }
281287 this . disposables . push (
282288 this . client . onNotification ( "$/command" , ( params ) => {
283289 Commands . executeCommand ( params . command , params . data ) ;
@@ -318,10 +324,10 @@ export async function reportAPIDoc(params: unknown) {
318324 if ( ! defaultClient ) {
319325 return ;
320326 }
321- defaultClient . client . sendNotification ( '$/api/report' , params ) ;
327+ defaultClient . client ? .sendNotification ( '$/api/report' , params ) ;
322328}
323329
324- type ConfigChange = {
330+ export type ConfigChange = {
325331 action : "set" ,
326332 key : string ,
327333 value : LSPAny ,
@@ -357,7 +363,7 @@ export async function setConfig(changes: ConfigChange[]): Promise<boolean> {
357363 global : change . global ,
358364 } ) ;
359365 }
360- await defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
366+ await defaultClient . client ? .sendRequest ( ExecuteCommandRequest . type , {
361367 command : 'lua.setConfig' ,
362368 arguments : params ,
363369 } ) ;
@@ -368,7 +374,7 @@ export async function getConfig(key: string, uri: vscode.Uri): Promise<LSPAny> {
368374 if ( ! defaultClient ) {
369375 return undefined ;
370376 }
371- return await defaultClient . client . sendRequest ( ExecuteCommandRequest . type , {
377+ return await defaultClient . client ? .sendRequest ( ExecuteCommandRequest . type , {
372378 command : 'lua.getConfig' ,
373379 arguments : [ {
374380 uri : uri . toString ( ) ,
0 commit comments