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 23, 2024
1 parent 6e35629 commit c6132de
Show file tree
Hide file tree
Showing 35 changed files with 61 additions and 37 deletions.
3 changes: 2 additions & 1 deletion packages/langium/src/lsp/call-hierarchy-provider.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion packages/langium/src/workspace/ast-descriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { LangiumCoreServices } from '../services.js';
import type { AstNode, AstNodeDescription, ReferenceInfo } from '../syntax-tree.js';
import type { AstNodeLocator } from './ast-node-locator.js';
import type { DocumentSegment, LangiumDocument } from './documents.js';
import { CancellationToken } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import { isLinkingError } from '../syntax-tree.js';
import { getDocument, streamAst, streamReferences } from '../utils/ast-utils.js';
import { toDocumentSegment } from '../utils/cst-utils.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/workspace/document-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import { CancellationToken, Disposable } from 'vscode-jsonrpc';
import { Disposable } from 'vscode-jsonrpc';
import { CancellationToken } from '../utils/cancellation.js';
import type { ServiceRegistry } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';
import type { AstNode } from '../syntax-tree.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/workspace/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// the overhead is very small, just a few kilobytes
export * from 'vscode-languageserver-textdocument';

import { CancellationToken } from 'vscode-jsonrpc';
import type { Diagnostic, Range } from 'vscode-languageserver-types';
import type { ParseResult } from '../parser/langium-parser.js';
import type { ServiceRegistry } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';
import type { AstNode, AstNodeDescription, Mutable, Reference } from '../syntax-tree.js';
import type { MultiMap } from '../utils/collections.js';
import type { Stream } from '../utils/stream.js';
import { CancellationToken } from '../utils/cancellation.js';
import { stream } from '../utils/stream.js';
import { URI } from '../utils/uri-utils.js';
import { TextDocument } from './documents.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/workspace/index-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import { CancellationToken } from 'vscode-languageserver';
import type { ServiceRegistry } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';
import type { AstNode, AstNodeDescription, AstReflection } from '../syntax-tree.js';
import { getDocument } from '../utils/ast-utils.js';
import { ContextCache } from '../utils/caching.js';
import { CancellationToken } from '../utils/cancellation.js';
import type { Stream } from '../utils/stream.js';
import { stream } from '../utils/stream.js';
import type { URI } from '../utils/uri-utils.js';
Expand Down
Loading

0 comments on commit c6132de

Please sign in to comment.