Language Server Protocol implementation for Node.js providing comprehensive LSP server capabilities including text synchronization, diagnostics, code completion, and workspace symbol searching
—
Advanced Language Server Protocol features including semantic tokens, call hierarchy, type hierarchy, and diagnostics. These features provide enhanced code intelligence and navigation capabilities.
Provides semantic syntax highlighting with detailed token classification and modifiers.
/**
* Semantic tokens feature providing enhanced syntax highlighting
*/
interface SemanticTokensFeatureShape {
semanticTokens: {
/** Refresh semantic tokens in the client */
refresh(): void;
/** Register handler for semantic tokens requests */
on(handler: ServerRequestHandler<SemanticTokensParams, SemanticTokens, SemanticTokensPartialResult, void>): Disposable;
/** Register handler for semantic tokens delta requests */
onDelta(handler: ServerRequestHandler<SemanticTokensDeltaParams, SemanticTokensDelta | SemanticTokens, SemanticTokensDeltaPartialResult | SemanticTokensPartialResult, void>): Disposable;
/** Register handler for semantic tokens range requests */
onRange(handler: ServerRequestHandler<SemanticTokensRangeParams, SemanticTokens, SemanticTokensPartialResult, void>): Disposable;
};
}
interface SemanticTokensParams extends WorkDoneProgressParams, PartialResultParams {
/** The text document */
textDocument: TextDocumentIdentifier;
}
interface SemanticTokensRangeParams extends WorkDoneProgressParams, PartialResultParams {
/** The text document */
textDocument: TextDocumentIdentifier;
/** The range to tokenize */
range: Range;
}
interface SemanticTokensDeltaParams extends WorkDoneProgressParams, PartialResultParams {
/** The text document */
textDocument: TextDocumentIdentifier;
/** The result id of a previous response */
previousResultId: string;
}
interface SemanticTokens {
/** An optional result id */
resultId?: string;
/** The actual tokens */
data: number[];
}
interface SemanticTokensPartialResult {
data: number[];
}
interface SemanticTokensDelta {
/** An optional result id */
resultId?: string;
/** The semantic token edits to transform a previous result into a new result */
edits: SemanticTokensEdit[];
}
interface SemanticTokensEdit {
/** The start offset of the edit */
start: number;
/** The count of elements to remove */
deleteCount: number;
/** The elements to insert */
data?: number[];
}Usage Example:
// Access via connection.languages.semanticTokens
connection.languages.semanticTokens.on((params) => {
const document = documents.get(params.textDocument.uri);
if (!document) return null;
const builder = new SemanticTokensBuilder();
// Add tokens (line, character, length, tokenType, tokenModifiers)
builder.push(0, 0, 8, TokenTypes.keyword, TokenModifiers.declaration);
builder.push(0, 9, 4, TokenTypes.function, TokenModifiers.definition);
return builder.build();
});
// Refresh tokens when needed
connection.languages.semanticTokens.refresh();Helper class for building semantic tokens responses.
/**
* Helper class for building semantic tokens
*/
class SemanticTokensBuilder {
/** Create a new semantic tokens builder */
constructor();
/**
* Add a semantic token
* @param line Line number (0-based)
* @param char Character offset on line (0-based)
* @param length Length of the token
* @param tokenType Token type index
* @param tokenModifiers Token modifiers as bit flags
*/
push(line: number, char: number, length: number, tokenType: number, tokenModifiers?: number): void;
/** Build the final semantic tokens */
build(): SemanticTokens;
/** Build semantic tokens edits */
buildEdits(): SemanticTokensEdits;
}Provides call hierarchy navigation for functions and methods.
/**
* Call hierarchy feature for navigating function calls
*/
interface CallHierarchyFeatureShape {
callHierarchy: {
/** Register handler for call hierarchy prepare requests */
onPrepare(handler: ServerRequestHandler<CallHierarchyPrepareParams, CallHierarchyItem[] | null, void>): Disposable;
/** Register handler for incoming calls requests */
onIncomingCalls(handler: ServerRequestHandler<CallHierarchyIncomingCallsParams, CallHierarchyIncomingCall[] | null, void>): Disposable;
/** Register handler for outgoing calls requests */
onOutgoingCalls(handler: ServerRequestHandler<CallHierarchyOutgoingCallsParams, CallHierarchyOutgoingCall[] | null, void>): Disposable;
};
}
interface CallHierarchyPrepareParams extends TextDocumentPositionParams, WorkDoneProgressParams {
}
interface CallHierarchyIncomingCallsParams extends WorkDoneProgressParams, PartialResultParams {
item: CallHierarchyItem;
}
interface CallHierarchyOutgoingCallsParams extends WorkDoneProgressParams, PartialResultParams {
item: CallHierarchyItem;
}
interface CallHierarchyItem {
/** The name of this item */
name: string;
/** The kind of this item */
kind: SymbolKind;
/** Tags for this item */
tags?: SymbolTag[];
/** More detail for this item */
detail?: string;
/** The resource identifier of this item */
uri: DocumentUri;
/** The range enclosing this symbol */
range: Range;
/** The range that should be selected and revealed when this symbol is being picked */
selectionRange: Range;
/** A data entry field that is preserved during call hierarchy prepare and call hierarchy incoming/outgoing calls requests */
data?: any;
}
interface CallHierarchyIncomingCall {
/** The item that makes the call */
from: CallHierarchyItem;
/** The ranges at which the calls appear */
fromRanges: Range[];
}
interface CallHierarchyOutgoingCall {
/** The item that is called */
to: CallHierarchyItem;
/** The range at which this item is called */
fromRanges: Range[];
}Provides type hierarchy navigation for classes and interfaces.
/**
* Type hierarchy feature for navigating type relationships
*/
interface TypeHierarchyFeatureShape {
typeHierarchy: {
/** Register handler for type hierarchy prepare requests */
onPrepare(handler: ServerRequestHandler<TypeHierarchyPrepareParams, TypeHierarchyItem[] | null, void>): Disposable;
/** Register handler for supertypes requests */
onSupertypes(handler: ServerRequestHandler<TypeHierarchySupertypesParams, TypeHierarchyItem[] | null, void>): Disposable;
/** Register handler for subtypes requests */
onSubtypes(handler: ServerRequestHandler<TypeHierarchySubtypesParams, TypeHierarchyItem[] | null, void>): Disposable;
};
}
interface TypeHierarchyPrepareParams extends TextDocumentPositionParams, WorkDoneProgressParams {
}
interface TypeHierarchySupertypesParams extends WorkDoneProgressParams, PartialResultParams {
item: TypeHierarchyItem;
}
interface TypeHierarchySubtypesParams extends WorkDoneProgressParams, PartialResultParams {
item: TypeHierarchyItem;
}
interface TypeHierarchyItem {
/** The name of this item */
name: string;
/** The kind of this item */
kind: SymbolKind;
/** Tags for this item */
tags?: SymbolTag[];
/** More detail for this item */
detail?: string;
/** The resource identifier of this item */
uri: DocumentUri;
/** The range enclosing this symbol */
range: Range;
/** The range that should be selected and revealed when this symbol is being picked */
selectionRange: Range;
/** A data entry field that is preserved during type hierarchy prepare and type hierarchy super-/sub-types requests */
data?: any;
}Provides pull-based diagnostics for documents and workspace.
/**
* Diagnostics feature for pull-based diagnostic reporting
*/
interface DiagnosticFeatureShape {
diagnostics: {
/** Register handler for diagnostic requests */
on(handler: ServerRequestHandler<DocumentDiagnosticParams, DocumentDiagnosticReport, DocumentDiagnosticReportPartialResult, void>): Disposable;
/** Refresh diagnostics in the client */
refresh(): void;
};
}
interface DocumentDiagnosticParams extends WorkDoneProgressParams, PartialResultParams {
/** The text document */
textDocument: TextDocumentIdentifier;
/** The additional identifier provided during registration */
identifier?: string;
/** The result id of a previous response if provided */
previousResultId?: string;
}
type DocumentDiagnosticReport = RelatedFullDocumentDiagnosticReport | RelatedUnchangedDocumentDiagnosticReport;
interface RelatedFullDocumentDiagnosticReport extends FullDocumentDiagnosticReport {
/** Diagnostics of related documents */
relatedDocuments?: { [uri: DocumentUri]: FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport };
}
interface FullDocumentDiagnosticReport {
/** A full document diagnostic report */
kind: 'full';
/** An optional result id */
resultId?: string;
/** The actual items */
items: Diagnostic[];
}
interface UnchangedDocumentDiagnosticReport {
/** A document diagnostic report indicating no changes to the last result */
kind: 'unchanged';
/** A result id which will be sent on the next diagnostic request for the same document */
resultId: string;
}
interface Diagnostic {
/** The range at which the message applies */
range: Range;
/** The diagnostic's severity */
severity?: DiagnosticSeverity;
/** The diagnostic's code */
code?: number | string;
/** An optional property to describe the error code */
codeDescription?: CodeDescription;
/** A human-readable string describing the source of this diagnostic */
source?: string;
/** The diagnostic's message */
message: string;
/** Additional metadata about the diagnostic */
tags?: DiagnosticTag[];
/** An array of related diagnostic information */
relatedInformation?: DiagnosticRelatedInformation[];
/** A data entry field that is preserved during diagnostic resolution */
data?: any;
}
enum DiagnosticSeverity {
Error = 1,
Warning = 2,
Information = 3,
Hint = 4
}Provides inlay hints for parameter names, type annotations, and other inline information.
/**
* Inlay hint feature for inline code annotations
*/
interface InlayHintFeatureShape {
inlayHint: {
/** Register handler for inlay hint requests */
on(handler: ServerRequestHandler<InlayHintParams, InlayHint[] | null, void>): Disposable;
/** Register handler for inlay hint resolve requests */
onResolve(handler: ServerRequestHandler<InlayHint, InlayHint, void>): Disposable;
/** Refresh inlay hints in the client */
refresh(): void;
};
}
interface InlayHintParams extends WorkDoneProgressParams {
/** The text document */
textDocument: TextDocumentIdentifier;
/** The visible document range for which inlay hints should be computed */
range: Range;
}
interface InlayHint {
/** The position of this hint */
position: Position;
/** The label of this hint */
label: string | InlayHintLabelPart[];
/** The kind of this hint */
kind?: InlayHintKind;
/** Optional text edits that are performed when accepting this inlay hint */
textEdits?: TextEdit[];
/** The tooltip text when you hover over this item */
tooltip?: string | MarkupContent;
/** Render padding before the hint */
paddingLeft?: boolean;
/** Render padding after the hint */
paddingRight?: boolean;
/** A data entry field that is preserved during resolve */
data?: any;
}
interface InlayHintLabelPart {
/** The value of this label part */
value: string;
/** The tooltip text when you hover over this label part */
tooltip?: string | MarkupContent;
/** An optional source code location that represents this label part */
location?: Location;
/** An optional command for this label part */
command?: Command;
}
enum InlayHintKind {
Type = 1,
Parameter = 2
}Provides inline value information during debugging sessions.
/**
* Inline value feature for debugging support
*/
interface InlineValueFeatureShape {
inlineValue: {
/** Register handler for inline value requests */
on(handler: ServerRequestHandler<InlineValueParams, InlineValue[] | null, void>): Disposable;
/** Refresh inline values in the client */
refresh(): void;
};
}
interface InlineValueParams extends WorkDoneProgressParams {
/** The text document */
textDocument: TextDocumentIdentifier;
/** The document range for which inline values should be computed */
range: Range;
/** Additional information about the context in which inline values were requested */
context: InlineValueContext;
}
interface InlineValueContext {
/** The stack frame (as a DAP Id) where the execution has stopped */
frameId: number;
/** The document range where execution has stopped */
stoppedLocation: Range;
}
type InlineValue = InlineValueText | InlineValueVariableLookup | InlineValueEvaluatableExpression;
interface InlineValueText {
/** The document range for which the inline value applies */
range: Range;
/** The text of the inline value */
text: string;
}
interface InlineValueVariableLookup {
/** The document range for which the inline value applies */
range: Range;
/** If specified the name of the variable to look up */
variableName?: string;
/** How to perform the lookup */
caseSensitiveLookup: boolean;
}
interface InlineValueEvaluatableExpression {
/** The document range for which the inline value applies */
range: Range;
/** If specified the expression overrides the extracted expression */
expression?: string;
}Provides moniker information for cross-reference and navigation purposes.
/**
* Moniker feature for cross-reference support
*/
interface MonikerFeatureShape {
moniker: {
/** Register handler for moniker requests */
on(handler: ServerRequestHandler<MonikerParams, Moniker[] | null, void>): Disposable;
};
}
interface MonikerParams extends TextDocumentPositionParams, WorkDoneProgressParams, PartialResultParams {
}
interface Moniker {
/** The scheme of the moniker */
scheme: string;
/** The identifier of the moniker */
identifier: string;
/** The scope in which the moniker is unique */
unique: UniquenessLevel;
/** The moniker kind if known */
kind?: MonikerKind;
}
enum UniquenessLevel {
/** The moniker is only unique inside a document */
document = 'document',
/** The moniker is unique inside a project for which a dump got created */
project = 'project',
/** The moniker is unique inside the group to which a project belongs */
group = 'group',
/** The moniker is unique inside the moniker scheme */
scheme = 'scheme',
/** The moniker is globally unique */
global = 'global'
}
enum MonikerKind {
/** The moniker represent a symbol that is imported into a project */
import = 'import',
/** The moniker represents a symbol that is exported from a project */
export = 'export',
/** The moniker represents a symbol that is local to a project */
local = 'local'
}type ServerRequestHandler<P, R, PR, E> = (
params: P,
token: CancellationToken,
workDoneProgress: WorkDoneProgressReporter,
partialResultProgress: ResultProgressReporter<PR>
) => HandlerResult<R, E>;
type HandlerResult<R, E> = R | ResponseError<E> | Promise<R> | Promise<ResponseError<E>>;
interface WorkDoneProgressReporter {
begin(title: string, percentage?: number, message?: string, cancellable?: boolean): void;
report(percentage: number): void;
report(message: string): void;
report(percentage: number, message?: string): void;
done(): void;
}
interface ResultProgressReporter<T> {
report(data: T): void;
}
enum SymbolTag {
Deprecated = 1
}
interface ResponseError<D> {
code: number;
message: string;
data?: D;
}
interface Disposable {
dispose(): void;
}Install with Tessl CLI
npx tessl i tessl/npm-vscode-languageserver