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

dispose of quick fix decoration when the next command is run #161641

Merged
merged 3 commits into from Sep 23, 2022
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
Expand Up @@ -153,6 +153,7 @@ export interface ICommandDetectionCapability {
readonly hasInput: boolean | undefined;
readonly onCommandStarted: Event<ITerminalCommand>;
readonly onCommandFinished: Event<ITerminalCommand>;
readonly onCommandExecuted: Event<void>;
readonly onCommandInvalidated: Event<ITerminalCommand[]>;
readonly onCurrentCommandInvalidated: Event<ICommandInvalidationRequest>;
setCwd(value: string): void;
Expand Down
Expand Up @@ -97,6 +97,8 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
readonly onBeforeCommandFinished = this._onBeforeCommandFinished.event;
private readonly _onCommandFinished = new Emitter<ITerminalCommand>();
readonly onCommandFinished = this._onCommandFinished.event;
private readonly _onCommandExecuted = new Emitter<void>();
readonly onCommandExecuted = this._onCommandExecuted.event;
private readonly _onCommandInvalidated = new Emitter<ITerminalCommand[]>();
readonly onCommandInvalidated = this._onCommandInvalidated.event;
private readonly _onCurrentCommandInvalidated = new Emitter<ICommandInvalidationRequest>();
Expand Down Expand Up @@ -422,6 +424,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
if (y === commandExecutedLine) {
this._currentCommand.command += this._terminal.buffer.active.getLine(commandExecutedLine)?.translateToString(true, undefined, this._currentCommand.commandExecutedX) || '';
}
this._onCommandExecuted.fire();
}

private _handleCommandExecutedWindows(): void {
Expand All @@ -431,6 +434,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
this._onCursorMoveListener = undefined;
this._evaluateCommandMarkersWindows();
this._currentCommand.commandExecutedX = this._terminal.buffer.active.cursorX;
this._onCommandExecuted.fire();
this._logService.debug('CommandDetectionCapability#handleCommandExecuted', this._currentCommand.commandExecutedX, this._currentCommand.commandExecutedMarker?.line);
}

Expand Down
Expand Up @@ -13,7 +13,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { ICommandAction, ITerminalContextualActionOptions } from 'vs/workbench/contrib/terminal/browser/terminal';
import { DecorationSelector, updateLayout } from 'vs/workbench/contrib/terminal/browser/xterm/decorationStyles';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Terminal } from 'xterm';
import { Terminal, IDecoration } from 'xterm';
import { IAction } from 'vs/base/common/actions';

export interface IContextualAction {
Expand Down Expand Up @@ -47,6 +47,8 @@ export class ContextualActionAddon extends Disposable implements ITerminalAddon,

private _matchActions: ICommandAction[] | undefined;

private _decoration: IDecoration | undefined;

constructor(private readonly _capabilities: ITerminalCapabilityStore,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
@IConfigurationService private readonly _configurationService: IConfigurationService) {
Expand Down Expand Up @@ -83,7 +85,13 @@ export class ContextualActionAddon extends Disposable implements ITerminalAddon,
if (!terminal || !commandDetection) {
return;
}
this._register(commandDetection.onCommandExecuted(() => {
this._decoration?.dispose();
this._decoration = undefined;
}));
this._register(commandDetection.onCommandFinished(async command => {
this._decoration?.dispose();
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
this._decoration = undefined;
this._matchActions = getMatchActions(command, this._commandListeners, this._onDidRequestRerunCommand);
}));
// The buffer is not ready by the time command finish
Expand All @@ -107,6 +115,7 @@ export class ContextualActionAddon extends Disposable implements ITerminalAddon,
}
const actions = this._matchActions;
const decoration = this._terminal.registerDecoration({ marker, layer: 'top' });
this._decoration = decoration;
decoration?.onRender((e: HTMLElement) => {
if (!this._decorationMarkerIds.has(decoration.marker.id)) {
this._currentQuickFixElement = e;
Expand Down