Skip to content

Commit 48e67d6

Browse files
authored
Alignment of default classes to interface definitions (#1604)
1 parent 6690076 commit 48e67d6

15 files changed

+111
-28
lines changed

packages/langium/src/lsp/completion/completion-provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ export interface CompletionProvider {
107107
/**
108108
* Handle a completion request.
109109
*
110+
* @param document - the document for which the completion request was triggered
111+
* @param params - the completion parameters
112+
* @param cancelToken - a token that can be used to cancel the request
113+
*
110114
* @throws `OperationCancelled` if cancellation is detected during execution
111115
* @throws `ResponseError` if an error is detected that should be sent as response to the client
112116
*/
@@ -131,6 +135,7 @@ export class DefaultCompletionProvider implements CompletionProvider {
131135
protected readonly fuzzyMatcher: FuzzyMatcher;
132136
protected readonly grammarConfig: GrammarConfig;
133137
protected readonly astReflection: AstReflection;
138+
readonly completionOptions?: CompletionProviderOptions;
134139

135140
constructor(services: LangiumServices) {
136141
this.scopeProvider = services.references.ScopeProvider;
@@ -145,7 +150,7 @@ export class DefaultCompletionProvider implements CompletionProvider {
145150
this.documentationProvider = services.documentation.DocumentationProvider;
146151
}
147152

148-
async getCompletion(document: LangiumDocument, params: CompletionParams): Promise<CompletionList | undefined> {
153+
async getCompletion(document: LangiumDocument, params: CompletionParams, _cancelToken?: CancellationToken): Promise<CompletionList | undefined> {
149154
const items: CompletionItem[] = [];
150155
const contexts = this.buildContexts(document, params.position);
151156

packages/langium/src/lsp/definition-provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export interface DefinitionProvider {
2424
/**
2525
* Handle a go to definition request.
2626
*
27+
* @param document The document in which the request was triggered.
28+
* @param params The parameters of the request.
29+
* @param cancelToken A cancellation token that can be used to cancel the request.
30+
* @returns A list of location links to the definition(s) of the symbol at the given position.
31+
*
2732
* @throws `OperationCancelled` if cancellation is detected during execution
2833
* @throws `ResponseError` if an error is detected that should be sent as response to the client
2934
*/
@@ -48,7 +53,7 @@ export class DefaultDefinitionProvider implements DefinitionProvider {
4853
this.grammarConfig = services.parser.GrammarConfig;
4954
}
5055

51-
getDefinition(document: LangiumDocument, params: DefinitionParams): MaybePromise<LocationLink[] | undefined> {
56+
getDefinition(document: LangiumDocument, params: DefinitionParams, _cancelToken?: CancellationToken): MaybePromise<LocationLink[] | undefined> {
5257
const rootNode = document.parseResult.value;
5358
if (rootNode.$cstNode) {
5459
const cst = rootNode.$cstNode;

packages/langium/src/lsp/document-highlight-provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export interface DocumentHighlightProvider {
2525
/**
2626
* Handle a document highlight request.
2727
*
28+
* @param document The document in which the request was received.
29+
* @param params The parameters of the document highlight request.
30+
* @param cancelToken A cancellation token that can be used to cancel the request.
31+
* @returns The document highlights or `undefined` if no highlights are available.
2832
* @throws `OperationCancelled` if cancellation is detected during execution
2933
* @throws `ResponseError` if an error is detected that should be sent as response to the client
3034
*/
@@ -42,7 +46,7 @@ export class DefaultDocumentHighlightProvider implements DocumentHighlightProvid
4246
this.grammarConfig = services.parser.GrammarConfig;
4347
}
4448

45-
getDocumentHighlight(document: LangiumDocument, params: DocumentHighlightParams): MaybePromise<DocumentHighlight[] | undefined> {
49+
getDocumentHighlight(document: LangiumDocument, params: DocumentHighlightParams, _cancelToken?: CancellationToken): MaybePromise<DocumentHighlight[] | undefined> {
4650
const rootNode = document.parseResult.value.$cstNode;
4751
if (!rootNode) {
4852
return undefined;

packages/langium/src/lsp/document-symbol-provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export interface DocumentSymbolProvider {
2121
/**
2222
* Handle a document symbols request.
2323
*
24+
* @param document The document in the workspace.
25+
* @param params The parameters of the request.
26+
* @param cancelToken A cancellation token that migh be used to cancel the request.
27+
* @returns The symbols for the given document.
28+
*
2429
* @throws `OperationCancelled` if cancellation is detected during execution
2530
* @throws `ResponseError` if an error is detected that should be sent as response to the client
2631
*/
@@ -37,7 +42,7 @@ export class DefaultDocumentSymbolProvider implements DocumentSymbolProvider {
3742
this.nodeKindProvider = services.shared.lsp.NodeKindProvider;
3843
}
3944

40-
getSymbols(document: LangiumDocument): MaybePromise<DocumentSymbol[]> {
45+
getSymbols(document: LangiumDocument, _params: DocumentSymbolParams, _cancelToken?: CancellationToken): MaybePromise<DocumentSymbol[]> {
4146
return this.getSymbol(document, document.parseResult.value);
4247
}
4348

packages/langium/src/lsp/document-update-handler.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,46 @@ import type { MaybePromise } from '../utils/promise-utils.js';
2121
*/
2222
export interface DocumentUpdateHandler {
2323

24+
/**
25+
* A document open event was triggered by the `TextDocuments` service.
26+
* @param event The document change event.
27+
*/
2428
didOpenDocument?(event: TextDocumentChangeEvent<TextDocument>): void;
2529

2630
/**
2731
* A content change event was triggered by the `TextDocuments` service.
32+
* @param event The document change event.
2833
*/
2934
didChangeContent?(event: TextDocumentChangeEvent<TextDocument>): void;
3035

36+
/**
37+
* A document save event (initiated) was triggered by the `TextDocuments` service.
38+
* @param event The document change event.
39+
*/
3140
willSaveDocument?(event: TextDocumentWillSaveEvent<TextDocument>): void;
3241

42+
/**
43+
* A document save event (initiated) was triggered by the `TextDocuments` service.
44+
* @param event The document change event.
45+
* @returns An array of text edits which will be applied to the document before it is saved.
46+
*/
3347
willSaveDocumentWaitUntil?(event: TextDocumentWillSaveEvent<TextDocument>): MaybePromise<TextEdit[]>;
3448

49+
/**
50+
* A document save event (completed) was triggered by the `TextDocuments` service.
51+
* @param event The document change event.
52+
*/
3553
didSaveDocument?(event: TextDocumentChangeEvent<TextDocument>): void;
3654

55+
/**
56+
* A document close event was triggered by the `TextDocuments` service.
57+
* @param event The document change event.
58+
*/
3759
didCloseDocument?(event: TextDocumentChangeEvent<TextDocument>): void;
3860

3961
/**
4062
* The client detected changes to files and folders watched by the language client.
63+
* @param params The files/folders change event.
4164
*/
4265
didChangeWatchedFiles?(params: DidChangeWatchedFilesParams): void;
4366

@@ -118,5 +141,4 @@ export class DefaultDocumentUpdateHandler implements DocumentUpdateHandler {
118141
.toArray();
119142
this.fireDocumentUpdate(changedUris, deletedUris);
120143
}
121-
122144
}

packages/langium/src/lsp/folding-range-provider.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export interface FoldingRangeProvider {
2121
/**
2222
* Handle a folding range request.
2323
*
24+
* @param document The document to compute folding ranges for
25+
* @param params The folding range parameters
26+
* @param cancelToken A cancellation token that can be used to cancel the request
27+
* @returns The computed folding ranges
28+
*
2429
* @throws `OperationCancelled` if cancellation is detected during execution
2530
* @throws `ResponseError` if an error is detected that should be sent as response to the client
2631
*/
@@ -37,7 +42,7 @@ export class DefaultFoldingRangeProvider implements FoldingRangeProvider {
3742
this.commentNames = services.parser.GrammarConfig.multilineCommentRules;
3843
}
3944

40-
getFoldingRanges(document: LangiumDocument): MaybePromise<FoldingRange[]> {
45+
getFoldingRanges(document: LangiumDocument, _params: FoldingRangeParams, _cancelToken?: CancellationToken): MaybePromise<FoldingRange[]> {
4146
const foldings: FoldingRange[] = [];
4247
const acceptor: FoldingRangeAcceptor = (foldingRange) => foldings.push(foldingRange);
4348
this.collectFolding(document, acceptor);
@@ -73,8 +78,7 @@ export class DefaultFoldingRangeProvider implements FoldingRangeProvider {
7378
* Returns true by default for all nodes. Returning false only ignores the specified node and not its content.
7479
* To ignore the content of a node use `shouldProcessContent`.
7580
*/
76-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
77-
protected shouldProcess(node: AstNode): boolean {
81+
protected shouldProcess(_node: AstNode): boolean {
7882
return true;
7983
}
8084

@@ -83,8 +87,7 @@ export class DefaultFoldingRangeProvider implements FoldingRangeProvider {
8387
* Returns true by default for all nodes. Returning false ignores _all_ content of this node, even transitive ones.
8488
* For more precise control over foldings use the `shouldProcess` method.
8589
*/
86-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
87-
protected shouldProcessContent(node: AstNode): boolean {
90+
protected shouldProcessContent(_node: AstNode): boolean {
8891
return true;
8992
}
9093

packages/langium/src/lsp/references-provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export interface ReferencesProvider {
2323
/**
2424
* Handle a find references request.
2525
*
26+
* @param document The document in which to search for references.
27+
* @param params The parameters of the find references request.
28+
* @param cancelToken A cancellation token that can be used to cancel the request.
29+
* @returns The locations of the references.
30+
*
2631
* @throws `OperationCancelled` if cancellation is detected during execution
2732
* @throws `ResponseError` if an error is detected that should be sent as response to the client
2833
*/
@@ -40,7 +45,7 @@ export class DefaultReferencesProvider implements ReferencesProvider {
4045
this.grammarConfig = services.parser.GrammarConfig;
4146
}
4247

43-
findReferences(document: LangiumDocument, params: ReferenceParams): MaybePromise<Location[]> {
48+
findReferences(document: LangiumDocument, params: ReferenceParams, _cancelToken?: CancellationToken): MaybePromise<Location[]> {
4449
const rootNode = document.parseResult.value.$cstNode;
4550
if (!rootNode) {
4651
return [];

packages/langium/src/lsp/rename-provider.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export interface RenameProvider {
2424
/**
2525
* Handle a rename request.
2626
*
27+
* @param document The document in which the rename request was triggered.
28+
* @param params The rename parameters.
29+
* @param cancelToken A cancellation token that can be used to cancel the request.
30+
* @returns A workspace edit that describes the changes to be applied to the workspace.
31+
*
2732
* @throws `OperationCancelled` if cancellation is detected during execution
2833
* @throws `ResponseError` if an error is detected that should be sent as response to the client
2934
*/
@@ -32,6 +37,11 @@ export interface RenameProvider {
3237
/**
3338
* Handle a prepare rename request.
3439
*
40+
* @param document The document in which the prepare rename request was triggered.
41+
* @param params The prepare rename parameters.
42+
* @param cancelToken A cancellation token that can be used to cancel the request.
43+
* @returns A range that describes the range of the symbol to be renamed.
44+
*
3545
* @throws `OperationCancelled` if cancellation is detected during execution
3646
* @throws `ResponseError` if an error is detected that should be sent as response to the client
3747
*/
@@ -50,7 +60,7 @@ export class DefaultRenameProvider implements RenameProvider {
5060
this.grammarConfig = services.parser.GrammarConfig;
5161
}
5262

53-
async rename(document: LangiumDocument, params: RenameParams): Promise<WorkspaceEdit | undefined> {
63+
async rename(document: LangiumDocument, params: RenameParams, _cancelToken?: CancellationToken): Promise<WorkspaceEdit | undefined> {
5464
const changes: Record<string, TextEdit[]> = {};
5565
const rootNode = document.parseResult.value.$cstNode;
5666
if (!rootNode) return undefined;
@@ -73,7 +83,7 @@ export class DefaultRenameProvider implements RenameProvider {
7383
return { changes };
7484
}
7585

76-
prepareRename(document: LangiumDocument, params: TextDocumentPositionParams): MaybePromise<Range | undefined> {
86+
prepareRename(document: LangiumDocument, params: TextDocumentPositionParams, _cancelToken?: CancellationToken): MaybePromise<Range | undefined> {
7787
return this.renameNodeRange(document, params.position);
7888
}
7989

packages/langium/src/lsp/workspace-symbol-provider.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ export interface WorkspaceSymbolProvider {
2121
/**
2222
* Handle a workspace symbols request.
2323
*
24+
* @param params workspaces symbols request parameters
25+
* @param cancelToken a cancellation token tha can be used to cancel the request
26+
* @returns a list of workspace symbols
27+
*
2428
* @throws `OperationCancelled` if cancellation is detected during execution
2529
* @throws `ResponseError` if an error is detected that should be sent as response to the client
2630
*/
2731
getSymbols(params: WorkspaceSymbolParams, cancelToken?: CancellationToken): MaybePromise<WorkspaceSymbol[]>;
2832
/**
2933
* Handle a resolve request for a workspace symbol.
3034
*
35+
* @param symbol the workspace symbol to resolve
36+
* @param cancelToken a cancellation token tha can be used to cancel the request
37+
* @returns the resolved workspace symbol
38+
*
3139
* @throws `OperationCancelled` if cancellation is detected during execution
3240
* @throws `ResponseError` if an error is detected that should be sent as response to the client
3341
*/

packages/langium/src/parser/async-parser.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@ import { Deferred, OperationCancelled } from '../utils/promise-utils.js';
1414
import { Emitter } from '../utils/event.js';
1515

1616
/**
17-
* Async parser that allows to cancel the current parsing process.
18-
* The sync parser implementation is blocking the event loop, which can become quite problematic for large files.
17+
* Async parser that allows cancellation of the current parsing process.
1918
*
20-
* Note that the default implementation is not actually async. It just wraps the sync parser in a promise.
21-
* A real implementation would create worker threads or web workers to offload the parsing work.
19+
* @remark The sync parser implementation is blocking the event loop, which can become quite problematic for large files.
20+
* @remark The default implementation is not actually async. It just wraps the sync parser in a promise. A real implementation would create worker threads or web workers to offload the parsing work.
2221
*/
2322
export interface AsyncParser {
23+
/**
24+
* Parses the given text and returns the parse result.
25+
*
26+
* @param text The text to parse.
27+
* @param cancelToken A cancellation token that can be used to cancel the parsing process.
28+
* @returns A promise that resolves to the parse result.
29+
*
30+
* @throw `OperationCancelled` if the parsing process is cancelled.
31+
*/
2432
parse<T extends AstNode>(text: string, cancelToken: CancellationToken): Promise<ParseResult<T>>;
2533
}
2634

2735
/**
28-
* Default implementation of the async parser. This implementation only wraps the sync parser in a promise.
36+
* Default implementation of the async parser which simply wraps the sync parser in a promise.
2937
*
30-
* A real implementation would create worker threads or web workers to offload the parsing work.
38+
* @remark A real implementation would create worker threads or web workers to offload the parsing work.
3139
*/
3240
export class DefaultAsyncParser implements AsyncParser {
3341

@@ -37,7 +45,7 @@ export class DefaultAsyncParser implements AsyncParser {
3745
this.syncParser = services.parser.LangiumParser;
3846
}
3947

40-
parse<T extends AstNode>(text: string): Promise<ParseResult<T>> {
48+
parse<T extends AstNode>(text: string, _cancelToken: CancellationToken): Promise<ParseResult<T>> {
4149
return Promise.resolve(this.syncParser.parse<T>(text));
4250
}
4351
}

0 commit comments

Comments
 (0)