Skip to content

Commit 741e7bb

Browse files
committed
Uses actual exec path as editor command
1 parent 06f8cf2 commit 741e7bb

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

src/env/browser/execPath.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getExecPath(): string {
2+
throw new Error('Cannot get exec path from webview context');
3+
}

src/env/node/execPath.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { resolve } from 'path';
2+
import { env } from 'vscode';
3+
import { getPlatform } from './platform';
4+
5+
export function getExecPath(): string {
6+
if (env.appHost !== 'desktop') {
7+
throw new Error('Cannot get exec path for not desktop runtime');
8+
}
9+
switch (getPlatform()) {
10+
case 'windows':
11+
// tested with vscode portable (from zip) https://code.visualstudio.com/docs/editor/portable#_enable-portable-mode
12+
return resolve(env.appRoot, '../../bin/code').replace(/\\/g, '/');
13+
case 'linux':
14+
return resolve(env.appRoot, '../../bin/code');
15+
case 'macOS':
16+
return resolve(env.appRoot, 'bin/code');
17+
default:
18+
break;
19+
}
20+
switch (env.appName) {
21+
case 'Visual Studio Code - Insiders':
22+
return 'code-insiders';
23+
case 'Visual Studio Code - Exploration':
24+
return 'code-exploration';
25+
case 'VSCodium':
26+
return 'codium';
27+
case 'Cursor':
28+
return 'cursor';
29+
default:
30+
return 'code';
31+
}
32+
}

src/env/node/platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const isLinux = platform === 'linux';
99
export const isMac = platform === 'darwin';
1010
export const isWindows = platform === 'win32';
1111

12-
export function getPlatform(): string {
12+
export function getPlatform(): 'windows' | 'macOS' | 'linux' | 'web' | 'unknown' {
1313
if (isWindows) return 'windows';
1414
if (isMac) return 'macOS';
1515
if (isLinux) return 'linux';

src/system/-webview/vscode.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
WorkspaceFolder,
99
} from 'vscode';
1010
import { version as codeVersion, ColorThemeKind, env, Uri, ViewColumn, window, workspace } from 'vscode';
11+
import { getExecPath } from '@env/execPath';
1112
import type { IconPath } from '../../@types/vscode.iconpath';
1213
import { imageMimetypes, Schemes, trackableSchemes } from '../../constants';
1314
import type { Container } from '../../container';
@@ -71,25 +72,8 @@ export function findOrOpenEditors(uris: Uri[], options?: TextDocumentShowOptions
7172
}
7273

7374
export function getEditorCommand(): string {
74-
let editor;
75-
switch (env.appName) {
76-
case 'Visual Studio Code - Insiders':
77-
editor = 'code-insiders --wait --reuse-window';
78-
break;
79-
case 'Visual Studio Code - Exploration':
80-
editor = 'code-exploration --wait --reuse-window';
81-
break;
82-
case 'VSCodium':
83-
editor = 'codium --wait --reuse-window';
84-
break;
85-
case 'Cursor':
86-
editor = 'cursor --wait --reuse-window';
87-
break;
88-
default:
89-
editor = 'code --wait --reuse-window';
90-
break;
91-
}
92-
return editor;
75+
const escapedExecPath = getExecPath().replace(/([ ()])/gm, '\\$1');
76+
return `${escapedExecPath} --wait --reuse-window`;
9377
}
9478

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

0 commit comments

Comments
 (0)