Skip to content

Commit

Permalink
Merge branch 'main' into fix/terminal-suggestion-positioning__accept-…
Browse files Browse the repository at this point in the history
…completions
  • Loading branch information
cpendery authored Dec 7, 2023
2 parents cc49e84 + 64c7a59 commit b07c5df
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const REMOTE_TUNNEL_CONNECTION_STATE = new RawContextKey<CONTEXT_KEY_STAT
const REMOTE_TUNNEL_USED_STORAGE_KEY = 'remoteTunnelServiceUsed';
const REMOTE_TUNNEL_PROMPTED_PREVIEW_STORAGE_KEY = 'remoteTunnelServicePromptedPreview';
const REMOTE_TUNNEL_EXTENSION_RECOMMENDED_KEY = 'remoteTunnelExtensionRecommended';
const REMOTE_TUNNEL_HAS_USED_BEFORE = 'remoteTunnelHasUsed';
const REMOTE_TUNNEL_EXTENSION_TIMEOUT = 4 * 60 * 1000; // show the recommendation that a machine started using tunnels if it joined less than 4 minutes ago

const INVALID_TOKEN_RETRIES = 2;
Expand Down Expand Up @@ -236,38 +237,47 @@ export class RemoteTunnelWorkbenchContribution extends Disposable implements IWo
return; // already initialized, token available
}

return await this.progressService.withProgress(
{
location: ProgressLocation.Window,
title: localize({ key: 'initialize.progress.title', comment: ['Only translate \'Looking for remote tunnel\', do not change the format of the rest (markdown link format)'] }, "[Looking for remote tunnel](command:{0})", RemoteTunnelCommandIds.showLog),
},
async (progress: IProgress<IProgressStep>) => {
const listener = this.remoteTunnelService.onDidChangeTunnelStatus(status => {
switch (status.type) {
case 'connecting':
if (status.progress) {
progress.report({ message: status.progress });
}
break;
}
});
let newSession: IRemoteTunnelSession | undefined;
if (mode.active) {
const token = await this.getSessionToken(mode.session);
if (token) {
newSession = { ...mode.session, token };
}
const doInitialStateDiscovery = async (progress?: IProgress<IProgressStep>) => {
const listener = progress && this.remoteTunnelService.onDidChangeTunnelStatus(status => {
switch (status.type) {
case 'connecting':
if (status.progress) {
progress.report({ message: status.progress });
}
break;
}
const status = await this.remoteTunnelService.initialize(mode.active && newSession ? { ...mode, session: newSession } : INACTIVE_TUNNEL_MODE);
listener.dispose();

if (status.type === 'connected') {
this.connectionInfo = status.info;
this.connectionStateContext.set('connected');
return;
});
let newSession: IRemoteTunnelSession | undefined;
if (mode.active) {
const token = await this.getSessionToken(mode.session);
if (token) {
newSession = { ...mode.session, token };
}
}
);
const status = await this.remoteTunnelService.initialize(mode.active && newSession ? { ...mode, session: newSession } : INACTIVE_TUNNEL_MODE);
listener?.dispose();

if (status.type === 'connected') {
this.connectionInfo = status.info;
this.connectionStateContext.set('connected');
return;
}
};


const hasUsed = this.storageService.getBoolean(REMOTE_TUNNEL_HAS_USED_BEFORE, StorageScope.APPLICATION, false);

if (hasUsed) {
await this.progressService.withProgress(
{
location: ProgressLocation.Window,
title: localize({ key: 'initialize.progress.title', comment: ['Only translate \'Looking for remote tunnel\', do not change the format of the rest (markdown link format)'] }, "[Looking for remote tunnel](command:{0})", RemoteTunnelCommandIds.showLog),
},
doInitialStateDiscovery
);
} else {
doInitialStateDiscovery(undefined);
}
}

private getPreferredTokenFromSession(session: ExistingSessionItem) {
Expand All @@ -279,6 +289,8 @@ export class RemoteTunnelWorkbenchContribution extends Disposable implements IWo
return this.connectionInfo;
}

this.storageService.store(REMOTE_TUNNEL_HAS_USED_BEFORE, true, StorageScope.APPLICATION, StorageTarget.MACHINE);

let tokenProblems = false;
for (let i = 0; i < INVALID_TOKEN_RETRIES; i++) {
tokenProblems = false;
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ export interface ITerminalInstance extends IBaseTerminalInstance {
*/
pasteSelection(): Promise<void>;

/**
* Override the copy on selection feature with a custom value.
* @param value Whether to enable copySelection.
*/
overrideCopyOnSelection(value: boolean): IDisposable;

/**
* Send text to the terminal instance. The text is written to the stdin of the underlying pty
* process (shell) of the terminal instance.
Expand Down
12 changes: 12 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1691,12 +1691,24 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private async _onSelectionChange(): Promise<void> {
this._onDidChangeSelection.fire(this);
if (this._configurationService.getValue(TerminalSettingId.CopyOnSelection)) {
if (this._overrideCopySelection === false) {
return;
}
if (this.hasSelection()) {
await this.copySelection();
}
}
}

private _overrideCopySelection: boolean | undefined = undefined;
overrideCopyOnSelection(value: boolean): IDisposable {
if (this._overrideCopySelection !== undefined) {
throw new Error('Cannot set a copy on selection override multiple times');
}
this._overrideCopySelection = value;
return toDisposable(() => this._overrideCopySelection = undefined);
}

@debounce(2000)
private async _updateProcessCwd(): Promise<void> {
if (this.isDisposed || this.shellLaunchConfig.customPtyImplementation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { ISearchOptions } from '@xterm/addon-search';
import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { openContextMenu } from 'vs/workbench/contrib/terminalContrib/find/browser/textInputContextMenu';
import { IDisposable } from 'vs/base/common/lifecycle';

const TERMINAL_FIND_WIDGET_INITIAL_WIDTH = 419;

Expand All @@ -25,6 +26,8 @@ export class TerminalFindWidget extends SimpleFindWidget {
private _findWidgetFocused: IContextKey<boolean>;
private _findWidgetVisible: IContextKey<boolean>;

private _overrideCopyOnSelectionDisposable: IDisposable | undefined;

constructor(
private _instance: ITerminalInstance | IDetachedTerminalInstance,
@IContextViewService _contextViewService: IContextViewService,
Expand Down Expand Up @@ -143,10 +146,14 @@ export class TerminalFindWidget extends SimpleFindWidget {
}

protected _onFocusTrackerFocus() {
if ('overrideCopyOnSelection' in this._instance) {
this._overrideCopyOnSelectionDisposable = this._instance.overrideCopyOnSelection(false);
}
this._findWidgetFocused.set(true);
}

protected _onFocusTrackerBlur() {
this._overrideCopyOnSelectionDisposable?.dispose();
this._instance.xterm?.clearActiveSearchDecoration();
this._findWidgetFocused.reset();
}
Expand Down

0 comments on commit b07c5df

Please sign in to comment.