Skip to content

Commit

Permalink
Merge pull request #211962 from microsoft/tyriar/211949
Browse files Browse the repository at this point in the history
Only enable suggest addon when shell type is pwsh
  • Loading branch information
Tyriar authored May 3, 2024
2 parents 8d282e9 + 723512c commit e54d7e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ export interface ITerminalInstance extends IBaseTerminalInstance {
onDidExecuteText: Event<void>;
onDidChangeTarget: Event<TerminalLocation | undefined>;
onDidSendText: Event<string>;
onDidChangeShellType: Event<TerminalShellType>;

/**
* An event that fires when a terminal is dropped on this instance via drag and drop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
readonly onDidChangeTarget = this._onDidChangeTarget.event;
private readonly _onDidSendText = this._register(new Emitter<string>());
readonly onDidSendText = this._onDidSendText.event;
private readonly _onDidChangeShellType = this._register(new Emitter<TerminalShellType>());
readonly onDidChangeShellType = this._onDidChangeShellType.event;

constructor(
private readonly _terminalShellTypeContextKey: IContextKey<string>,
Expand Down Expand Up @@ -1896,9 +1898,13 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}

setShellType(shellType: TerminalShellType | undefined) {
this._shellType = shellType;
if (this._shellType === shellType) {
return;
}
if (shellType) {
this._shellType = shellType;
this._terminalShellTypeContextKey.set(shellType?.toString());
this._onDidChangeShellType.fire(shellType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import type { Terminal as RawXtermTerminal } from '@xterm/xterm';
import * as dom from 'vs/base/browser/dom';
import { Event } from 'vs/base/common/event';
import { KeyCode } from 'vs/base/common/keyCodes';
import { DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { localize2 } from 'vs/nls';
Expand Down Expand Up @@ -39,7 +40,7 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo

constructor(
private readonly _instance: ITerminalInstance,
_processManager: ITerminalProcessManager,
processManager: ITerminalProcessManager,
widgetManager: TerminalWidgetManager,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
Expand All @@ -51,7 +52,9 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo
}

xtermOpen(xterm: IXtermTerminal & { raw: RawXtermTerminal }): void {
this._loadSuggestAddon(xterm.raw);
this.add(Event.runAndSubscribe(this._instance.onDidChangeShellType, async () => {
this._loadSuggestAddon(xterm.raw);
}));
this.add(this._contextKeyService.onDidChangeContext(e => {
if (e.affectsSome(this._terminalSuggestWidgetContextKeys)) {
this._loadSuggestAddon(xterm.raw);
Expand All @@ -66,8 +69,8 @@ class TerminalSuggestContribution extends DisposableStore implements ITerminalCo

private _loadSuggestAddon(xterm: RawXtermTerminal): void {
const sendingKeybindingsToShell = this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION).sendKeybindingsToShell;
if (sendingKeybindingsToShell) {
this._addon.dispose();
if (sendingKeybindingsToShell || this._instance.shellType !== 'pwsh') {
this._addon.clear();
return;
}
if (this._terminalSuggestWidgetVisibleContextKey) {
Expand Down

0 comments on commit e54d7e9

Please sign in to comment.