Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/env/browser/execPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getExecPath(): string {
throw new Error('Cannot get exec path from webview context');
}
32 changes: 32 additions & 0 deletions src/env/node/execPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { resolve } from 'path';
import { env } from 'vscode';
import { getPlatform } from './platform';

export function getExecPath(): string {
if (env.appHost !== 'desktop') {
throw new Error('Cannot get exec path for not desktop runtime');
}
switch (getPlatform()) {
case 'windows':
// tested with vscode portable (from zip) https://code.visualstudio.com/docs/editor/portable#_enable-portable-mode
return resolve(env.appRoot, '../../bin/code').replace(/\\/g, '/');
case 'linux':
return resolve(env.appRoot, '../../bin/code');
case 'macOS':
return resolve(env.appRoot, 'bin/code');
default:
break;
}
switch (env.appName) {
case 'Visual Studio Code - Insiders':
return 'code-insiders';
case 'Visual Studio Code - Exploration':
return 'code-exploration';
case 'VSCodium':
return 'codium';
case 'Cursor':
return 'cursor';
default:
return 'code';
}
}
2 changes: 1 addition & 1 deletion src/env/node/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const isLinux = platform === 'linux';
export const isMac = platform === 'darwin';
export const isWindows = platform === 'win32';

export function getPlatform(): string {
export function getPlatform(): 'windows' | 'macOS' | 'linux' | 'web' | 'unknown' {
if (isWindows) return 'windows';
if (isMac) return 'macOS';
if (isLinux) return 'linux';
Expand Down
22 changes: 3 additions & 19 deletions src/system/-webview/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
WorkspaceFolder,
} from 'vscode';
import { version as codeVersion, ColorThemeKind, env, Uri, ViewColumn, window, workspace } from 'vscode';
import { getExecPath } from '@env/execPath';
import type { IconPath } from '../../@types/vscode.iconpath';
import { imageMimetypes, Schemes, trackableSchemes } from '../../constants';
import type { Container } from '../../container';
Expand Down Expand Up @@ -71,25 +72,8 @@
}

export function getEditorCommand(): string {
let editor;
switch (env.appName) {
case 'Visual Studio Code - Insiders':
editor = 'code-insiders --wait --reuse-window';
break;
case 'Visual Studio Code - Exploration':
editor = 'code-exploration --wait --reuse-window';
break;
case 'VSCodium':
editor = 'codium --wait --reuse-window';
break;
case 'Cursor':
editor = 'cursor --wait --reuse-window';
break;
default:
editor = 'code --wait --reuse-window';
break;
}
return editor;
const escapedExecPath = getExecPath().replace(/([ ()])/gm, '\\$1');
return `${escapedExecPath} --wait --reuse-window`;
}

export function getEditorIfActive(document: TextDocument): TextEditor | undefined {
Expand Down