Skip to content

Commit

Permalink
Don't return code actions for types we weren't asked for
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Jun 6, 2019
1 parent 564140e commit 9e06d2d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/extension/providers/assist_code_action_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class AssistCodeActionProvider implements RankedCodeActionProvider {
public provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): Promise<CodeAction[]> | undefined {
if (!isAnalyzableAndInWorkspace(document))
return undefined;
// If we were only asked for specific action types and that doesn't include
// refactor (which is all we supply), bail out.
if (context && context.only && !context.only.contains(CodeActionKind.Refactor))
return undefined;
return new Promise<CodeAction[]>((resolve, reject) => {
this.analyzer.editGetAssists({
file: fsPath(document.uri),
Expand Down
4 changes: 4 additions & 0 deletions src/extension/providers/fix_code_action_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class FixCodeActionProvider implements RankedCodeActionProvider {
public async provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): Promise<CodeAction[]> | undefined {
if (!isAnalyzableAndInWorkspace(document))
return undefined;
// If we were only asked for specific action types and that doesn't include
// quickfix (which is all we supply), bail out.
if (context && context.only && !context.only.contains(CodeActionKind.QuickFix))
return undefined;
try {
const result = await this.analyzer.editGetFixes({
file: fsPath(document.uri),
Expand Down
4 changes: 4 additions & 0 deletions src/extension/providers/ignore_lint_code_action_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class IgnoreLintCodeActionProvider implements RankedCodeActionProvider {
public async provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): Promise<CodeAction[]> | undefined {
if (!isAnalyzableAndInWorkspace(document))
return undefined;
// If we were only asked for specific action types and that doesn't include
// quickfix (which is all we supply), bail out.
if (context && context.only && !context.only.contains(CodeActionKind.QuickFix))
return undefined;

if (!config.showIgnoreQuickFixes || !context || !context.diagnostics || !context.diagnostics.length)
return undefined;
Expand Down
4 changes: 4 additions & 0 deletions src/extension/providers/refactor_code_action_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class RefactorCodeActionProvider implements RankedCodeActionProvider {
public async provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): Promise<CodeAction[]> | undefined {
if (!isAnalyzableAndInWorkspace(document))
return undefined;
// If we were only asked for specific action types and that doesn't include
// refactor (which is all we supply), bail out.
if (context && context.only && !context.only.contains(CodeActionKind.Refactor))
return undefined;
try {
const result = await this.analyzer.editGetAvailableRefactorings({
file: fsPath(document.uri),
Expand Down
4 changes: 4 additions & 0 deletions src/extension/providers/source_code_action_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class SourceCodeActionProvider implements CodeActionProvider {
public provideCodeActions(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): CodeAction[] | undefined {
if (!isAnalyzableAndInWorkspace(document))
return undefined;
// If we were only asked for specific action types and that doesn't include
// source (which is all we supply), bail out.
if (context && context.only && !context.only.contains(CodeActionKind.Source))
return undefined;
return [{
command: {
arguments: [document],
Expand Down

0 comments on commit 9e06d2d

Please sign in to comment.