/****************************************************************************** * Copyright 2021 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 { CompletionItem, CompletionList, Diagnostic, DocumentSymbol, FoldingRange, FormattingOptions, Range, ReferenceParams, SemanticTokenTypes, TextDocumentIdentifier, TextDocumentPositionParams, WorkspaceSymbol } from 'vscode-languageserver-protocol'; import { DiagnosticSeverity } from 'vscode-languageserver-types'; import type { LangiumServices, LangiumSharedLSPServices } from '../lsp/lsp-services.js'; import { SemanticTokensDecoder } from '../lsp/semantic-token-provider.js'; import type { ParserOptions } from '../parser/langium-parser.js'; import type { LangiumCoreServices, LangiumSharedCoreServices } from '../services.js'; import type { AstNode, Properties } from '../syntax-tree.js'; import type { AsyncDisposable } from '../utils/disposable.js'; import { Disposable } from '../utils/disposable.js'; import type { BuildOptions } from '../workspace/document-builder.js'; import { TextDocument, type LangiumDocument } from '../workspace/documents.js'; export interface ParseHelperOptions extends BuildOptions { /** * Specifies the URI of the generated document. Will use a counter variable if not specified. */ documentUri?: string; /** * Options passed to the LangiumParser. */ parserOptions?: ParserOptions; } export declare function parseHelper(services: LangiumCoreServices): (input: string, options?: ParseHelperOptions) => Promise>; export type ExpectFunction = (actual: unknown, expected: unknown, message?: string) => void; /** * Overrides the assertion function used by tests. Uses `assert.deepStrictEqual` by default * * @deprecated Since 1.2.0. Do not override the assertion functionality. */ export declare function expectFunction(functions: ExpectFunction): void; export interface ExpectedBase { /** * Document content. * Use `<|>` and `<|...|>` to mark special items that are relevant to the test case. */ text: string; /** * Parse options used to parse the {@link text} property. */ parseOptions?: ParseHelperOptions; /** * String to mark indices for test cases. `<|>` by default. */ indexMarker?: string; /** * String to mark start indices for test cases. `<|` by default. */ rangeStartMarker?: string; /** * String to mark end indices for test cases. `|>` by default. */ rangeEndMarker?: string; /** * Whether to dispose the created documents right after performing the check. * * Defaults to `false`. */ disposeAfterCheck?: boolean; } export interface ExpectedHighlight extends ExpectedBase { index?: number; rangeIndex?: number | number[]; } /** * Testing utility function for the `textDocument/documentHighlight` LSP request * * @returns A function that performs the assertion */ export declare function expectHighlight(services: LangiumServices): (input: ExpectedHighlight) => Promise; export interface ExpectedSymbolsList extends ExpectedBase { expectedSymbols: Array; symbolToString?: (item: DocumentSymbol) => string; } export interface ExpectedSymbolsCallback extends ExpectedBase { assert: (symbols: DocumentSymbol[]) => void; } export type ExpectedSymbols = ExpectedSymbolsList | ExpectedSymbolsCallback; export declare function expectSymbols(services: LangiumServices): (input: ExpectedSymbols) => Promise; export interface ExpectedWorkspaceSymbolsBase { query?: string; } export interface ExpectedWorkspaceSymbolsList extends ExpectedWorkspaceSymbolsBase { expectedSymbols: Array; symbolToString?: (item: WorkspaceSymbol) => string; } export interface ExpectedWorkspaceSymbolsCallback extends ExpectedWorkspaceSymbolsBase { assert: (symbols: WorkspaceSymbol[]) => void; } export type ExpectedWorkspaceSymbols = ExpectedWorkspaceSymbolsList | ExpectedWorkspaceSymbolsCallback; export declare function expectWorkspaceSymbols(services: LangiumSharedLSPServices): (input: ExpectedWorkspaceSymbols) => Promise; export interface ExpectedFoldings extends ExpectedBase { assert?: (foldings: FoldingRange[], expected: Array<[number, number]>) => void; } export declare function expectFoldings(services: LangiumServices): (input: ExpectedFoldings) => Promise; export declare function textDocumentParams(document: LangiumDocument): { textDocument: TextDocumentIdentifier; }; export interface ExpectedCompletionItems extends ExpectedBase { index: number; expectedItems: Array; itemToString?: (item: CompletionItem) => string; } export interface ExpectedCompletionCallback extends ExpectedBase { index: number; assert: (completions: CompletionList) => void; } export type ExpectedCompletion = ExpectedCompletionItems | ExpectedCompletionCallback; export declare function expectCompletion(services: LangiumServices): (expectedCompletion: ExpectedCompletion) => Promise; export interface ExpectedGoToDefinition extends ExpectedBase { index: number; rangeIndex: number | number[]; } export declare function expectGoToDefinition(services: LangiumServices): (expectedGoToDefinition: ExpectedGoToDefinition) => Promise; export interface ExpectedFindReferences extends ExpectedBase { includeDeclaration: boolean; } export declare function expectFindReferences(services: LangiumServices): (expectedFindReferences: ExpectedFindReferences) => Promise; export declare function referenceParams(document: LangiumDocument, offset: number, includeDeclaration: boolean): ReferenceParams; export interface ExpectedHover extends ExpectedBase { index: number; hover?: string | RegExp; } export declare function expectHover(services: LangiumServices): (expectedHover: ExpectedHover) => Promise; export interface ExpectFormatting { /** * Document content before formatting. */ before: string; /** * Expected document content after formatting. * The test case will compare this to the actual formatted document. */ after: string; /** * Parse options used to parse the {@link text} property. */ parseOptions?: ParseHelperOptions; /** * If given, only the specified range will be affected by the formatter */ range?: Range; /** * Options used by the formatter. Default: * ```ts * { * insertSpaces: true, * tabSize: 4 * } * ``` */ options?: FormattingOptions; /** * Whether to dispose the created documents right after performing the check. * * Defaults to `false`. */ disposeAfterCheck?: boolean; } export declare function expectFormatting(services: LangiumServices): (expectedFormatting: ExpectFormatting) => Promise; export declare function textDocumentPositionParams(document: LangiumDocument, offset: number): TextDocumentPositionParams; export declare function parseDocument(services: LangiumCoreServices, input: string, options?: ParseHelperOptions): Promise>; export declare function replaceIndices(base: ExpectedBase): { output: string; indices: number[]; ranges: Array<[number, number]>; }; export interface ValidationResult extends AsyncDisposable { diagnostics: Diagnostic[]; document: LangiumDocument; } export type ValidationHelperOptions = ParseHelperOptions & { failOnParsingErrors?: boolean; }; export declare function validationHelper(services: LangiumCoreServices): (input: string, options?: ValidationHelperOptions) => Promise>; export type ExpectDiagnosticOptionsWithoutContent = ExpectDiagnosticCode & ExpectDiagnosticData & (ExpectDiagnosticAstOptions | ExpectDiagnosticRangeOptions | ExpectDiagnosticOffsetOptions); export type ExpectDiagnosticOptions = ExpectDiagnosticContent & ExpectDiagnosticOptionsWithoutContent; export interface ExpectDiagnosticContent { message?: string | RegExp; severity?: DiagnosticSeverity; } export interface ExpectDiagnosticCode { code?: string; } export interface ExpectDiagnosticData { data?: unknown; } export interface ExpectDiagnosticAstOptions { node?: T; property?: Properties | { name: Properties; index?: number; }; } export interface ExpectDiagnosticRangeOptions { range: Range; } export interface ExpectDiagnosticOffsetOptions { offset: number; length: number; } export type Predicate = (arg: T) => boolean; export declare function isDiagnosticDataEqual(lhs: unknown, rhs: unknown): boolean; export declare function isRangeEqual(lhs: Range, rhs: Range): boolean; export declare function rangeToString(range: Range): string; export declare function filterByOptions(validationResult: ValidationResult, options: ExpectDiagnosticOptions): Diagnostic[]; export declare function expectNoIssues(validationResult: ValidationResult, filterOptions?: ExpectDiagnosticOptions): void; export declare function expectIssue(validationResult: ValidationResult, filterOptions?: ExpectDiagnosticOptions): void; export declare function expectError(validationResult: ValidationResult, message: string | RegExp, filterOptions: ExpectDiagnosticOptionsWithoutContent): void; export declare function expectWarning(validationResult: ValidationResult, message: string | RegExp, filterOptions: ExpectDiagnosticOptionsWithoutContent): void; export declare function printDiagnostics(diagnostics: Diagnostic[] | undefined): string; /** * Add the given document to the `TextDocuments` service, simulating it being opened in an editor. * * @deprecated Since 3.2.0. Use `set`/`delete` from `TextDocuments` instead. */ export declare function setTextDocument(services: LangiumServices | LangiumSharedLSPServices, document: TextDocument): Disposable; export declare function clearDocuments(services: LangiumCoreServices | LangiumSharedCoreServices, documents?: LangiumDocument[]): Promise; export interface DecodedSemanticTokensWithRanges { tokens: SemanticTokensDecoder.DecodedSemanticToken[]; ranges: Array<[number, number]>; } export declare function highlightHelper(services: LangiumServices): (input: string, options?: ParseHelperOptions) => Promise; export interface DecodedTokenOptions { rangeIndex?: number; tokenType: SemanticTokenTypes; } export declare function expectSemanticToken(tokensWithRanges: DecodedSemanticTokensWithRanges, options: DecodedTokenOptions): void; //# sourceMappingURL=langium-test.d.ts.map