Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CodeActionOptions with providedCodeActionKinds #385

Merged
merged 1 commit into from
Aug 21, 2018
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
17 changes: 15 additions & 2 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
CompletionItem as VCompletionItem, CompletionList as VCompletionList, SignatureHelp as VSignatureHelp, Definition as VDefinition, DocumentHighlight as VDocumentHighlight,
SymbolInformation as VSymbolInformation, CodeActionContext as VCodeActionContext, Command as VCommand, CodeLens as VCodeLens,
FormattingOptions as VFormattingOptions, TextEdit as VTextEdit, WorkspaceEdit as VWorkspaceEdit, MessageItem,
Hover as VHover, CodeAction as VCodeAction, DocumentSymbol as VDocumentSymbol,
Hover as VHover, CodeActionKind as VCodeActionKind, CodeAction as VCodeAction, DocumentSymbol as VDocumentSymbol,
DocumentLink as VDocumentLink, TextDocumentWillSaveEvent,
WorkspaceFolder as VWorkspaceFolder, CompletionContext as VCompletionContext, ConfigurationChangeEvent
} from 'vscode';
Expand Down Expand Up @@ -53,7 +53,7 @@ import {
DocumentLinkRequest, DocumentLinkResolveRequest, DocumentLinkRegistrationOptions,
ExecuteCommandRequest, ExecuteCommandParams, ExecuteCommandRegistrationOptions,
ApplyWorkspaceEditRequest, ApplyWorkspaceEditParams, ApplyWorkspaceEditResponse,
MarkupKind, SymbolKind, CompletionItemKind, Command, CodeActionKind, DocumentSymbol, SymbolInformation
MarkupKind, SymbolKind, CompletionItemKind, Command, CodeActionKind, DocumentSymbol, SymbolInformation, CodeActionOptions
} from 'vscode-languageserver-protocol';

import { ColorProviderMiddleware } from './colorProvider';
Expand Down Expand Up @@ -1668,6 +1668,8 @@ class WorkspaceSymbolFeature extends WorkspaceFeature<undefined> {

class CodeActionFeature extends TextDocumentFeature<TextDocumentRegistrationOptions> {

private _providedCodeActionKinds: CodeActionKind[] = [];

constructor(client: BaseLanguageClient) {
super(client, CodeActionRequest.type);
}
Expand Down Expand Up @@ -1695,6 +1697,11 @@ class CodeActionFeature extends TextDocumentFeature<TextDocumentRegistrationOpti
if (!capabilities.codeActionProvider || !documentSelector) {
return;
}

const codeActionOptions = capabilities.codeActionProvider as CodeActionOptions;
if (codeActionOptions !== void 0 && codeActionOptions.providedCodeActionKinds !== void 0) {
this._providedCodeActionKinds = codeActionOptions.providedCodeActionKinds;
}
this.register(this.messages, {
id: UUID.generateUuid(),
registerOptions: Object.assign({}, { documentSelector: documentSelector })
Expand Down Expand Up @@ -1730,12 +1737,18 @@ class CodeActionFeature extends TextDocumentFeature<TextDocumentRegistrationOpti
);
}
let middleware = client.clientOptions.middleware!;
let providedCodeActionKinds :VCodeActionKind[] = [];
for (let kind of this._providedCodeActionKinds) {
providedCodeActionKinds.push(client.protocol2CodeConverter.asCodeActionKind(kind));
}
return Languages.registerCodeActionsProvider(options.documentSelector!, {
provideCodeActions: (document: TextDocument, range: VRange, context: VCodeActionContext, token: CancellationToken): ProviderResult<(VCommand | VCodeAction)[]> => {
return middleware.provideCodeActions
? middleware.provideCodeActions(document, range, context, token, provideCodeActions)
: provideCodeActions(document, range, context, token);
}
}, {
providedCodeActionKinds: providedCodeActionKinds
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions client/src/protocolConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export interface Converter {
asCodeAction(item: undefined | null): undefined;
asCodeAction(item: ls.CodeAction | undefined | null): code.CodeAction | undefined;

asCodeActionKind(item: null | undefined): undefined;
asCodeActionKind(item: ls.CodeActionKind): code.CodeActionKind;
asCodeActionKind(item: ls.CodeActionKind | null | undefined): code.CodeActionKind | undefined;

asCodeLens(item: ls.CodeLens): code.CodeLens;
asCodeLens(item: undefined | null): undefined;
asCodeLens(item: ls.CodeLens | undefined | null): code.CodeLens | undefined;
Expand Down Expand Up @@ -758,6 +762,7 @@ export function createConverter(uriConverter?: URIConverter): Converter {
asCommand,
asCommands,
asCodeAction,
asCodeActionKind,
asCodeLens,
asCodeLenses,
asWorkspaceEdit,
Expand Down
15 changes: 14 additions & 1 deletion protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,19 @@ export interface SignatureHelpOptions {
triggerCharacters?: string[];
}

/**
* Code Action options.
*/
export interface CodeActionOptions {
/**
* CodeActionKinds that this server may return.
*
* The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server
* may list out every specific kind they provide.
*/
providedCodeActionKinds?: CodeActionKind[];
}

/**
* Code Lens options.
*/
Expand Down Expand Up @@ -766,7 +779,7 @@ export interface _ServerCapabilities {
/**
* The server provides code actions.
*/
codeActionProvider?: boolean;
codeActionProvider?: boolean | CodeActionOptions;
/**
* The server provides code lens.
*/
Expand Down