Registry / type-stubs / vscode-languageserver-protocol

vscode-languageserver-protocol

JSON →
library3.17.5jsnpmunverified

vscode-languageserver-protocol is the official TypeScript and JavaScript implementation of the Language Server Protocol (LSP), maintained by Microsoft. It provides the core data structures, types, and interfaces necessary for implementing language servers and clients that communicate via the LSP specification. The package is currently at stable version 3.17.5, with frequent `next` releases (like 3.17.6-next.17) indicating active development, often in sync with the broader `vscode-languageserver-node` monorepo which includes the `client` and `server` libraries. Its primary differentiator is being the canonical source for LSP definitions, ensuring strong type-safety and adherence to the protocol specification, which is crucial for interoperability between diverse editors and language tools. Unlike its companion packages (`vscode-languageserver` and `vscode-languageserver-client`), this package focuses solely on the protocol's message formats and type definitions, not on the communication transport layer.

npm install vscode-languageserver-protocol
INSTALL
IMPORT
SIG · VSCODE-LANGUAGESER
V
vscode-languageserver-protocol
type-stubsjavascriptv3.17.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

InitializeParams
import { InitializeParams } from 'vscode-languageserver-protocol';
const InitializeParams = require('vscode-languageserver-protocol').InitializeParams;
Prefer ESM imports for type definitions in modern TypeScript/Node.js projects. CommonJS `require` is generally not recommended for this package's types.
RequestType
import { RequestType } from 'vscode-languageserver-protocol';
import RequestType from 'vscode-languageserver-protocol';
All core protocol elements (like `RequestType`, `NotificationType`, `LSPAny`) are named exports, not default exports.
TextDocumentSyncKind
import { TextDocumentSyncKind } from 'vscode-languageserver-protocol';
import { TextDocumentSyncKind } from 'vscode-languageserver/node';
Enums and basic types related to document synchronization and other core features are directly from the `vscode-languageserver-protocol` package, not the client or server runtimes.
ServerCapabilities
import { ServerCapabilities } from 'vscode-languageserver-protocol';
import type { ServerCapabilities } from 'vscode-languageserver-types';
While `vscode-languageserver-types` exists for basic types, `vscode-languageserver-protocol` provides the full, specified interfaces like `ServerCapabilities`.

Demonstrates the definition of language server capabilities and the handling of an `InitializeRequest` using the types provided by `vscode-languageserver-protocol`, emphasizing its role as a type-only package for LSP definitions.

