or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

connection.mddocuments.mdextended-features.mdindex.mdlanguage-features.mdnotebooks.mdutilities.md
tile.json

tessl/npm-vscode-languageserver

Language Server Protocol implementation for Node.js providing comprehensive LSP server capabilities including text synchronization, diagnostics, code completion, and workspace symbol searching

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/vscode-languageserver@9.0.x

To install, run

npx @tessl/cli install tessl/npm-vscode-languageserver@9.0.0

index.mddocs/

VSCode Language Server

The VSCode Language Server is a comprehensive implementation of the Language Server Protocol (LSP) for Node.js and browser environments. It provides server-side infrastructure for building language servers that power intelligent code features in Visual Studio Code and other editors supporting LSP.

Package Information

  • Package Name: vscode-languageserver
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install vscode-languageserver

Core Imports

import { createConnection, TextDocuments, ProposedFeatures } from "vscode-languageserver";
import { TextDocument } from "vscode-languageserver-textdocument";

For CommonJS:

const { createConnection, TextDocuments, ProposedFeatures } = require("vscode-languageserver");

Node.js specific imports:

import { createConnection } from "vscode-languageserver/node";

Browser specific imports:

import { createConnection } from "vscode-languageserver/browser";

Basic Usage

import { createConnection, TextDocuments, ProposedFeatures } from "vscode-languageserver";
import { TextDocument } from "vscode-languageserver-textdocument";

// Create a connection for the server
const connection = createConnection(ProposedFeatures.all);

// Create a simple text document manager
const documents = new TextDocuments(TextDocument);

// Listen for document changes
documents.onDidChangeContent(change => {
    // Validate the document when its content has changed
    validateTextDocument(change.document);
});

// Listen for when a text document is opened
documents.onDidOpen(event => {
    validateTextDocument(event.document);
});

// Provide hover information
connection.onHover(params => {
    return {
        contents: "Hover information here"
    };
});

// Start listening for messages
documents.listen(connection);
connection.listen();

Architecture

The VSCode Language Server is built around several key components:

  • Connection Management: Creates and manages the communication channel between client and server
  • Document Lifecycle: Tracks and synchronizes text documents between client and server
  • Feature Handlers: Implements LSP request/notification handlers for language features
  • Type System: Full TypeScript integration with comprehensive LSP protocol types
  • Cross-Platform Support: Works in both Node.js and browser environments
  • Feature Composition: Extensible architecture supporting both standard and proposed LSP features

Capabilities

Connection Management

Core connection establishment and communication infrastructure for Language Server Protocol implementations. Essential for all language servers.

function createConnection(): Connection;
function createConnection(options?: ConnectionStrategy | ConnectionOptions): Connection;
function createConnection(
    inputStream: NodeJS.ReadableStream, 
    outputStream: NodeJS.WritableStream, 
    options?: ConnectionStrategy | ConnectionOptions
): Connection;
function createConnection(
    reader: MessageReader, 
    writer: MessageWriter, 
    options?: ConnectionStrategy | ConnectionOptions
): Connection;

Connection Management

Document Management

Text document lifecycle management and synchronization between client and server. Handles document open, change, save, and close events.

class TextDocuments<T extends { uri: DocumentUri }> {
    constructor(configuration: TextDocumentsConfiguration<T>);
    onDidOpen: Event<TextDocumentChangeEvent<T>>;
    onDidClose: Event<TextDocumentChangeEvent<T>>;
    onDidChangeContent: Event<TextDocumentChangeEvent<T>>;
    onDidSave: Event<TextDocumentChangeEvent<T>>;
    onWillSave: Event<TextDocumentWillSaveEvent<T>>;
    get(uri: DocumentUri): T | undefined;
    all(): T[];
    keys(): DocumentUri[];
    listen(connection: TextDocumentConnection): void;
}

interface TextDocumentsConfiguration<T extends { uri: DocumentUri }> {
    create(uri: DocumentUri, languageId: string, version: number, content: string): T;
    update(document: T, changes: TextDocumentContentChangeEvent[], version: number): T;
}

Document Management

Language Features

Complete Language Server Protocol feature implementations including completion, hover, diagnostics, and all standard LSP capabilities.

