/****************************************************************************** * Copyright 2022 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ import type { Range, SemanticTokens, SemanticTokensClientCapabilities, SemanticTokensDelta, SemanticTokensDeltaParams, SemanticTokensOptions, SemanticTokensParams, SemanticTokensRangeParams } from 'vscode-languageserver'; import { SemanticTokensBuilder as BaseSemanticTokensBuilder, SemanticTokenTypes } from 'vscode-languageserver'; import { CancellationToken } from '../utils/cancellation.js'; import type { AstNode, CstNode, Properties } from '../syntax-tree.js'; import type { MaybePromise } from '../utils/promise-utils.js'; import type { LangiumDocument } from '../workspace/documents.js'; import type { LangiumServices } from './lsp-services.js'; export declare const AllSemanticTokenTypes: Record; export declare const AllSemanticTokenModifiers: Record; export declare const DefaultSemanticTokenOptions: SemanticTokensOptions; export interface SemanticTokenProvider { semanticHighlight(document: LangiumDocument, params: SemanticTokensParams, cancelToken?: CancellationToken): MaybePromise; semanticHighlightRange(document: LangiumDocument, params: SemanticTokensRangeParams, cancelToken?: CancellationToken): MaybePromise; semanticHighlightDelta(document: LangiumDocument, params: SemanticTokensDeltaParams, cancelToken?: CancellationToken): MaybePromise; readonly tokenTypes: Record; readonly tokenModifiers: Record; readonly semanticTokensOptions: SemanticTokensOptions; } export declare function mergeSemanticTokenProviderOptions(options: Array): SemanticTokensOptions; export interface SemanticToken { line: number; char: number; length: number; tokenType: number; tokenModifiers: number; } export type SemanticTokenAcceptorOptions = ({ line: number; char: number; length: number; } | { node: N; property: Properties; index?: number; } | { node: N; keyword: string; index?: number; } | { cst: CstNode; } | { range: Range; }) & { type: string; modifier?: string | string[]; }; export interface SemanticTokenPropertyOptions { node: T; property: Properties; index?: number; type: string; modifier?: string | string[]; } export interface SemanticTokenKeywordOptions { node: AstNode; keyword: string; index?: number; type: string; modifier?: string | string[]; } export interface SemanticTokenNodeOptions { node: CstNode; type: string; modifier?: string | string[]; } export interface SemanticTokenRangeOptions { range: Range; type: string; modifier?: string | string[]; } export declare class SemanticTokensBuilder extends BaseSemanticTokensBuilder { private _tokens; push(line: number, char: number, length: number, tokenType: number, tokenModifiers: number): void; build(): SemanticTokens; buildEdits(): SemanticTokens | SemanticTokensDelta; /** * Flushes the cached delta token values */ flush(): void; private applyTokens; private compareTokens; } export type SemanticTokenAcceptor = (options: SemanticTokenAcceptorOptions) => void; /** * A basic super class for providing semantic token data. * Users of Langium should extend this class to create their own `SemanticTokenProvider`. * * The entry method for generating semantic tokens based on an `AstNode` is the `highlightElement` method. */ export declare abstract class AbstractSemanticTokenProvider implements SemanticTokenProvider { /** * Store a token builder for each open document. */ protected tokensBuilders: Map; protected currentDocument?: LangiumDocument; protected currentTokensBuilder?: SemanticTokensBuilder; protected currentRange?: Range; protected clientCapabilities?: SemanticTokensClientCapabilities; constructor(services: LangiumServices); initialize(clientCapabilities?: SemanticTokensClientCapabilities): void; get tokenTypes(): Record; get tokenModifiers(): Record; get semanticTokensOptions(): SemanticTokensOptions; semanticHighlight(document: LangiumDocument, _params: SemanticTokensParams, cancelToken?: CancellationToken): Promise; semanticHighlightRange(document: LangiumDocument, params: SemanticTokensRangeParams, cancelToken?: CancellationToken): Promise; semanticHighlightDelta(document: LangiumDocument, params: SemanticTokensDeltaParams, cancelToken?: CancellationToken): Promise; protected createAcceptor(): SemanticTokenAcceptor; protected getDocumentTokensBuilder(document: LangiumDocument): SemanticTokensBuilder; protected computeHighlighting(document: LangiumDocument, acceptor: SemanticTokenAcceptor, cancelToken: CancellationToken): Promise; /** * @return `'prune'` to skip the children of this element, nothing otherwise. */ protected abstract highlightElement(node: AstNode, acceptor: SemanticTokenAcceptor): void | undefined | 'prune'; protected highlightToken(options: SemanticTokenRangeOptions): void; protected highlightProperty(options: SemanticTokenPropertyOptions): void; protected highlightKeyword(options: SemanticTokenKeywordOptions): void; protected highlightNode(options: SemanticTokenNodeOptions): void; } export declare namespace SemanticTokensDecoder { interface DecodedSemanticToken { offset: number; tokenType: SemanticTokenTypes; tokenModifiers: number; text: string; } function decode(tokens: SemanticTokens, tokenTypes: Record, document: LangiumDocument): DecodedSemanticToken[]; } //# sourceMappingURL=semantic-token-provider.d.ts.map