import { InitializeParams, TextDocumentSyncKind, TextDocumentSyncOptions, ServerCapabilities, CompletionItemKind, MarkupKind, Connection, InitializeRequest, InitializeResult, InitializeError, } from 'vscode-languageserver-protocol'; // Define a custom initialization options interface interface MyServerInitializationOptions { enableCustomFeature: boolean; } // Example of how a server might define its capabilities, // leveraging the protocol types. const serverCapabilities: ServerCapabilities = { textDocumentSync: { openClose: true, change: TextDocumentSyncKind.Incremental, willSave: true, willSaveWaitUntil: true, save: { includeText: true, }, } as TextDocumentSyncOptions, completionProvider: { resolveProvider: true, triggerCharacters: ['.', ':'], allCommitCharacters: ['\n', '\t'], completionItem: { labelDetailsSupport: true, }, completionItemKinds: [ CompletionItemKind.Keyword, CompletionItemKind.Variable, CompletionItemKind.Function, ], }, hoverProvider: true, }; // Types for a hypothetical server initialization logic function handleInitializeRequest(params: InitializeParams<MyServerInitializationOptions>): InitializeResult | InitializeError { console.log(`Client requested initialization with custom feature enabled: ${params.initializationOptions?.enableCustomFeature}`); if (params.processId === null) { return { jsonrpc: '2.0', id: null, error: { code: -32602, message: 'processId must not be null', }, }; } return { capabilities: serverCapabilities, serverInfo: { name: 'MyLanguageServer', version: '1.0.0', }, }; } // This connection object is typically provided by vscode-languageserver/node or browser // It's mocked here to show how protocol types fit in. const mockConnection: Connection = { sendRequest: (type, params) => Promise.resolve({ capabilities: {} }), sendNotification: (type, params) => {}, onRequest: (type, handler) => { if (type === InitializeRequest.type) { // Simulate an incoming initialize request handler({ processId: 123, capabilities: {}, initializationOptions: { enableCustomFeature: true } }); } }, onNotification: (type, handler) => {}, listen: () => {}, dispose: () => {}, } as Connection; mockConnection.onRequest(InitializeRequest.type, (params) => handleInitializeRequest(params)); console.log('Protocol types defined and a mock handler registered for demonstration.');
Debug
Known issues
breakingWhile `vscode-languageserver-protocol` is currently at `3.17.x` (LSP 3.17), the related `vscode-languageserver` (server implementation) and `vscode-languageserver-client` packages are actively developing towards `10.0.0-next` releases. This indicates significant breaking changes in the broader LSP ecosystem are anticipated, which may eventually lead to a `4.x` release of the protocol package itself with updated types and message structures, requiring careful migration. Previous major versions of the protocol have introduced breaking changes in message structures and interfaces (e.g., v2.x to v3.x).
fix
Monitor the `vscode-languageserver-node` GitHub repository for upcoming `4.x` protocol releases and consult their migration guides. Keep client and server implementations in sync with the protocol version.
affects: >=3.17
gotchaThis package provides only the TypeScript types and JavaScript interfaces for the Language Server Protocol messages. It does *not* include any runtime for establishing connections, sending messages, or running a language server/client. Developers must use `vscode-languageserver` (for Node.js servers) or `vscode-languageclient` (for VS Code extensions) for the actual communication runtime.
fix
Always pair this protocol package with a corresponding client or server runtime package (e.g., `vscode-languageserver` for server-side logic or `vscode-languageclient` for VS Code extensions) to handle connection and message transport.
affects: >=3.0
gotchaThe `vscode-languageserver-node` monorepo, which includes this package, has migrated to using `exports` property in `package.json` and targets `NodeJS 22.13.14` and `es2022` for recent `next` versions of client/server. This change might require adoption in `tsconfig.json` files around `module` and `moduleResolution` settings (e.g., `node16`).
fix
Ensure your `tsconfig.json` correctly configures `module` and `moduleResolution` (e.g., `"module": "Node16"`, `"moduleResolution": "Node16"`) to correctly resolve module paths, especially when working with newer Node.js versions or consuming pre-release client/server packages.
affects: >=3.17.5
deprecatedOlder versions or legacy setups might use CommonJS `require()` statements. While the package aims for broad compatibility, the ecosystem is moving towards ECMAScript Modules (ESM). Newer versions of the related `vscode-languageserver-node` packages (e.g., 10.x client/server) are built with ESM in mind.
fix
For new projects, prefer ESM `import` statements. If migrating an existing CommonJS project, be aware that mixing CommonJS and ESM can introduce complexities, and a wrapper might be needed for VS Code extensions.
affects: All versions, especially >3.x
gotchaThe `npm audit` alerts related to transitive dependencies (e.g., `serialize-javascript`, `minimatch`, `qs`) are frequently addressed in `next` releases. It's crucial to regularly update your dependencies to the latest patch versions to benefit from security fixes, even if the core protocol itself isn't directly exploitable.
fix
Run `npm audit` regularly and apply suggested fixes. Prioritize updating `vscode-languageserver-protocol` and its related client/server packages to the latest stable or `next` versions that include security patches. Avoid `npm audit fix --force` unless you understand the potential breaking changes.
affects: <3.17.6-next.17
Errors
Common errors & fixes
Cannot find name 'RequestType' / Module '"vscode-languageserver-protocol"' has no exported member 'RequestType'.
Attempting to import a named export incorrectly or from a version that does not expose it.
fix
Ensure correct named import syntax: `import { RequestType } from 'vscode-languageserver-protocol';`. Verify package version compatibility if you are defining custom request/notification types, as their structure has evolved.
TypeError: Cannot read properties of undefined (reading 'syncKind') or similar runtime errors when using types from this package with an old runtime.
Using types from `vscode-languageserver-protocol` but trying to use a `vscode-languageserver` or `vscode-languageclient` runtime that is significantly older or incompatible with the protocol version.
fix
Always keep `vscode-languageserver-protocol`, `vscode-languageserver`, and `vscode-languageclient` packages synchronized to compatible major/minor versions to avoid runtime mismatches, as they are developed within the same monorepo.
Error: `createConnection` is not a function / Module 'vscode-languageserver-protocol' has no exported member 'createConnection'.
`createConnection` is part of the `vscode-languageserver/node` or `vscode-jsonrpc` package, not `vscode-languageserver-protocol`.
fix
Import `createConnection` from the appropriate package, typically `vscode-languageserver/node` for server implementations: `import { createConnection } from 'vscode-languageserver/node';`. The protocol package is for types only.
Upgrade
Version history
3.17.5latest on npm
Audit
Dependencies
vscode-jsonrpcrequiredProvides the underlying JSON-RPC message protocol for communication between client and server. The protocol package depends on its types.
Agent activity
39 hits · last 30 days
node
32
OpenAI (training)
1
Resources