Ensure external terminal cwd is a local path, use canonical
Fixes #100815
This commit is contained in:
parent
08e5cccb11
commit
fc528bc5c1
3 changed files with 44 additions and 16 deletions
|
@ -22,7 +22,7 @@ export interface ITerminalForPlatform {
|
|||
|
||||
export interface IExternalTerminalService {
|
||||
readonly _serviceBrand: undefined;
|
||||
openTerminal(configuration: IExternalTerminalSettings, path: string): Promise<void>;
|
||||
openTerminal(configuration: IExternalTerminalSettings, cwd: string | undefined): Promise<void>;
|
||||
runInTerminal(title: string, cwd: string, args: string[], env: ITerminalEnvironment, settings: IExternalTerminalSettings): Promise<number | undefined>;
|
||||
getDefaultTerminalForPlatforms(): Promise<ITerminalForPlatform>;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,11 @@ abstract class ExternalTerminalService {
|
|||
public _serviceBrand: undefined;
|
||||
|
||||
async getDefaultTerminalForPlatforms(): Promise<ITerminalForPlatform> {
|
||||
const linuxTerminal = await LinuxExternalTerminalService.getDefaultTerminalLinuxReady();
|
||||
return { windows: WindowsExternalTerminalService.getDefaultTerminalWindows(), linux: linuxTerminal, osx: 'xterm' };
|
||||
return {
|
||||
windows: WindowsExternalTerminalService.getDefaultTerminalWindows(),
|
||||
linux: await LinuxExternalTerminalService.getDefaultTerminalLinuxReady(),
|
||||
osx: 'xterm'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,13 @@ import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
|
|||
import { IHistoryService } from 'vs/workbench/services/history/common/history';
|
||||
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { IPathService } from 'vs/workbench/services/path/common/pathService';
|
||||
import { IConfigurationRegistry, Extensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
||||
import { IExternalTerminalMainService } from 'vs/platform/externalTerminal/electron-sandbox/externalTerminalMainService';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
|
||||
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
|
||||
|
||||
const OPEN_NATIVE_CONSOLE_COMMAND_ID = 'workbench.action.terminal.openNativeConsole';
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
|
@ -30,21 +30,46 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
|
|||
// Open external terminal in local workspaces
|
||||
const terminalService = accessor.get(IExternalTerminalService);
|
||||
const configurationService = accessor.get(IConfigurationService);
|
||||
const root = historyService.getLastActiveWorkspaceRoot(Schemas.file);
|
||||
const remoteAuthorityResolverService = accessor.get(IRemoteAuthorityResolverService);
|
||||
const root = historyService.getLastActiveWorkspaceRoot();
|
||||
const config = configurationService.getValue<IExternalTerminalSettings>('terminal.external');
|
||||
if (root) {
|
||||
|
||||
// It's a local workspace, open the root
|
||||
if (root?.scheme === Schemas.file) {
|
||||
terminalService.openTerminal(config, root.fsPath);
|
||||
} else {
|
||||
// Opens current file's folder, if no folder is open in editor
|
||||
const activeFile = historyService.getLastActiveFile(Schemas.file);
|
||||
if (activeFile) {
|
||||
terminalService.openTerminal(config, paths.dirname(activeFile.fsPath));
|
||||
} else {
|
||||
const pathService = accessor.get(IPathService);
|
||||
const userHome = await pathService.userHome();
|
||||
terminalService.openTerminal(config, userHome.fsPath);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If it's a remote workspace, open the canonical URI if it is a local folder
|
||||
try {
|
||||
if (root?.scheme === Schemas.vscodeRemote) {
|
||||
const canonicalUri = await remoteAuthorityResolverService.getCanonicalURI(root);
|
||||
if (canonicalUri.scheme === Schemas.file) {
|
||||
terminalService.openTerminal(config, canonicalUri.fsPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch { }
|
||||
|
||||
// Open the current file's folder if it's local or its canonical URI is local
|
||||
// Opens current file's folder, if no folder is open in editor
|
||||
const activeFile = historyService.getLastActiveFile(Schemas.file);
|
||||
if (activeFile?.scheme === Schemas.file) {
|
||||
terminalService.openTerminal(config, paths.dirname(activeFile.fsPath));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (activeFile?.scheme === Schemas.vscodeRemote) {
|
||||
const canonicalUri = await remoteAuthorityResolverService.getCanonicalURI(activeFile);
|
||||
if (canonicalUri.scheme === Schemas.file) {
|
||||
terminalService.openTerminal(config, canonicalUri.fsPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch { }
|
||||
|
||||
// Fallback to opening without a cwd which will end up using the local home path
|
||||
terminalService.openTerminal(config, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue