CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Pending
Overview
Eval results
Files

language-features.mddocs/

Language Features

Complete Language Server Protocol feature implementations including completion, hover, diagnostics, and all standard LSP capabilities. These features provide the core intelligent code editing experience.

Capabilities

Completion

Provides code completion suggestions including functions, variables, keywords, and snippets.

/**
 * Register handler for completion requests
 * @param handler Function to handle completion requests
 */
onCompletion(handler: RequestHandler<CompletionParams, CompletionItem[] | CompletionList | null, CompletionItem>): Disposable;

/**
 * Register handler for completion item resolve requests
 * @param handler Function to resolve additional completion item details
 */
onCompletionResolve(handler: RequestHandler<CompletionItem, CompletionItem, void>): Disposable;

interface CompletionParams extends TextDocumentPositionParams, WorkDoneProgressParams, PartialResultParams {
    /** The completion context */
    context?: CompletionContext;
}

interface CompletionItem {
    /** The label of this completion item */
    label: string;
    /** The kind of this completion item */
    kind?: CompletionItemKind;
    /** A human-readable string with additional information about this item */
    detail?: string;
    /** A human-readable string that represents a doc-comment */
    documentation?: string | MarkupContent;
    /** Indicates if this item is deprecated */
    deprecated?: boolean;
    /** The string that should be inserted into a document when selecting this completion */
    insertText?: string;
    /** The format of the insert text */
    insertTextFormat?: InsertTextFormat;
    /** An edit which is applied to a document when selecting this completion */
    textEdit?: TextEdit | InsertReplaceEdit;
    /** Additional text edits that are applied when selecting this completion */
    additionalTextEdits?: TextEdit[];
    /** An optional command that is executed after inserting this completion */
    command?: Command;
    /** Data that is preserved during completion resolve */
    data?: any;
}

interface CompletionList {
    /** This list is not complete */
    isIncomplete: boolean;
    /** The completion items */
    items: CompletionItem[];
}

Usage Example:

connection.onCompletion((params): CompletionItem[] => {
    return [
        {
            label: 'console.log',
            kind: CompletionItemKind.Function,
            detail: 'Log to console',
            documentation: 'Outputs a message to the console',
            insertText: 'console.log($1)',
            insertTextFormat: InsertTextFormat.Snippet
        }
    ];
});

connection.onCompletionResolve((item): CompletionItem => {
    if (item.data === 'console.log') {
        item.documentation = {
            kind: 'markdown',
            value: '**console.log(message: any, ...optionalParams: any[]): void**\n\nOutputs a message to the console.'
        };
    }
    return item;
});

Hover

Provides hover information when users hover over symbols.

/**
 * Register handler for hover requests
 * @param handler Function to handle hover requests
 */
onHover(handler: RequestHandler<HoverParams, Hover | null, void>): Disposable;

interface HoverParams extends TextDocumentPositionParams, WorkDoneProgressParams {
}

interface Hover {
    /** The hover's content */
    contents: MarkedString | MarkedString[] | MarkupContent;
    /** An optional range is a range inside a text document that is used to visualize a hover */
    range?: Range;
}

type MarkedString = string | { language: string; value: string };

interface MarkupContent {
    /** The type of the Markup */
    kind: MarkupKind;
    /** The content itself */
    value: string;
}

enum MarkupKind {
    PlainText = 'plaintext',
    Markdown = 'markdown'
}

Usage Example:

connection.onHover((params): Hover | null => {
    const document = documents.get(params.textDocument.uri);
    if (!document) return null;
    
    const position = params.position;
    const word = getWordAtPosition(document, position);
    
    if (word === 'console') {
        return {
            contents: {
                kind: MarkupKind.Markdown,
                value: '**console**\n\nProvides access to the browser or Node.js debugging console.'
            },
            range: getWordRangeAtPosition(document, position)
        };
    }
    
    return null;
});

Go to Definition

Provides navigation to symbol definitions.

/**
 * Register handler for go to definition requests
 * @param handler Function to handle definition requests
 */
onDefinition(handler: RequestHandler<DefinitionParams, Definition | DefinitionLink[] | null, void>): Disposable;

interface DefinitionParams extends TextDocumentPositionParams, WorkDoneProgressParams, PartialResultParams {
}

type Definition = Location | Location[];

interface DefinitionLink {
    /** Span of the origin of this link */
    originSelectionRange?: Range;
    /** The target resource identifier of this link */
    targetUri: DocumentUri;
    /** The full target range of this link */
    targetRange: Range;
    /** The range that should be selected and revealed when this link is followed */
    targetSelectionRange: Range;
}

interface Location {
    uri: DocumentUri;
    range: Range;
}

Find References

Finds all references to a symbol.

/**
 * Register handler for find references requests
 * @param handler Function to handle references requests
 */
onReferences(handler: RequestHandler<ReferenceParams, Location[] | null, void>): Disposable;

interface ReferenceParams extends TextDocumentPositionParams, WorkDoneProgressParams, PartialResultParams {
    context: ReferenceContext;
}

interface ReferenceContext {
    /** Include the declaration of the current symbol */
    includeDeclaration: boolean;
}

Document Highlights

Highlights all occurrences of a symbol in a document.

/**
 * Register handler for document highlight requests
 * @param handler Function to handle document highlight requests
 */
onDocumentHighlight(handler: RequestHandler<DocumentHighlightParams, DocumentHighlight[] | null, void>): Disposable;

interface DocumentHighlightParams extends TextDocumentPositionParams, WorkDoneProgressParams, PartialResultParams {
}

interface DocumentHighlight {
    /** The range this highlight applies to */
    range: Range;
    /** The highlight kind */
    kind?: DocumentHighlightKind;
}

enum DocumentHighlightKind {
    /** A textual occurrence */
    Text = 1,
    /** Read-access of a symbol */
    Read = 2,
    /** Write-access of a symbol */
    Write = 3
}

Document Symbols

Provides hierarchical symbols for a document.

/**
 * Register handler for document symbol requests
 * @param handler Function to handle document symbol requests
 */
onDocumentSymbol(handler: RequestHandler<DocumentSymbolParams, SymbolInformation[] | DocumentSymbol[] | null, void>): Disposable;

interface DocumentSymbolParams extends WorkDoneProgressParams, PartialResultParams {
    /** The text document */
    textDocument: TextDocumentIdentifier;
}

interface DocumentSymbol {
    /** The name of this symbol */
    name: string;
    /** More detail for this symbol */
    detail?: string;
    /** The kind of this symbol */
    kind: SymbolKind;
    /** Tags for this symbol */
    tags?: SymbolTag[];
    /** Indicates if this symbol is deprecated */
    deprecated?: boolean;
    /** The range enclosing this symbol */
    range: Range;
    /** The range that should be selected and revealed when this symbol is being picked */
    selectionRange: Range;
    /** Children of this symbol */
    children?: DocumentSymbol[];
}

interface SymbolInformation {
    /** The name of this symbol */
    name: string;
    /** The kind of this symbol */
    kind: SymbolKind;
    /** Tags for this symbol */
    tags?: SymbolTag[];
    /** Indicates if this symbol is deprecated */
    deprecated?: boolean;
    /** The location of this symbol */
    location: Location;
    /** The name of the symbol containing this symbol */
    containerName?: string;
}

Workspace Symbols

Provides workspace-wide symbol search.

/**
 * Register handler for workspace symbol requests
 * @param handler Function to handle workspace symbol requests
 */
onWorkspaceSymbol(handler: RequestHandler<WorkspaceSymbolParams, SymbolInformation[] | WorkspaceSymbol[] | null, WorkspaceSymbol>): Disposable;

/**
 * Register handler for workspace symbol resolve requests
 * @param handler Function to resolve workspace symbol details
 */
onWorkspaceSymbolResolve(handler: RequestHandler<WorkspaceSymbol, WorkspaceSymbol, void>): Disposable;

interface WorkspaceSymbolParams extends WorkDoneProgressParams, PartialResultParams {
    /** A query string to filter symbols by */
    query: string;
}

interface WorkspaceSymbol {
    /** The name of this symbol */
    name: string;
    /** The kind of this symbol */
    kind: SymbolKind;
    /** Tags for this symbol */
    tags?: SymbolTag[];
    /** The name of the symbol containing this symbol */
    containerName?: string;
    /** The location of the symbol */
    location: Location | { uri: DocumentUri };
    /** Data that is preserved during resolve */
    data?: any;
}

Code Actions

Provides code actions like quick fixes and refactorings.

/**
 * Register handler for code action requests
 * @param handler Function to handle code action requests
 */
onCodeAction(handler: RequestHandler<CodeActionParams, (Command | CodeAction)[] | null, void>): Disposable;

/**
 * Register handler for code action resolve requests
 * @param handler Function to resolve code action details
 */
onCodeActionResolve(handler: RequestHandler<CodeAction, CodeAction, void>): Disposable;

interface CodeActionParams extends WorkDoneProgressParams, PartialResultParams {
    /** The document in which the command was invoked */
    textDocument: TextDocumentIdentifier;
    /** The range for which the command was invoked */
    range: Range;
    /** Context carrying additional information */
    context: CodeActionContext;
}

interface CodeActionContext {
    /** An array of diagnostics known on the client side overlapping the range provided to the code action request */
    diagnostics: Diagnostic[];
    /** Requested kinds of actions to return */
    only?: CodeActionKind[];
    /** The reason why code actions were requested */
    triggerKind?: CodeActionTriggerKind;
}

interface CodeAction {
    /** A short, human-readable, title for this code action */
    title: string;
    /** The kind of the code action */
    kind?: CodeActionKind;
    /** The diagnostics that this code action resolves */
    diagnostics?: Diagnostic[];
    /** Marks this as a preferred action */
    isPreferred?: boolean;
    /** Marks that the code action cannot currently be applied */
    disabled?: { reason: string };
    /** The workspace edit this code action performs */
    edit?: WorkspaceEdit;
    /** A command this code action executes */
    command?: Command;
    /** Data that is preserved during resolve */
    data?: any;
}

Formatting

Provides document and range formatting capabilities.

/**
 * Register handler for document formatting requests
 * @param handler Function to handle document formatting requests
 */
onDocumentFormatting(handler: RequestHandler<DocumentFormattingParams, TextEdit[] | null, void>): Disposable;

/**
 * Register handler for document range formatting requests
 * @param handler Function to handle range formatting requests
 */
onDocumentRangeFormatting(handler: RequestHandler<DocumentRangeFormattingParams, TextEdit[] | null, void>): Disposable;

/**
 * Register handler for document on-type formatting requests
 * @param handler Function to handle on-type formatting requests
 */
onDocumentOnTypeFormatting(handler: RequestHandler<DocumentOnTypeFormattingParams, TextEdit[] | null, void>): Disposable;

interface DocumentFormattingParams extends WorkDoneProgressParams {
    /** The document to format */
    textDocument: TextDocumentIdentifier;
    /** The format options */
    options: FormattingOptions;
}

interface DocumentRangeFormattingParams extends WorkDoneProgressParams {
    /** The document to format */
    textDocument: TextDocumentIdentifier;
    /** The range to format */
    range: Range;
    /** The format options */
    options: FormattingOptions;
}

interface DocumentOnTypeFormattingParams extends TextDocumentPositionParams {
    /** The character that has been typed */
    ch: string;
    /** The format options */
    options: FormattingOptions;
}

interface FormattingOptions {
    /** Size of a tab in spaces */
    tabSize: number;
    /** Prefer spaces over tabs */
    insertSpaces: boolean;
    /** Trim trailing whitespace on a line */
    trimTrailingWhitespace?: boolean;
    /** Insert a newline character at the end of the file if one does not exist */
    insertFinalNewline?: boolean;
    /** Trim all newlines after the final newline at the end of the file */
    trimFinalNewlines?: boolean;
}

Rename

Provides symbol renaming capabilities.

/**
 * Register handler for rename requests
 * @param handler Function to handle rename requests
 */
onRename(handler: RequestHandler<RenameParams, WorkspaceEdit | null, void>): Disposable;

/**
 * Register handler for prepare rename requests
 * @param handler Function to handle prepare rename requests
 */
onPrepareRename(handler: RequestHandler<PrepareRenameParams, Range | { range: Range; placeholder: string } | { defaultBehavior: boolean } | null, void>): Disposable;

interface RenameParams extends TextDocumentPositionParams, WorkDoneProgressParams {
    /** The new name of the symbol */
    newName: string;
}

interface PrepareRenameParams extends TextDocumentPositionParams, WorkDoneProgressParams {
}

interface WorkspaceEdit {
    /** Holds changes to existing resources */
    changes?: { [uri: DocumentUri]: TextEdit[] };
    /** Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes are either an array of `TextDocumentEdit`s to express changes to n different text documents where each text document edit addresses a specific version of a text document */
    documentChanges?: (TextDocumentEdit | CreateFile | RenameFile | DeleteFile)[];
    /** A map of change annotations that can be referenced in document edits */
    changeAnnotations?: { [id: string]: ChangeAnnotation };
}

Core Types

interface TextDocumentPositionParams {
    /** The text document */
    textDocument: TextDocumentIdentifier;
    /** The position inside the text document */
    position: Position;
}

interface WorkDoneProgressParams {
    /** An optional token that a server can use to report work done progress */
    workDoneToken?: ProgressToken;
}

interface PartialResultParams {
    /** An optional token that a server can use to report partial results to the client */
    partialResultToken?: ProgressToken;
}

type ProgressToken = number | string;

interface Command {
    /** Title of the command */
    title: string;
    /** The identifier of the actual command handler */
    command: string;
    /** Arguments that the command handler should be invoked with */
    arguments?: any[];
}

enum SymbolKind {
    File = 1,
    Module = 2,
    Namespace = 3,
    Package = 4,
    Class = 5,
    Method = 6,
    Property = 7,
    Field = 8,
    Constructor = 9,
    Enum = 10,
    Interface = 11,
    Function = 12,
    Variable = 13,
    Constant = 14,
    String = 15,
    Number = 16,
    Boolean = 17,
    Array = 18,
    Object = 19,
    Key = 20,
    Null = 21,
    EnumMember = 22,
    Struct = 23,
    Event = 24,
    Operator = 25,
    TypeParameter = 26
}

enum CompletionItemKind {
    Text = 1,
    Method = 2,
    Function = 3,
    Constructor = 4,
    Field = 5,
    Variable = 6,
    Class = 7,
    Interface = 8,
    Module = 9,
    Property = 10,
    Unit = 11,
    Value = 12,
    Enum = 13,
    Keyword = 14,
    Snippet = 15,
    Color = 16,
    File = 17,
    Reference = 18,
    Folder = 19,
    EnumMember = 20,
    Constant = 21,
    Struct = 22,
    Event = 23,
    Operator = 24,
    TypeParameter = 25
}

enum InsertTextFormat {
    PlainText = 1,
    Snippet = 2
}

Install with Tessl CLI

npx tessl i tessl/npm-vscode-languageserver

docs

connection.md

documents.md

extended-features.md

index.md

language-features.md

notebooks.md

utilities.md

tile.json