Skip to content

Commit

Permalink
Uses actual exec path as editor command
Browse files Browse the repository at this point in the history
  • Loading branch information
nzaytsev committed Feb 3, 2025
1 parent 06f8cf2 commit 741e7bb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
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 @@ import type {
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 findOrOpenEditors(uris: Uri[], options?: TextDocumentShowOptions
}

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');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.
return `${escapedExecPath} --wait --reuse-window`;
}

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

0 comments on commit 741e7bb

Please sign in to comment.