What is vscode-languageclient?
The vscode-languageclient npm package is a library that helps in creating language clients for Visual Studio Code extensions. It facilitates communication between the client (VS Code) and the language server, enabling features like auto-completion, go-to-definition, and diagnostics.
What are vscode-languageclient's main functionalities?
Initialize Language Client
This code initializes a language client that communicates with a language server. The client is configured to listen to plaintext files and synchronize file events.
const { LanguageClient, TransportKind } = require('vscode-languageclient/node');
const client = new LanguageClient(
'languageServerExample',
'Language Server Example',
{
command: 'path/to/language-server',
args: [],
transport: TransportKind.stdio
},
{
documentSelector: [{ scheme: 'file', language: 'plaintext' }],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
}
}
);
client.start();
Handle Server Notifications
This code sets up a handler for custom notifications sent from the language server to the client. It logs the received notification parameters to the console.
client.onReady().then(() => {
client.onNotification('custom/notification', (params) => {
console.log('Received custom notification:', params);
});
});
Send Custom Requests
This code sends a custom request from the client to the language server and logs the server's response.
client.onReady().then(() => {
client.sendRequest('custom/request', { text: 'Hello, server!' }).then((response) => {
console.log('Received response:', response);
});
});
Other packages similar to vscode-languageclient
vscode-languageserver
The vscode-languageserver package provides tools to implement a language server. It is often used in conjunction with vscode-languageclient to create a full language server-client setup. While vscode-languageclient is focused on the client-side, vscode-languageserver provides the server-side implementation.
monaco-languageclient
The monaco-languageclient package is similar to vscode-languageclient but is designed for use with the Monaco Editor, which is the editor that powers VS Code. It allows for language server communication in web-based editors, providing similar functionalities to vscode-languageclient but in a different environment.
lsp-client
The lsp-client package is a lightweight alternative to vscode-languageclient. It provides basic functionalities to communicate with language servers using the Language Server Protocol (LSP). It is less feature-rich but can be a good choice for simpler use cases.
VSCode Language Server - Client Module
This npm module allows VSCode extensions to easily integrate language servers adhering to the language server protocol
See here for a detailed documentation on how to
implement language servers for VSCode.
History
For the history please see the main repository
License
MIT