Skip to content

Commit a33dc50

Browse files
authored
Filter out notebook codeaction kind (microsoft#184930)
* filter notebook codeactions unless specifically invoked * feedback revisions * fix some mistakes/formatting * simplify
1 parent 4558410 commit a33dc50

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/vs/workbench/api/common/extHostLanguageFeatures.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
77
import { mixin } from 'vs/base/common/objects';
88
import type * as vscode from 'vscode';
99
import * as typeConvert from 'vs/workbench/api/common/extHostTypeConverters';
10-
import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, SymbolInformation, DocumentSymbol, SemanticTokensEdits, SemanticTokens, SemanticTokensEdit, Location, InlineCompletionTriggerKind, InternalDataTransferItem } from 'vs/workbench/api/common/extHostTypes';
10+
import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, SymbolInformation, DocumentSymbol, SemanticTokensEdits, SemanticTokens, SemanticTokensEdit, Location, InlineCompletionTriggerKind, InternalDataTransferItem, CodeActionTriggerKind } from 'vs/workbench/api/common/extHostTypes';
1111
import { ISingleEditOperation } from 'vs/editor/common/core/editOperation';
1212
import * as languages from 'vs/editor/common/languages';
1313
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
@@ -376,6 +376,7 @@ class CodeActionAdapter {
376376

377377
private readonly _cache = new Cache<vscode.CodeAction | vscode.Command>('CodeAction');
378378
private readonly _disposables = new Map<number, DisposableStore>();
379+
private readonly nbKind = new CodeActionKind('notebook');
379380

380381
constructor(
381382
private readonly _documents: ExtHostDocuments,
@@ -414,6 +415,7 @@ class CodeActionAdapter {
414415
if (!isNonEmptyArray(commandsOrActions) || token.isCancellationRequested) {
415416
return undefined;
416417
}
418+
417419
const cacheId = this._cache.add(commandsOrActions);
418420
const disposables = new DisposableStore();
419421
this._disposables.set(cacheId, disposables);
@@ -434,6 +436,10 @@ class CodeActionAdapter {
434436
command: this._commands.toInternal(candidate, disposables),
435437
});
436438
} else {
439+
if (codeActionContext.triggerKind !== CodeActionTriggerKind.Invoke && candidate.kind && this.nbKind.contains(candidate.kind)) {
440+
continue;
441+
}
442+
437443
if (codeActionContext.only) {
438444
if (!candidate.kind) {
439445
this._logService.warn(`${this._extension.identifier.value} - Code actions of kind '${codeActionContext.only.value} 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.`);

src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class CodeActionOnSaveParticipant implements IStoredFileWorkingCopySaveParticipa
280280

281281
private getActionsToRun(model: ITextModel, codeActionKind: CodeActionKind, excludes: readonly CodeActionKind[], progress: IProgress<CodeActionProvider>, token: CancellationToken) {
282282
return getCodeActions(this.languageFeaturesService.codeActionProvider, model, model.getFullModelRange(), {
283-
type: CodeActionTriggerType.Auto,
283+
type: CodeActionTriggerType.Invoke,
284284
triggerAction: CodeActionTriggerSource.OnSave,
285285
filter: { include: codeActionKind, excludes: excludes, includeSourceActions: true },
286286
}, progress, token);

0 commit comments

Comments
 (0)