Skip to content

Commit 4de1e43

Browse files
committed
export setConfig and getConfig
1 parent 33cdade commit 4de1e43

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

client/src/languageserver.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
LanguageClientOptions,
1717
ServerOptions,
1818
DocumentSelector,
19+
LSPAny,
20+
ExecuteCommandRequest,
1921
} from 'vscode-languageclient/node';
2022

2123
export let defaultClient: LuaClient;
@@ -188,6 +190,18 @@ export function activate(context: ExtensionContext) {
188190
]);
189191
defaultClient.start();
190192
return;
193+
} else {
194+
getConfig("Lua.runtime.version", document.uri).then((version) => {
195+
let x = version;
196+
setConfig([
197+
{
198+
action: "set",
199+
key: "Lua.runtime.version",
200+
value: "Lua 5.4",
201+
uri: document.uri,
202+
}
203+
])
204+
});
191205
}
192206
}
193207

@@ -209,3 +223,60 @@ export async function reportAPIDoc(params: any) {
209223
}
210224
defaultClient.client.sendNotification('$/api/report', params);
211225
}
226+
227+
type ConfigChange = {
228+
action: "set",
229+
key: string,
230+
value: LSPAny,
231+
uri: vscode.Uri,
232+
global?: boolean,
233+
} | {
234+
action: "add",
235+
key: string,
236+
value: LSPAny,
237+
uri: vscode.Uri,
238+
global?: boolean,
239+
} | {
240+
action: "prop",
241+
key: string,
242+
prop: string;
243+
value: LSPAny,
244+
uri: vscode.Uri,
245+
global?: boolean,
246+
}
247+
248+
export async function setConfig(changes: ConfigChange[]): Promise<boolean> {
249+
if (!defaultClient) {
250+
return false;
251+
}
252+
let params = [];
253+
for (const change of changes) {
254+
params.push({
255+
action: change.action,
256+
prop: (change.action == "prop") ? change.prop : undefined,
257+
key: change.key,
258+
value: change.value,
259+
uri: change.uri.toString(),
260+
global: change.global,
261+
})
262+
};
263+
await defaultClient.client.sendRequest(ExecuteCommandRequest.type, {
264+
command: 'lua.setConfig',
265+
arguments: params,
266+
});
267+
return true;
268+
}
269+
270+
export async function getConfig(key: string, uri: vscode.Uri): Promise<LSPAny> {
271+
if (!defaultClient) {
272+
return undefined;
273+
}
274+
let result = await defaultClient.client.sendRequest(ExecuteCommandRequest.type, {
275+
command: 'lua.getConfig',
276+
arguments: [{
277+
uri: uri.toString(),
278+
key: key,
279+
}]
280+
});
281+
return result;
282+
}

0 commit comments

Comments
 (0)