Registry / serialization / vscode-languageserver-types

vscode-languageserver-types

JSON →
library3.17.5jsnpmunverified

The `vscode-languageserver-types` package provides the core TypeScript type definitions for the Language Server Protocol (LSP). It defines the fundamental data structures, interfaces, and enums used to communicate between language clients (like VS Code) and language servers, enabling advanced features such as autocompletion, diagnostics, go-to-definition, and refactoring. This package is a foundational component of the larger `vscode-languageserver-node` ecosystem, offering a stable and well-defined contract for language server implementers. The current stable version is 3.17.5, which aligns with version 3.17 of the Language Server Protocol specification. Releases generally follow the evolution of the LSP and the VS Code language server client/server packages, often with pre-releases indicating upcoming changes. Its key differentiator is being the canonical TypeScript representation of the LSP specification, directly maintained by the VS Code team, ensuring high fidelity and compatibility across the ecosystem.

npm install vscode-languageserver-types
INSTALL
IMPORT
SIG · VSCODE-LANGUAGESER
V
vscode-languageserver-types
serializationjavascriptv3.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.

TextDocumentItem
import { TextDocumentItem } from 'vscode-languageserver-types';
const { TextDocumentItem } = require('vscode-languageserver-types');
Primarily designed for ESM. CommonJS 'require' is deprecated for new TypeScript projects using this library.
Position
import { Position } from 'vscode-languageserver-types';
import * as LSP from 'vscode-languageserver-types'; const pos: LSP.Position;
While `import * as LSP` works, named imports are generally preferred for type clarity and bundler optimizations.
Hover
import { Hover, MarkupKind } from 'vscode-languageserver-types';
Many LSP types like Hover often require importing related enums or interfaces (e.g., `MarkupKind` for `MarkupContent`).

Demonstrates importing core LSP types like `TextDocumentIdentifier`, `Position`, `Range`, `Hover`, and `MarkupKind` to define a document location and construct a basic hover response, illustrating how these types are used in language server communication.

import { TextDocumentIdentifier, Position, Range, Hover, MarkupContent, MarkupKind } from 'vscode-languageserver-types'; // Example: Representing a document and a specific position within it. const documentUri: TextDocumentIdentifier = { uri: 'file:///path/to/my/document.ts' }; const caretPosition: Position = { line: 5, character: 10 }; // Example: Defining a range in the document. const selectionRange: Range = { start: { line: 4, character: 0 }, end: { line: 4, character: 20 } }; // Example: Creating a Hover response for a language server. const hoverContent: MarkupContent = { kind: MarkupKind.Markdown, value: [ '```typescript', 'function exampleFunction(param: string): number', '```', 'This is an example function that takes a string and returns a number.' ].join('\n') }; const hoverResult: Hover = { contents: hoverContent, range: selectionRange }; console.log('Document URI:', documentUri.uri); console.log('Caret Position:', caretPosition); console.log('Hover Result:', JSON.stringify(hoverResult, null, 2)); // In a real language server, these types would be used for request/response bodies. // For instance, a client might send a `TextDocumentPositionParams` with `documentUri` and `caretPosition`, // and the server would respond with a `Hover` object using these types.
Debug
Known issues
breakingMajor Language Server Protocol (LSP) version changes (e.g., from 2.x to 3.x or 3.x to 4.x) introduce breaking changes to the types in this package. These changes are intentional to reflect the evolving protocol specification.
fix
Ensure your `vscode-languageserver-types` package version strictly aligns with the LSP specification version your client and server expect. When upgrading LSP versions, simultaneously upgrade `vscode-languageserver-types` and other related `vscode-languageserver-node` packages (client, server, protocol) to compatible versions.
affects: <=2.x migrating to >=3.x
gotchaMismatched versions between `vscode-languageserver-types` and other packages within the `vscode-languageserver-node` ecosystem (e.g., `vscode-languageserver`, `vscode-languageserver-client`) can lead to type incompatibilities, runtime errors, or unexpected behavior.
fix
Always install all `vscode-languageserver-node` ecosystem packages with compatible versions, ideally the same major.minor version, or as indicated by the monorepo's release notes. Use a tool like `npm-check-updates` or refer to the official repository for recommended version pairings.
affects: All versions
gotchaUsing CommonJS `require()` syntax with `vscode-languageserver-types` in modern TypeScript projects can lead to tooling issues or incorrect type inference, as the package is primarily designed for ES Modules (ESM).
fix
Configure your project for ESM (e.g., add `"type": "module"` to `package.json` for Node.js projects) and always use `import ... from '...'` syntax. If using older environments, ensure your bundler (Webpack, Rollup) is configured to handle ESM imports correctly.
affects: All versions >=3.x
Errors
Common errors & fixes
TS2307: Cannot find module 'vscode-languageserver-types' or its corresponding type declarations.
The package is either not installed, or your TypeScript configuration cannot locate its type definitions.
fix
Run `npm install vscode-languageserver-types` or `yarn add vscode-languageserver-types`. Ensure your `tsconfig.json` includes `node_modules/@types` in its `typeRoots` (though usually default) and that the module resolution is correctly configured (e.g., `"moduleResolution": "Node10"` or `"bundler"`).
TS2345: Argument of type '{ contents: string; range: Range; }' is not assignable to parameter of type 'Hover'. Object literal may only specify known properties, and 'contents' does not exist in type 'MarkupContent | MarkedString | MarkedString[]'.
You are providing incorrect type for `Hover.contents` or the structure of `Hover` does not match the version of `vscode-languageserver-types` you are using. Older LSP versions allowed simple strings for `contents`, while newer versions require `MarkupContent` or `MarkedString` arrays.
fix
Update your code to use `MarkupContent` (preferred for new implementations) or an array of `MarkedString` for the `contents` property of `Hover`. For `MarkupContent`, specify `kind` (e.g., `MarkupKind.Markdown`) and `value`. Verify your `vscode-languageserver-types` version against the LSP specification to ensure correct type usage.
Upgrade
Version history
3.17.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
vscode-languageserver-types — npm install vscode-languageserver-types · libregistry