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

Revert AI light-bulb #198857

Merged
merged 1 commit into from
Nov 22, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/vs/base/common/codicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ export const Codicon = {
gitFetch: register('git-fetch', 0xec1d),
copilot: register('copilot', 0xec1e),
lightbulbSparkle: register('lightbulb-sparkle', 0xec1f),
lightbulbSparkleAutofix: register('lightbulb-sparkle-autofix', 0xec1f),

// derived icons, that could become separate icons

Expand Down
8 changes: 0 additions & 8 deletions src/vs/editor/contrib/codeAction/browser/codeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ class ManagedCodeActionSet extends Disposable implements CodeActionSet {
public get hasAutoFix() {
return this.validActions.some(({ action: fix }) => !!fix.kind && CodeActionKind.QuickFix.contains(new CodeActionKind(fix.kind)) && !!fix.isPreferred);
}

public get hasAIFix() {
return this.validActions.some(({ action: fix }) => !!fix.isAI);
}

public get allAIFixes() {
return this.validActions.every(({ action: fix }) => !!fix.isAI);
}
}

const emptyCodeActionsResponse = { actions: [] as CodeActionItem[], documentation: undefined };
Expand Down
41 changes: 36 additions & 5 deletions src/vs/editor/contrib/codeAction/browser/codeActionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CodeActionOracle extends Disposable {
}

public trigger(trigger: CodeActionTrigger): void {
const selection = this._editor.getSelection();
const selection = this._getRangeOfSelectionUnlessWhitespaceEnclosed(trigger);
this._signalChange(selection ? { trigger, selection } : undefined);
}

Expand All @@ -61,6 +61,39 @@ class CodeActionOracle extends Disposable {
this.trigger({ type: CodeActionTriggerType.Auto, triggerAction: CodeActionTriggerSource.Default });
}, this._delay);
}

private _getRangeOfSelectionUnlessWhitespaceEnclosed(trigger: CodeActionTrigger): Selection | undefined {
if (!this._editor.hasModel()) {
return undefined;
}

const model = this._editor.getModel();
const selection = this._editor.getSelection();
if (selection.isEmpty() && trigger.type === CodeActionTriggerType.Auto) {
const { lineNumber, column } = selection.getPosition();
const line = model.getLineContent(lineNumber);
if (line.length === 0) {
// empty line
return undefined;
} else if (column === 1) {
// look only right
if (/\s/.test(line[0])) {
return undefined;
}
} else if (column === model.getLineMaxColumn(lineNumber)) {
// look only left
if (/\s/.test(line[line.length - 1])) {
return undefined;
}
} else {
// look left and right
if (/\s/.test(line[column - 2]) && /\s/.test(line[column - 1])) {
return undefined;
}
}
}
return selection;
}
}

export namespace CodeActionsState {
Expand Down Expand Up @@ -100,9 +133,7 @@ const emptyCodeActionSet = Object.freeze<CodeActionSet>({
validActions: [],
dispose: () => { },
documentation: [],
hasAutoFix: false,
hasAIFix: false,
allAIFixes: false,
hasAutoFix: false
});


Expand Down Expand Up @@ -253,7 +284,7 @@ export class CodeActionModel extends Disposable {
});

// Only retriggers if actually found quickfix on the same line as cursor
return { validActions: filteredActions, allActions: allCodeActions, documentation: codeActionSet.documentation, hasAutoFix: codeActionSet.hasAutoFix, hasAIFix: codeActionSet.hasAIFix, allAIFixes: codeActionSet.allAIFixes, dispose: () => { codeActionSet.dispose(); } };
return { validActions: filteredActions, allActions: allCodeActions, documentation: codeActionSet.documentation, hasAutoFix: codeActionSet.hasAutoFix, dispose: () => { codeActionSet.dispose(); } };
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/vs/editor/contrib/codeAction/browser/lightBulbWidget.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
cursor: pointer;
}

