Skip to content

Commit

Permalink
Show lightbulb when user makes a selection in js/ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Sep 10, 2021
1 parent 74989b2 commit ad67ad4
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
context: vscode.CodeActionContext,
token: vscode.CancellationToken
): Promise<TsCodeAction[] | undefined> {
if (!this.shouldTrigger(context)) {
if (!this.shouldTrigger(context, rangeOrSelection)) {
return undefined;
}
if (!this.client.toOpenedFilePath(document)) {
Expand Down Expand Up @@ -386,12 +386,14 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider<TsCodeActi
return codeAction;
}

private shouldTrigger(context: vscode.CodeActionContext) {
private shouldTrigger(context: vscode.CodeActionContext, rangeOrSelection: vscode.Range | vscode.Selection) {
if (context.only && !vscode.CodeActionKind.Refactor.contains(context.only)) {
return false;
}

return context.triggerKind === vscode.CodeActionTriggerKind.Invoke;
if (context.triggerKind === vscode.CodeActionTriggerKind.Invoke) {
return true;
}
return rangeOrSelection instanceof vscode.Selection;
}

private static getKind(refactor: Proto.RefactorActionInfo) {
Expand Down

0 comments on commit ad67ad4

Please sign in to comment.