interface Connection {
    onCompletion(handler: CompletionHandler): Disposable;
    onHover(handler: HoverHandler): Disposable;
    onDefinition(handler: DefinitionHandler): Disposable;
    onReferences(handler: ReferencesHandler): Disposable;
    onDocumentSymbol(handler: DocumentSymbolHandler): Disposable;
    // ... all other LSP handlers
}

type CompletionHandler = RequestHandler<CompletionParams, CompletionItem[] | CompletionList | null, CompletionItem>;
type HoverHandler = RequestHandler<HoverParams, Hover | null, void>;
type DefinitionHandler = RequestHandler<DefinitionParams, Definition | DefinitionLink[] | null, void>;

Language Features

Extended Features

Advanced Language Server Protocol features including semantic tokens, call hierarchy, type hierarchy, and diagnostics.

interface Languages {
    semanticTokens: {
        on(handler: SemanticTokensHandler): Disposable;
        onDelta(handler: SemanticTokensDeltaHandler): Disposable;
        onRange(handler: SemanticTokensRangeHandler): Disposable;
        refresh(): void;
    };
    callHierarchy: {
        onPrepare(handler: CallHierarchyPrepareHandler): Disposable;
        onIncomingCalls(handler: CallHierarchyIncomingCallsHandler): Disposable;
        onOutgoingCalls(handler: CallHierarchyOutgoingCallsHandler): Disposable;
    };
    typeHierarchy: {
        onPrepare(handler: TypeHierarchyPrepareHandler): Disposable;
        onSupertypes(handler: TypeHierarchySupertypesHandler): Disposable;
        onSubtypes(handler: TypeHierarchySubtypesHandler): Disposable;
    };
}

Extended Features

Notebook Support

Notebook document synchronization and management for Jupyter notebooks and other notebook formats. Supports both notebook-level and cell-level text document management.

class NotebookDocuments<T extends { uri: DocumentUri }> {
    constructor(configurationOrTextDocuments: TextDocumentsConfiguration<T> | TextDocuments<T>);
    onDidOpen: Event<NotebookDocument>;
    onDidChange: Event<NotebookDocumentChangeEvent>;
    onDidSave: Event<NotebookDocument>;
    onDidClose: Event<NotebookDocument>;
    getCellTextDocument(cellUri: DocumentUri): T | undefined;
    getNotebookDocument(notebookUri: DocumentUri): NotebookDocument | undefined;
    getNotebookCell(cellUri: DocumentUri): NotebookCell | undefined;
}

Notebook Support

Utility Classes

Helper classes for common language server tasks including semantic token building, error tracking, and progress reporting.

class SemanticTokensBuilder {
    constructor();
    push(line: number, char: number, length: number, tokenType: number, tokenModifiers?: number): void;
    build(): SemanticTokens;
    buildEdits(): SemanticTokensEdits;
}

class ErrorMessageTracker {
    constructor();
    add(message: string): void;
    sendErrors(connection: { window: RemoteWindow }): void;
}

Utility Classes

Core Types

interface Connection extends _Connection {
    console: RemoteConsole;
    tracer: RemoteTracer;
    telemetry: Telemetry;
    client: RemoteClient;
    window: RemoteWindow;
    workspace: RemoteWorkspace;
    languages: Languages;
    notebooks: Notebooks;
    
    onInitialize(handler: RequestHandler<InitializeParams, InitializeResult, InitializeError>): Disposable;
    onInitialized(handler: NotificationHandler<InitializedParams>): Disposable;
    onShutdown(handler: RequestHandler0<void, void>): Disposable;
    onExit(handler: NotificationHandler0): Disposable;
    
    sendDiagnostics(params: PublishDiagnosticsParams): void;
    sendProgress<T>(type: ProgressType<T>, token: string | number, value: T): void;
    
    listen(): void;
    dispose(): void;
}

interface TextDocumentChangeEvent<T> {
    document: T;
}

interface TextDocumentWillSaveEvent<T> {
    document: T;
    reason: TextDocumentSaveReason;
}

type DocumentUri = string;

interface Disposable {
    dispose(): void;
}

type Event<T> = (listener: (e: T) => any, thisArg?: any) => Disposable;