]> gitweb.factorcode.org Git - factor.git/blob - basis/editors/visual-studio-code/visual-studio-code.factor
vscode: Prefer code-insiders version if installed.
[factor.git] / basis / editors / visual-studio-code / visual-studio-code.factor
1 ! Copyright (C) 2015 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators.short-circuit editors
4 generalizations io.files io.pathnames io.standard-paths kernel
5 make math.parser memoize namespaces sequences system tools.which ;
6 IN: editors.visual-studio-code
7
8 ! Command line arguments
9 ! https://code.visualstudio.com/docs/editor/command-line
10
11 SINGLETON: visual-studio-code
12 visual-studio-code editor-class set-global
13
14 HOOK: find-visual-studio-code-invocation os ( -- array )
15
16 : visual-studio-code-invocation ( -- array )
17     {
18         [ \ visual-studio-code-invocation get ]
19         [ find-visual-studio-code-invocation ]
20         [ "code" ]
21     } 0|| ;
22
23 M: macosx find-visual-studio-code-invocation
24     "com.microsoft.VSCode" find-native-bundle [
25         "Contents/MacOS/Electron" append-path
26     ] [
27         f
28     ] if* ;
29
30 ERROR: can't-find-visual-studio-code ;
31
32 M: linux find-visual-studio-code-invocation
33     {
34         [ "code-insiders" which ]
35         [ "code" which ]
36         [ "Code" which ]
37         [ home "VSCode-linux-x64/Code" append-path ]
38         [ "/usr/share/code/code" ]
39     } [ dup exists? [ drop f ] unless ] map-compose 0|| ;
40
41 M: windows find-visual-studio-code-invocation
42     {
43         [ { "Microsoft VS Code Insiders" } "code-insiders.cmd" find-in-applications ]
44         [ "code.cmd" ]
45     } 0|| ;
46
47 M: visual-studio-code editor-command ( file line -- command )
48     [
49         visual-studio-code-invocation
50         [ , ] [ can't-find-visual-studio-code ] if*
51         "-g" , "-r" ,
52         number>string ":" glue ,
53     ] { } make ;