Skip to content

Commit 079844c

Browse files
committed
Support Snap installation of VSCode on Linux
1 parent 137588b commit 079844c

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var codeSync: cs.CodeSync;
1010
export async function activate(context: vscode.ExtensionContext) {
1111
logger = new Logger('extension');
1212
codeSync = new cs.CodeSync(cs.vsCodeExtensionDir, cs.codeSyncExtensionDir, '');
13+
helpers.isCodeASnapPackage(true);
1314
codeSync.CanManageExtensions = helpers.isCodeOnPath();
1415
if (!codeSync.CanManageExtensions) {
1516
await vscode.window.showWarningMessage(helpers.getCodePathWarningMessage());

src/helpers.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as os from 'os';
44
import * as path from 'path';
55
import * as fs from 'fs';
66
import * as child_process from 'child_process';
7+
import * as process from 'process';
78
import * as cs from './cs';
89
var recursive_copy = require('recursive-copy');
910
var mkdirp = require('mkdirp');
@@ -148,16 +149,58 @@ export function logError(err: Error): void {
148149
logger.appendLine(`\tStacktrace: ${err.stack}`);
149150
}
150151

151-
function getCodeCommand(): string {
152+
function getCodeString(): string {
152153
let codeString: string = 'code';
153154
if (isInsiders()) {
154155
codeString = 'code-insiders';
155156
}
157+
return codeString;
158+
}
159+
160+
interface SnapPackageResult {
161+
value: boolean,
162+
path: string
163+
}
164+
165+
export function isCodeASnapPackage(log: boolean = false): SnapPackageResult {
166+
let codeString = getCodeString();
167+
168+
if (linux) {
169+
const env = process.env;
170+
if ('SNAP' in env) {
171+
// VSCode has been installed through Snap so we need to invoke the code binary directly
172+
let codePath = path.join(env['SNAP'], 'usr/share/code/bin', codeString);
173+
if (log) {
174+
logger.appendLine(`Code appears to be running through Snap. Using following as Code path: ${codePath}`);
175+
}
176+
return {
177+
value: true,
178+
path: codePath
179+
};
180+
}
181+
} else {
182+
return {
183+
value: false,
184+
path: null
185+
};
186+
}
187+
}
188+
189+
function getCodeCommand(): string {
190+
let codeString = getCodeString();
156191

157192
if (windows) {
158193
return `${codeString}.cmd`;
159-
}
160-
else {
194+
} else if (osx) {
195+
return codeString;
196+
} else if (linux) {
197+
let result = isCodeASnapPackage();
198+
if (result.value) {
199+
return result.path;
200+
} else {
201+
return codeString;
202+
}
203+
} else {
161204
return codeString;
162205
}
163206
}

0 commit comments

Comments
 (0)