@@ -4,6 +4,7 @@ import * as os from 'os';
44import * as path from 'path' ;
55import * as fs from 'fs' ;
66import * as child_process from 'child_process' ;
7+ import * as process from 'process' ;
78import * as cs from './cs' ;
89var recursive_copy = require ( 'recursive-copy' ) ;
910var 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