.monaco-editor .lightBulbWidget.codicon-light-bulb,
.monaco-editor .lightBulbWidget.codicon-lightbulb-sparkle {
.monaco-editor .lightBulbWidget.codicon-light-bulb {
color: var(--vscode-editorLightBulb-foreground);
}

.monaco-editor .lightBulbWidget.codicon-lightbulb-autofix,
.monaco-editor .lightBulbWidget.codicon-lightbulb-sparkle-autofix {
.monaco-editor .lightBulbWidget.codicon-lightbulb-autofix {
color: var(--vscode-editorLightBulbAutoFix-foreground, var(--vscode-editorLightBulb-foreground));
}

Expand Down
63 changes: 20 additions & 43 deletions src/vs/editor/contrib/codeAction/browser/lightBulbWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { computeIndentLevel } from 'vs/editor/common/model/utils';
import { autoFixCommandId, quickFixCommandId } from 'vs/editor/contrib/codeAction/browser/codeAction';
import type { CodeActionSet, CodeActionTrigger } from 'vs/editor/contrib/codeAction/common/types';
import * as nls from 'vs/nls';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';

namespace LightBulbState {
Expand Down Expand Up @@ -55,15 +54,13 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
public readonly onClick = this._onClick.event;

private _state: LightBulbState.State = LightBulbState.Hidden;
private _iconClasses: string[] = [];

private _preferredKbLabel?: string;
private _quickFixKbLabel?: string;

constructor(
private readonly _editor: ICodeEditor,
@IKeybindingService keybindingService: IKeybindingService,
@ICommandService commandService: ICommandService,
@IKeybindingService keybindingService: IKeybindingService
) {
super();

Expand All @@ -81,25 +78,14 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
}
}));

this._register(dom.addStandardDisposableGenericMouseDownListener(this._domNode, async e => {
this._register(dom.addStandardDisposableGenericMouseDownListener(this._domNode, e => {
if (this.state.type !== LightBulbState.Type.Showing) {
return;
}
const focusEditor = () => {
this._editor.focus();
e.preventDefault();
};

if (this.state.actions.allAIFixes && this.state.actions.validActions.length === 1) {
const action = this.state.actions.validActions[0].action;
if (action.command?.id) {
commandService.executeCommand(action.command.id, ...(action.command.arguments || []));
}
focusEditor();
return;
}

// Make sure that focus / cursor location is not lost when clicking widget icon
focusEditor();
this._editor.focus();
e.preventDefault();
// a bit of extra work to make sure the menu
// doesn't cover the line-text
const { top, height } = dom.getDomNodePagePosition(this._domNode);
Expand Down Expand Up @@ -222,35 +208,26 @@ export class LightBulbWidget extends Disposable implements IContentWidget {
}

private _updateLightBulbTitleAndIcon(): void {
this._domNode.classList.remove(...this._iconClasses);
this._iconClasses = [];
if (this.state.type !== LightBulbState.Type.Showing) {
return;
}
let icon: ThemeIcon;
if (this.state.actions.allAIFixes) {
icon = Codicon.sparkle;
} else if (this.state.actions.hasAutoFix) {
if (this.state.actions.hasAIFix) {
icon = Codicon.lightbulbSparkleAutofix;
} else {
icon = Codicon.lightbulbAutofix;
}
if (this.state.type === LightBulbState.Type.Showing && this.state.actions.hasAutoFix) {
// update icon
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightBulb));
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.lightbulbAutofix));

if (this._preferredKbLabel) {
this.title = nls.localize('preferredcodeActionWithKb', "Show Code Actions. Preferred Quick Fix Available ({0})", this._preferredKbLabel);
return;
}
} else if (this.state.actions.hasAIFix) {
icon = Codicon.lightbulbSparkle;
}

// update icon
this._domNode.classList.remove(...ThemeIcon.asClassNameArray(Codicon.lightbulbAutofix));
this._domNode.classList.add(...ThemeIcon.asClassNameArray(Codicon.lightBulb));

if (this._quickFixKbLabel) {
this.title = nls.localize('codeActionWithKb', "Show Code Actions ({0})", this._quickFixKbLabel);
} else {
icon = Codicon.lightBulb;
if (this._quickFixKbLabel) {
this.title = nls.localize('codeActionWithKb', "Show Code Actions ({0})", this._quickFixKbLabel);
} else {
this.title = nls.localize('codeAction', "Show Code Actions");
}
this.title = nls.localize('codeAction', "Show Code Actions");
}
this._iconClasses = ThemeIcon.asClassNameArray(icon);
this._domNode.classList.add(...this._iconClasses);
}

private set title(value: string) {
Expand Down
2 changes: 0 additions & 2 deletions src/vs/platform/actionWidget/common/actionWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ export interface ActionSet<T> extends IDisposable {
readonly validActions: readonly T[];
readonly allActions: readonly T[];
readonly hasAutoFix: boolean;
readonly hasAIFix: boolean;
readonly allAIFixes: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
documentation,
allActions: actions,
hasAutoFix: false,
hasAIFix: false,
allAIFixes: false,
validActions: actions,
dispose: () => { }
} as ActionSet<TerminalQuickFixItem>;
Expand Down