Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"vscode-css-languageservice": "5.0.0",
"vscode-emmet-helper": "2.1.2",
"vscode-html-languageservice": "4.0.0",
"vscode-languageserver": "7.0.0",
"vscode-languageserver": "7.1.0-next.4",
"vscode-languageserver-types": "3.16.0",
"vscode-uri": "2.1.2"
}
Expand Down
36 changes: 24 additions & 12 deletions packages/language-server/src/plugins/PluginHost.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { flatten } from 'lodash';
import {
CancellationToken,
CodeAction,
CodeActionContext,
Color,
Expand Down Expand Up @@ -86,7 +87,8 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
async getCompletions(
textDocument: TextDocumentIdentifier,
position: Position,
completionContext?: CompletionContext
completionContext?: CompletionContext,
cancellationToken?: CancellationToken
): Promise<CompletionList> {
const document = this.getDocument(textDocument.uri);
if (!document) {
Expand All @@ -96,7 +98,7 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
const completions = (
await this.execute<CompletionList>(
'getCompletions',
[document, position, completionContext],
[document, position, completionContext, cancellationToken],
ExecuteMode.Collect
)
).filter((completion) => completion != null);
Expand Down Expand Up @@ -127,7 +129,8 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {

async resolveCompletion(
textDocument: TextDocumentIdentifier,
completionItem: AppCompletionItem
completionItem: AppCompletionItem,
cancellationToken: CancellationToken
): Promise<CompletionItem> {
const document = this.getDocument(textDocument.uri);

Expand All @@ -137,7 +140,7 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {

const result = await this.execute<CompletionItem>(
'resolveCompletion',
[document, completionItem],
[document, completionItem, cancellationToken],
ExecuteMode.FirstNonNull
);

Expand Down Expand Up @@ -212,7 +215,10 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
);
}

async getDocumentSymbols(textDocument: TextDocumentIdentifier): Promise<SymbolInformation[]> {
async getDocumentSymbols(
textDocument: TextDocumentIdentifier,
cancellationToken: CancellationToken
): Promise<SymbolInformation[]> {
const document = this.getDocument(textDocument.uri);
if (!document) {
throw new Error('Cannot call methods on an unopened document');
Expand All @@ -221,7 +227,7 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
return flatten(
await this.execute<SymbolInformation[]>(
'getDocumentSymbols',
[document],
[document, cancellationToken],
ExecuteMode.Collect
)
);
Expand Down Expand Up @@ -256,7 +262,8 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
async getCodeActions(
textDocument: TextDocumentIdentifier,
range: Range,
context: CodeActionContext
context: CodeActionContext,
cancellationToken: CancellationToken
): Promise<CodeAction[]> {
const document = this.getDocument(textDocument.uri);
if (!document) {
Expand All @@ -266,7 +273,7 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
return flatten(
await this.execute<CodeAction[]>(
'getCodeActions',
[document, range, context],
[document, range, context, cancellationToken],
ExecuteMode.Collect
)
);
Expand Down Expand Up @@ -350,7 +357,8 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
async getSignatureHelp(
textDocument: TextDocumentIdentifier,
position: Position,
context: SignatureHelpContext | undefined
context: SignatureHelpContext | undefined,
cancellationToken: CancellationToken
): Promise<SignatureHelp | null> {
const document = this.getDocument(textDocument.uri);
if (!document) {
Expand All @@ -359,7 +367,7 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {

return await this.execute<any>(
'getSignatureHelp',
[document, position, context],
[document, position, context, cancellationToken],
ExecuteMode.FirstNonNull
);
}
Expand Down Expand Up @@ -403,15 +411,19 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
}
}

async getSemanticTokens(textDocument: TextDocumentIdentifier, range?: Range) {
async getSemanticTokens(
textDocument: TextDocumentIdentifier,
range?: Range,
cancellationToken?: CancellationToken
) {
const document = this.getDocument(textDocument.uri);
if (!document) {
throw new Error('Cannot call methods on an unopened document');
}

return await this.execute<SemanticTokens>(
'getSemanticTokens',
[document, range],
[document, range, cancellationToken],
ExecuteMode.FirstNonNull
);
}
Expand Down
18 changes: 13 additions & 5 deletions packages/language-server/src/plugins/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CancellationToken,
CompletionContext,
FileChangeType,
LinkedEditingRanges,
Expand Down Expand Up @@ -53,12 +54,14 @@ export interface CompletionsProvider<T extends TextDocumentIdentifier = any> {
getCompletions(
document: Document,
position: Position,
completionContext?: CompletionContext
completionContext?: CompletionContext,
cancellationToken?: CancellationToken
): Resolvable<AppCompletionList<T> | null>;

resolveCompletion?(
document: Document,
completionItem: AppCompletionItem<T>
completionItem: AppCompletionItem<T>,
cancellationToken?: CancellationToken
): Resolvable<AppCompletionItem<T>>;
}

Expand All @@ -83,7 +86,10 @@ export interface ColorPresentationsProvider {
}

export interface DocumentSymbolsProvider {
getDocumentSymbols(document: Document): Resolvable<SymbolInformation[]>;
getDocumentSymbols(
document: Document,
cancellationToken?: CancellationToken
): Resolvable<SymbolInformation[]>;
}

export interface DefinitionsProvider {
Expand All @@ -101,7 +107,8 @@ export interface CodeActionsProvider {
getCodeActions(
document: Document,
range: Range,
context: CodeActionContext
context: CodeActionContext,
cancellationToken?: CancellationToken
): Resolvable<CodeAction[]>;
executeCommand?(
document: Document,
Expand Down Expand Up @@ -140,7 +147,8 @@ export interface SignatureHelpProvider {
getSignatureHelp(
document: Document,
position: Position,
context: SignatureHelpContext | undefined
context: SignatureHelpContext | undefined,
cancellationToken?: CancellationToken
): Resolvable<SignatureHelp | null>;
}

Expand Down
26 changes: 22 additions & 4 deletions packages/language-server/src/plugins/svelte/SveltePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
Range,
TextEdit,
WorkspaceEdit,
SelectionRange
SelectionRange,
CancellationToken,
CompletionContext
} from 'vscode-languageserver';
import { Document } from '../../lib/documents';
import { LSConfigManager, LSSvelteConfig } from '../../ls-config';
Expand Down Expand Up @@ -138,12 +140,22 @@ export class SveltePlugin
}
}

async getCompletions(document: Document, position: Position): Promise<CompletionList | null> {
async getCompletions(
document: Document,
position: Position,
_?: CompletionContext,
cancellationToken?: CancellationToken
): Promise<CompletionList | null> {
if (!this.featureEnabled('completions')) {
return null;
}

return getCompletions(await this.getSvelteDoc(document), position);
const svelteDoc = await this.getSvelteDoc(document);
if (cancellationToken?.isCancellationRequested) {
return null;
}

return getCompletions(svelteDoc, position);
}

async doHover(document: Document, position: Position): Promise<Hover | null> {
Expand All @@ -157,13 +169,19 @@ export class SveltePlugin
async getCodeActions(
document: Document,
range: Range,
context: CodeActionContext
context: CodeActionContext,
cancellationToken?: CancellationToken
): Promise<CodeAction[]> {
if (!this.featureEnabled('codeActions')) {
return [];
}

const svelteDoc = await this.getSvelteDoc(document);

if (cancellationToken?.isCancellationRequested) {
return [];
}

try {
return getCodeActions(svelteDoc, range, context);
} catch (error) {
Expand Down
60 changes: 47 additions & 13 deletions packages/language-server/src/plugins/typescript/TypeScriptPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ts, { NavigationTree } from 'typescript';
import {
CancellationToken,
CodeAction,
CodeActionContext,
CompletionContext,
Expand Down Expand Up @@ -112,12 +113,15 @@ export class TypeScriptPlugin
this.semanticTokensProvider = new SemanticTokensProviderImpl(this.lsAndTsDocResolver);
}

async getDiagnostics(document: Document): Promise<Diagnostic[]> {
async getDiagnostics(
document: Document,
cancellationToken?: CancellationToken
): Promise<Diagnostic[]> {
if (!this.featureEnabled('diagnostics')) {
return [];
}

return this.diagnosticsProvider.getDiagnostics(document);
return this.diagnosticsProvider.getDiagnostics(document, cancellationToken);
}

async doHover(document: Document, position: Position): Promise<Hover | null> {
Expand All @@ -128,13 +132,21 @@ export class TypeScriptPlugin
return this.hoverProvider.doHover(document, position);
}

async getDocumentSymbols(document: Document): Promise<SymbolInformation[]> {
async getDocumentSymbols(
document: Document,
cancellationToken?: CancellationToken
): Promise<SymbolInformation[]> {
if (!this.featureEnabled('documentSymbols')) {
return [];
}

const { lang, tsDoc } = await this.getLSAndTSDoc(document);
const fragment = await tsDoc.getFragment();

if (cancellationToken?.isCancellationRequested) {
return [];
}

const navTree = lang.getNavigationTree(tsDoc.filePath);

const symbols: SymbolInformation[] = [];
Expand Down Expand Up @@ -209,7 +221,8 @@ export class TypeScriptPlugin
async getCompletions(
document: Document,
position: Position,
completionContext?: CompletionContext
completionContext?: CompletionContext,
cancellationToken?: CancellationToken
): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null> {
if (!this.featureEnabled('completions')) {
return null;
Expand All @@ -224,7 +237,8 @@ export class TypeScriptPlugin
const completions = await this.completionProvider.getCompletions(
document,
position,
completionContext
completionContext,
cancellationToken
);

if (completions && tsDirectiveCommentCompletions) {
Expand All @@ -239,9 +253,14 @@ export class TypeScriptPlugin

async resolveCompletion(
document: Document,
completionItem: AppCompletionItem<CompletionEntryWithIdentifer>
completionItem: AppCompletionItem<CompletionEntryWithIdentifer>,
cancellationToken?: CancellationToken
): Promise<AppCompletionItem<CompletionEntryWithIdentifer>> {
return this.completionProvider.resolveCompletion(document, completionItem);
return this.completionProvider.resolveCompletion(
document,
completionItem,
cancellationToken
);
}

async getDefinitions(document: Document, position: Position): Promise<DefinitionLink[]> {
Expand Down Expand Up @@ -304,13 +323,14 @@ export class TypeScriptPlugin
async getCodeActions(
document: Document,
range: Range,
context: CodeActionContext
context: CodeActionContext,
cancellationToken?: CancellationToken
): Promise<CodeAction[]> {
if (!this.featureEnabled('codeActions')) {
return [];
}

return this.codeActionsProvider.getCodeActions(document, range, context);
return this.codeActionsProvider.getCodeActions(document, range, context, cancellationToken);
}

async executeCommand(
Expand Down Expand Up @@ -405,23 +425,37 @@ export class TypeScriptPlugin
async getSignatureHelp(
document: Document,
position: Position,
context: SignatureHelpContext | undefined
context: SignatureHelpContext | undefined,
cancellationToken?: CancellationToken
): Promise<SignatureHelp | null> {
if (!this.featureEnabled('signatureHelp')) {
return null;
}

return this.signatureHelpProvider.getSignatureHelp(document, position, context);
return this.signatureHelpProvider.getSignatureHelp(
document,
position,
context,
cancellationToken
);
}

async getSemanticTokens(textDocument: Document, range?: Range): Promise<SemanticTokens | null> {
async getSemanticTokens(
textDocument: Document,
range?: Range,
cancellationToken?: CancellationToken
): Promise<SemanticTokens | null> {
if (!this.featureEnabled('semanticTokens')) {
return {
data: []
};
}

return this.semanticTokensProvider.getSemanticTokens(textDocument, range);
return this.semanticTokensProvider.getSemanticTokens(
textDocument,
range,
cancellationToken
);
}

private async getLSAndTSDoc(document: Document) {
Expand Down
Loading