best way for client to get server version #1349
Replies: 2 comments 1 reply
-
Hi Dfgordon. I interacted with copilot regarding your question and it provided the following suggestion. Let me know if this helps. Copilot Suggestion To check the server version using vscode-languageclient/node, you can listen for the onReady event of the LanguageClient instance. This event is fired when the client is ready and the server has sent back the initializeResult, including the serverInfo. Here is how you can achieve this:
Here is an example implementation: import * as vscode from 'vscode';
import * as path from 'path';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';
export function activate(context: vscode.ExtensionContext) {
// Server configuration
const serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'));
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
const serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Client configuration
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'plaintext' }],
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/.clientrc')
}
};
// Create the language client
const client = new LanguageClient(
'languageServerExample',
'Language Server Example',
serverOptions,
clientOptions
);
// Listen for the onReady event
client.onReady().then(() => {
const initializeResult = client.initializeResult;
if (initializeResult && initializeResult.serverInfo) {
const serverVersion = initializeResult.serverInfo.version;
console.log(`Server version: ${serverVersion}`);
// You can now use the server version as needed
}
});
// Start the client
context.subscriptions.push(client.start());
}
export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
} |
Beta Was this translation helpful? Give feedback.
-
Thanks Reynald, that lead me to the answer. Starting with version 8 you can simply |
Beta Was this translation helpful? Give feedback.
-
I would like my client that uses
vscode-languageclient/node
to check the server version. I found that the client populatesclient.initializeResult.serverInfo.version
at some point during startup, but I can't figure out which event to listen for. One workaround I found is to do it as a side effect of some unrelated notification.The question is whether
vscode-languageclient/node
provides something explicitly for this purpose, like something to listen for that fires when the server sends back theinitializeResult
.I have control of the server and could generate a notification, but in general one might not have that.
Beta Was this translation helpful? Give feedback.
All reactions