Skip to content

Commit

Permalink
introduced 'utils/cancellation.ts' doing only "export * from 'vscode-…
Browse files Browse the repository at this point in the history
…jsonrpc/lib/common/cancellation.js';"; updated related imports

aims at providing cancellation related types and symbols with smallest possible overhead while avoiding code clones
  • Loading branch information
sailingKieler committed Jan 24, 2024
1 parent 6e35629 commit 15bc2ec
Show file tree
Hide file tree
Showing 36 changed files with 65 additions and 42 deletions.
Expand Up @@ -8,8 +8,7 @@ import type { AstNode, AstNodeDescription, LangiumDocument, PrecomputedScopes }
import type { DomainModelServices } from './domain-model-module.js';
import type { QualifiedNameProvider } from './domain-model-naming.js';
import type { Domainmodel, PackageDeclaration } from './generated/ast.js';
import { AstUtils, DefaultScopeComputation, interruptAndCheck, MultiMap } from 'langium';
import { CancellationToken } from 'vscode-jsonrpc';
import { AstUtils, Cancellation, DefaultScopeComputation, interruptAndCheck, MultiMap } from 'langium';
import { isType, isPackageDeclaration } from './generated/ast.js';

export class DomainModelScopeComputation extends DefaultScopeComputation {
Expand All @@ -24,7 +23,7 @@ export class DomainModelScopeComputation extends DefaultScopeComputation {
/**
* Exports only types (`DataType or `Entity`) with their qualified names.
*/
override async computeExports(document: LangiumDocument, cancelToken = CancellationToken.None): Promise<AstNodeDescription[]> {
override async computeExports(document: LangiumDocument, cancelToken = Cancellation.CancellationToken.None): Promise<AstNodeDescription[]> {
const descr: AstNodeDescription[] = [];
for (const modelNode of AstUtils.streamAllContents(document.parseResult.value)) {
await interruptAndCheck(cancelToken);
Expand All @@ -41,14 +40,14 @@ export class DomainModelScopeComputation extends DefaultScopeComputation {
return descr;
}

override async computeLocalScopes(document: LangiumDocument, cancelToken = CancellationToken.None): Promise<PrecomputedScopes> {
override async computeLocalScopes(document: LangiumDocument, cancelToken = Cancellation.CancellationToken.None): Promise<PrecomputedScopes> {
const model = document.parseResult.value as Domainmodel;
const scopes = new MultiMap<AstNode, AstNodeDescription>();
await this.processContainer(model, scopes, document, cancelToken);
return scopes;
}

protected async processContainer(container: Domainmodel | PackageDeclaration, scopes: PrecomputedScopes, document: LangiumDocument, cancelToken: CancellationToken): Promise<AstNodeDescription[]> {
protected async processContainer(container: Domainmodel | PackageDeclaration, scopes: PrecomputedScopes, document: LangiumDocument, cancelToken: Cancellation.CancellationToken): Promise<AstNodeDescription[]> {
const localDescriptions: AstNodeDescription[] = [];
for (const element of container.elements) {
await interruptAndCheck(cancelToken);
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/call-hierarchy-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams, CancellationToken } from 'vscode-languageserver';
import type { CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams, } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { GrammarConfig } from '../languages/grammar-config.js';
import type { NameProvider } from '../references/name-provider.js';
import type { References } from '../references/references.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/code-action.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, CodeAction, CodeActionParams, Command } from 'vscode-languageserver';
import type { CodeAction, CodeActionParams, Command } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { LangiumDocument } from '../workspace/documents.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/code-lens-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, CodeLens, CodeLensParams } from 'vscode-languageserver';
import type { CodeLens, CodeLensParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { LangiumDocument } from '../workspace/documents.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/completion/completion-provider.ts
Expand Up @@ -4,12 +4,13 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, CompletionItem, CompletionParams } from 'vscode-languageserver';
import type { CompletionItem, CompletionParams } from 'vscode-languageserver';
import type { LangiumCompletionParser } from '../../parser/langium-parser.js';
import type { NameProvider } from '../../references/name-provider.js';
import type { ScopeProvider } from '../../references/scope-provider.js';
import type { LangiumServices } from '../lsp-services.js';
import type { AstNode, AstNodeDescription, AstReflection, CstNode, ReferenceInfo } from '../../syntax-tree.js';
import type { CancellationToken } from '../../utils/cancellation.js';
import type { MaybePromise } from '../../utils/promise-utils.js';
import type { LangiumDocument, TextDocument, TextEdit } from '../../workspace/documents.js';
import type { NextFeature } from './follow-element-computation.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/declaration-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, DeclarationParams, LocationLink } from 'vscode-languageserver';
import type { DeclarationParams, LocationLink } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { LangiumDocument } from '../workspace/documents.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/definition-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, DefinitionParams } from 'vscode-languageserver';
import type { DefinitionParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { GrammarConfig } from '../languages/grammar-config.js';
import type { NameProvider } from '../references/name-provider.js';
import type { References } from '../references/references.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/document-highlight-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, DocumentHighlightParams } from 'vscode-languageserver';
import type { DocumentHighlightParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { GrammarConfig } from '../languages/grammar-config.js';
import type { NameProvider } from '../references/name-provider.js';
import type { FindReferencesOptions, References } from '../references/references.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/document-link-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, DocumentLink, DocumentLinkParams } from 'vscode-languageserver';
import type { DocumentLink, DocumentLinkParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { LangiumDocument } from '../workspace/documents.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/document-symbol-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, DocumentSymbol, DocumentSymbolParams} from 'vscode-languageserver';
import type { DocumentSymbol, DocumentSymbolParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { NameProvider } from '../references/name-provider.js';
import type { LangiumServices } from './lsp-services.js';
import type { AstNode } from '../syntax-tree.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/lsp/execute-command-handler.ts
Expand Up @@ -7,7 +7,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import type { MaybePromise } from '../utils/promise-utils.js';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';

export interface ExecuteCommandHandler {
get commands(): string[]
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/folding-range-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, FoldingRangeParams } from 'vscode-languageserver';
import type { FoldingRangeParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { LangiumServices } from './lsp-services.js';
import type { AstNode, CstNode } from '../syntax-tree.js';
import type { MaybePromise } from '../utils/promise-utils.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/formatter.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, DocumentFormattingParams, DocumentOnTypeFormattingOptions, DocumentOnTypeFormattingParams, DocumentRangeFormattingParams, FormattingOptions, Range, TextEdit } from 'vscode-languageserver-protocol';
import type { DocumentFormattingParams, DocumentOnTypeFormattingOptions, DocumentOnTypeFormattingParams, DocumentRangeFormattingParams, FormattingOptions, Range, TextEdit } from 'vscode-languageserver-protocol';
import type { CancellationToken } from '../utils/cancellation.js';
import type { AstNode, CstNode, Properties } from '../syntax-tree.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { Stream } from '../utils/stream.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/hover-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, Hover, HoverParams } from 'vscode-languageserver';
import type { Hover, HoverParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { GrammarConfig } from '../languages/grammar-config.js';
import type { References } from '../references/references.js';
import type { LangiumServices } from './lsp-services.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/lsp/implementation-provider.ts
Expand Up @@ -11,7 +11,7 @@ import type { LangiumServices } from './lsp-services.js';
import type { AstNode } from '../syntax-tree.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { LangiumDocument } from '../workspace/documents.js';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import { findDeclarationNodeAtOffset } from '../utils/cst-utils.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/lsp/inlay-hint-provider.ts
Expand Up @@ -6,7 +6,7 @@

import type { InlayHint, InlayHintParams } from 'vscode-languageserver';
import type { AstNode } from '../syntax-tree.js';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { LangiumDocument } from '../workspace/documents.js';
import { streamAst } from '../utils/ast-utils.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/references-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, ReferenceParams } from 'vscode-languageserver';
import type { ReferenceParams } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { NameProvider } from '../references/name-provider.js';
import type { References } from '../references/references.js';
import type { LeafCstNode } from '../syntax-tree.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/rename-provider.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, Position, Range, RenameParams, TextDocumentPositionParams, WorkspaceEdit } from 'vscode-languageserver-protocol';
import type { Position, Range, RenameParams, TextDocumentPositionParams, WorkspaceEdit } from 'vscode-languageserver-protocol';
import type { CancellationToken } from '../utils/cancellation.js';
import type { GrammarConfig } from '../languages/grammar-config.js';
import type { NameProvider } from '../references/name-provider.js';
import type { References } from '../references/references.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/semantic-token-provider.ts
Expand Up @@ -7,7 +7,8 @@
/* eslint-disable no-bitwise */

import type { Range, SemanticTokens, SemanticTokensClientCapabilities, SemanticTokensDelta, SemanticTokensDeltaParams, SemanticTokensOptions, SemanticTokensParams, SemanticTokensRangeParams } from 'vscode-languageserver';
import { SemanticTokensBuilder as BaseSemanticTokensBuilder, CancellationToken, SemanticTokenModifiers, SemanticTokenTypes } from 'vscode-languageserver';
import { SemanticTokensBuilder as BaseSemanticTokensBuilder, SemanticTokenModifiers, SemanticTokenTypes } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import type { AstNode, CstNode, Properties } from '../syntax-tree.js';
import { streamAst } from '../utils/ast-utils.js';
import { inRange } from '../utils/cst-utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/lsp/signature-help-provider.ts
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import type { SignatureHelp, SignatureHelpOptions, SignatureHelpParams } from 'vscode-languageserver';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import type { AstNode } from '../syntax-tree.js';
import { findLeafNodeAtOffset } from '../utils/cst-utils.js';
import type { MaybePromise } from '../utils/promise-utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/lsp/type-provider.ts
Expand Up @@ -10,7 +10,7 @@ import type { LangiumServices } from './lsp-services.js';
import type { AstNode } from '../syntax-tree.js';
import type { MaybePromise } from '../utils/promise-utils.js';
import type { LangiumDocument } from '../workspace/documents.js';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import { findDeclarationNodeAtOffset } from '../utils/cst-utils.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/lsp/workspace-symbol-provider.ts
Expand Up @@ -11,7 +11,7 @@ import type { MaybePromise} from '../utils/promise-utils.js';
import type { AstNodeDescription } from '../syntax-tree.js';
import type { NodeKindProvider } from './node-kind-provider.js';
import type { FuzzyMatcher } from './fuzzy-matcher.js';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import { interruptAndCheck } from '../utils/promise-utils.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/parser/async-parser.ts
Expand Up @@ -4,7 +4,7 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { LangiumCoreServices } from '../services.js';
import type { AstNode } from '../syntax-tree.js';
import type { LangiumParser, ParseResult } from './langium-parser.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/references/linker.ts
Expand Up @@ -9,7 +9,7 @@ import type { AstNode, AstNodeDescription, AstReflection, CstNode, LinkingError,
import type { AstNodeLocator } from '../workspace/ast-node-locator.js';
import type { LangiumDocument, LangiumDocuments } from '../workspace/documents.js';
import type { ScopeProvider } from './scope-provider.js';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import { isAstNode, isAstNodeDescription, isLinkingError } from '../syntax-tree.js';
import { getDocument, streamAst, streamReferences } from '../utils/ast-utils.js';
import { interruptAndCheck } from '../utils/promise-utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/references/scope-computation.ts
Expand Up @@ -9,7 +9,7 @@ import type { AstNode, AstNodeDescription } from '../syntax-tree.js';
import type { AstNodeDescriptionProvider } from '../workspace/ast-descriptions.js';
import type { LangiumDocument, PrecomputedScopes } from '../workspace/documents.js';
import type { NameProvider } from './name-provider.js';
import { CancellationToken } from 'vscode-jsonrpc';
import { CancellationToken } from '../utils/cancellation.js';
import { streamAllContents, streamContents } from '../utils/ast-utils.js';
import { MultiMap } from '../utils/collections.js';
import { interruptAndCheck } from '../utils/promise-utils.js';
Expand Down
7 changes: 7 additions & 0 deletions packages/langium/src/utils/cancellation.ts
@@ -0,0 +1,7 @@
/******************************************************************************
* Copyright 2024 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.
******************************************************************************/

export * from 'vscode-jsonrpc/lib/common/cancellation.js';
3 changes: 2 additions & 1 deletion packages/langium/src/utils/index.ts
Expand Up @@ -14,7 +14,8 @@ export * from './stream.js';
export * from './uri-utils.js';

import * as AstUtils from './ast-utils.js';
import * as Cancellation from './cancellation.js';
import * as CstUtils from './cst-utils.js';
import * as GrammarUtils from './grammar-utils.js';
import * as RegExpUtils from './regexp-utils.js';
export { AstUtils, CstUtils, GrammarUtils, RegExpUtils };
export { AstUtils, Cancellation, CstUtils, GrammarUtils, RegExpUtils };
3 changes: 1 addition & 2 deletions packages/langium/src/utils/promise-utils.ts
Expand Up @@ -4,8 +4,7 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { AbstractCancellationTokenSource } from 'vscode-jsonrpc';
import { CancellationToken, CancellationTokenSource } from 'vscode-jsonrpc';
import { CancellationToken, CancellationTokenSource, type AbstractCancellationTokenSource } from '../utils/cancellation.js';

export type MaybePromise<T> = T | Promise<T>

Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/validation/document-validator.ts
Expand Up @@ -12,7 +12,8 @@ import type { LangiumCoreServices } from '../services.js';
import type { AstNode, CstNode } from '../syntax-tree.js';
import type { LangiumDocument } from '../workspace/documents.js';
import type { DiagnosticData, DiagnosticInfo, ValidationAcceptor, ValidationCategory, ValidationRegistry } from './validation-registry.js';
import { CancellationToken, DiagnosticSeverity, Position, Range } from 'vscode-languageserver';
import { DiagnosticSeverity, Position, Range } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import { findNodeForKeyword, findNodeForProperty } from '../utils/grammar-utils.js';
import { streamAst } from '../utils/ast-utils.js';
import { tokenToRange } from '../utils/cst-utils.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/validation/validation-registry.ts
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CancellationToken, CodeDescription, DiagnosticRelatedInformation, DiagnosticTag, integer, Range } from 'vscode-languageserver';
import type { CodeDescription, DiagnosticRelatedInformation, DiagnosticTag, integer, Range } from 'vscode-languageserver';
import type { CancellationToken } from '../utils/cancellation.js';
import type { LangiumCoreServices } from '../services.js';
import type { AstNode, AstReflection, Properties } from '../syntax-tree.js';
import type { MaybePromise } from '../utils/promise-utils.js';
Expand Down

0 comments on commit 15bc2ec

Please sign in to comment.