Skip to content

Commit 47f1dfd

Browse files
ziggy42shiftkey
authored andcommittedAug 27, 2020
Detect snap installation of Visual Studio Code on Linux (#156)
1 parent cde7962 commit 47f1dfd

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed
 

‎app/src/lib/editors/linux.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,42 @@ async function getPathIfAvailable(path: string): Promise<string | null> {
4949
return (await pathExists(path)) ? path : null
5050
}
5151

52+
async function getFirstPathIfAvailable(
53+
possiblePaths: string[]
54+
): Promise<string | null> {
55+
for (const possiblePath of possiblePaths) {
56+
const path = await getPathIfAvailable(possiblePath)
57+
if (path) {
58+
return path
59+
}
60+
}
61+
return null
62+
}
63+
5264
async function getEditorPath(editor: ExternalEditor): Promise<string | null> {
5365
switch (editor) {
5466
case ExternalEditor.Atom:
5567
return getPathIfAvailable('/usr/bin/atom')
5668
case ExternalEditor.VSCode:
5769
return getPathIfAvailable('/usr/bin/code')
5870
case ExternalEditor.VSCodeInsiders:
59-
return getPathIfAvailable('/usr/bin/code-insiders')
71+
return getFirstPathIfAvailable([
72+
'/snap/bin/code-insiders',
73+
'/usr/bin/code-insiders',
74+
])
6075
case ExternalEditor.VSCodium:
6176
return getPathIfAvailable('/usr/bin/codium')
6277
case ExternalEditor.SublimeText:
6378
return getPathIfAvailable('/usr/bin/subl')
6479
case ExternalEditor.Typora:
6580
return getPathIfAvailable('/usr/bin/typora')
6681
case ExternalEditor.SlickEdit:
67-
const possiblePaths = [
82+
return getFirstPathIfAvailable([
6883
'/opt/slickedit-pro2018/bin/vs',
6984
'/opt/slickedit-pro2017/bin/vs',
7085
'/opt/slickedit-pro2016/bin/vs',
7186
'/opt/slickedit-pro2015/bin/vs',
72-
]
73-
for (const possiblePath of possiblePaths) {
74-
const slickeditPath = await getPathIfAvailable(possiblePath)
75-
if (slickeditPath) {
76-
return slickeditPath
77-
}
78-
}
79-
return null
87+
])
8088
default:
8189
return assertNever(editor, `Unknown editor: ${editor}`)
8290
}

0 commit comments

Comments
 (0)