未验证 提交 185cd700 编写于 作者: M Megan Rogge

improve empty workpsace handling

上级 152413e0
...@@ -572,6 +572,8 @@ export interface ITerminalInstance { ...@@ -572,6 +572,8 @@ export interface ITerminalInstance {
readonly navigationMode: INavigationMode | undefined; readonly navigationMode: INavigationMode | undefined;
description: string | undefined; description: string | undefined;
userHome: string | undefined
/** /**
* Shows the environment information hover if the widget exists. * Shows the environment information hover if the widget exists.
*/ */
......
...@@ -70,6 +70,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic ...@@ -70,6 +70,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput'; import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
import { isSafari } from 'vs/base/browser/browser'; import { isSafari } from 'vs/base/browser/browser';
import { ISeparator, template } from 'vs/base/common/labels'; import { ISeparator, template } from 'vs/base/common/labels';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
// How long in milliseconds should an average frame take to render for a notification to appear // How long in milliseconds should an average frame take to render for a notification to appear
// which suggests the fallback DOM-based renderer // which suggests the fallback DOM-based renderer
...@@ -175,6 +176,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { ...@@ -175,6 +176,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _staticTitle?: string; private _staticTitle?: string;
private _workspaceFolder?: string; private _workspaceFolder?: string;
private _labelComputer?: TerminalLabelComputer; private _labelComputer?: TerminalLabelComputer;
private _userHome?: string;
target?: TerminalLocation; target?: TerminalLocation;
get instanceId(): number { return this._instanceId; } get instanceId(): number { return this._instanceId; }
...@@ -231,6 +233,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { ...@@ -231,6 +233,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
get initialCwd(): string | undefined { return this._initialCwd; } get initialCwd(): string | undefined { return this._initialCwd; }
get capabilities(): ProcessCapability[] { return this._capabilities; } get capabilities(): ProcessCapability[] { return this._capabilities; }
get description(): string | undefined { return this._description || this.shellLaunchConfig.description; } get description(): string | undefined { return this._description || this.shellLaunchConfig.description; }
get userHome(): string | undefined { return this._userHome; }
// The onExit event is special in that it fires and is disposed after the terminal instance // The onExit event is special in that it fires and is disposed after the terminal instance
// itself is disposed // itself is disposed
private readonly _onExit = new Emitter<number | undefined>(); private readonly _onExit = new Emitter<number | undefined>();
...@@ -278,6 +281,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { ...@@ -278,6 +281,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
resource: URI | undefined, resource: URI | undefined,
@ITerminalInstanceService private readonly _terminalInstanceService: ITerminalInstanceService, @ITerminalInstanceService private readonly _terminalInstanceService: ITerminalInstanceService,
@ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService, @ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService,
@IPathService private readonly _pathService: IPathService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService, @IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IKeybindingService private readonly _keybindingService: IKeybindingService, @IKeybindingService private readonly _keybindingService: IKeybindingService,
@INotificationService private readonly _notificationService: INotificationService, @INotificationService private readonly _notificationService: INotificationService,
...@@ -693,7 +697,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { ...@@ -693,7 +697,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._xtermTypeAhead = this._register(this._instantiationService.createInstance(TypeAheadAddon, this._processManager, this._configHelper)); this._xtermTypeAhead = this._register(this._instantiationService.createInstance(TypeAheadAddon, this._processManager, this._configHelper));
this._xterm.loadAddon(this._xtermTypeAhead); this._xterm.loadAddon(this._xtermTypeAhead);
this._userHome = (await this._pathService.userHome()).fsPath;
return xterm; return xterm;
} }
...@@ -1748,7 +1752,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { ...@@ -1748,7 +1752,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
if (this._isVisible) { if (this._isVisible) {
// HACK: Force the renderer to unpause by simulating an IntersectionObserver event. // HACK: Force the renderer to unpause by simulating an IntersectionObserver event.
// This is to fix an issue where dragging the window to the top of the screen to // This is to fix an issue where dragging the windpow to the top of the screen to
// maximize on Windows/Linux would fire an event saying that the terminal was not // maximize on Windows/Linux would fire an event saying that the terminal was not
// visible. // visible.
if (this._xterm.getOption('rendererType') === 'canvas') { if (this._xterm.getOption('rendererType') === 'canvas') {
...@@ -2284,7 +2288,7 @@ export class TerminalLabelComputer extends Disposable { ...@@ -2284,7 +2288,7 @@ export class TerminalLabelComputer extends Disposable {
readonly onDidChangeLabel = this._onDidChangeLabel.event; readonly onDidChangeLabel = this._onDidChangeLabel.event;
constructor( constructor(
private readonly _configHelper: TerminalConfigHelper, private readonly _configHelper: TerminalConfigHelper,
private readonly _instance: Pick<ITerminalInstance, 'shellLaunchConfig' | 'cwd' | 'initialCwd' | 'processName' | 'sequence' | 'workspaceFolder' | 'staticTitle' | 'capabilities' | 'title' | 'description'>, private readonly _instance: Pick<ITerminalInstance, 'shellLaunchConfig' | 'cwd' | 'initialCwd' | 'processName' | 'sequence' | 'userHome' | 'workspaceFolder' | 'staticTitle' | 'capabilities' | 'title' | 'description'>,
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService @IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService
) { ) {
super(); super();
...@@ -2317,14 +2321,11 @@ export class TerminalLabelComputer extends Disposable { ...@@ -2317,14 +2321,11 @@ export class TerminalLabelComputer extends Disposable {
if (this._instance.staticTitle && labelType === TerminalLabelType.Title) { if (this._instance.staticTitle && labelType === TerminalLabelType.Title) {
return this._instance.staticTitle.replace(/[\n\r\t]/g, '') || templateProperties.process?.replace(/[\n\r\t]/g, '') || ''; return this._instance.staticTitle.replace(/[\n\r\t]/g, '') || templateProperties.process?.replace(/[\n\r\t]/g, '') || '';
} }
const detection = this._instance.capabilities.includes(ProcessCapability.CwdDetection);
const zeroRootWorkspace = this._workspaceContextService.getWorkspace().folders.length === 0 && templateProperties.cwd === (this._instance.userHome || this._configHelper.config.cwd);
const singleRootWorkspace = this._workspaceContextService.getWorkspace().folders.length === 1 && templateProperties.cwd === (this._configHelper.config.cwd || this._workspaceContextService.getWorkspace().folders[0]?.uri.fsPath);
templateProperties.cwdFolder = (!templateProperties.cwd || !detection || zeroRootWorkspace || singleRootWorkspace) ? '' : path.basename(templateProperties.cwd);
if (!templateProperties.cwd || !this._instance.capabilities.includes(ProcessCapability.CwdDetection) ||
(this._workspaceContextService.getWorkspace().folders.length <= 1 &&
(templateProperties.cwd === (this._configHelper.config.cwd || (this._workspaceContextService.getWorkspace().folders[0].uri.fsPath))))) {
templateProperties.cwdFolder = '';
} else if (templateProperties.cwd && typeof templateProperties.cwd === 'string') {
templateProperties.cwdFolder = path.basename(templateProperties.cwd);
}
//Remove special characters that could mess with rendering //Remove special characters that could mess with rendering
const label = template(labelTemplate, (templateProperties as unknown) as { [key: string]: string | ISeparator | undefined | null; }).replace(/[\n\r\t]/g, ''); const label = template(labelTemplate, (templateProperties as unknown) as { [key: string]: string | ISeparator | undefined | null; }).replace(/[\n\r\t]/g, '');
return label === '' && labelType === TerminalLabelType.Title ? (this._instance.processName || '') : label; return label === '' && labelType === TerminalLabelType.Title ? (this._instance.processName || '') : label;
......
...@@ -17,7 +17,7 @@ import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/term ...@@ -17,7 +17,7 @@ import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/term
import { ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal'; import { ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
import { basename } from 'path'; import { basename } from 'path';
function createInstance(partial?: Partial<ITerminalInstance>): Pick<ITerminalInstance, 'shellLaunchConfig' | 'cwd' | 'initialCwd' | 'processName' | 'sequence' | 'workspaceFolder' | 'staticTitle' | 'capabilities' | 'title' | 'description'> { function createInstance(partial?: Partial<ITerminalInstance>): Pick<ITerminalInstance, 'shellLaunchConfig' | 'userHome' | 'cwd' | 'initialCwd' | 'processName' | 'sequence' | 'workspaceFolder' | 'staticTitle' | 'capabilities' | 'title' | 'description'> {
return { return {
shellLaunchConfig: {}, shellLaunchConfig: {},
cwd: 'cwd', cwd: 'cwd',
...@@ -29,6 +29,7 @@ function createInstance(partial?: Partial<ITerminalInstance>): Pick<ITerminalIns ...@@ -29,6 +29,7 @@ function createInstance(partial?: Partial<ITerminalInstance>): Pick<ITerminalIns
capabilities: isWindows ? [] : [ProcessCapability.CwdDetection], capabilities: isWindows ? [] : [ProcessCapability.CwdDetection],
title: '', title: '',
description: '', description: '',
userHome: undefined,
...partial ...partial
}; };
} }
...@@ -183,6 +184,7 @@ suite('Workbench - TerminalInstance', () => { ...@@ -183,6 +184,7 @@ suite('Workbench - TerminalInstance', () => {
strictEqual(terminalLabelComputer.description, 'root2'); strictEqual(terminalLabelComputer.description, 'root2');
} }
}); });
//TODO: enable and test userHome
test.skip('should hide cwdFolder in empty workspaces when cwd matches the workspace\'s default cwd ($HOME or $HOMEDRIVE$HOMEPATH)', async () => { test.skip('should hide cwdFolder in empty workspaces when cwd matches the workspace\'s default cwd ($HOME or $HOMEDRIVE$HOMEPATH)', async () => {
configurationService = new TestConfigurationService({ terminal: { integrated: { tabs: { separator: ' ~ ', title: '${process}${separator}${cwdFolder}', description: '${cwdFolder}' } }, cwd: ROOT_1 } }); configurationService = new TestConfigurationService({ terminal: { integrated: { tabs: { separator: ' ~ ', title: '${process}${separator}${cwdFolder}', description: '${cwdFolder}' } }, cwd: ROOT_1 } });
configHelper = new TerminalConfigHelper(configurationService, null!, null!, null!, null!, null!); configHelper = new TerminalConfigHelper(configurationService, null!, null!, null!, null!, null!);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册