1 ! Copyright (C) 2015 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators combinators.short-circuit editors
4 generalizations io.files io.pathnames io.standard-paths kernel
5 make math.parser namespaces sequences system tools.which ;
6 IN: editors.visual-studio-code
8 ! Command line arguments
9 ! https://code.visualstudio.com/docs/editor/command-line
11 MIXIN: visual-studio-code-base
13 SINGLETON: visual-studio-code
15 INSTANCE: visual-studio-code visual-studio-code-base
17 editor-class [ visual-studio-code ] initialize
19 HOOK: find-visual-studio-code-path editor-class ( -- path )
21 M: visual-studio-code-base find-visual-studio-code-path
27 [ "~/VSCode-linux-x64/Code" ]
28 [ "/usr/share/code/code" ]
29 } [ dup file-exists? [ drop f ] unless ] map-compose 0|| ] }
31 "com.microsoft.VSCode" find-native-bundle
32 [ "Contents/MacOS/Electron" append-path ] [ f ] if* ] }
33 { windows [ "code.cmd" ] }
36 : visual-studio-code-invocation ( -- path )
38 [ \ visual-studio-code-invocation get ]
39 [ find-visual-studio-code-path ]
43 ERROR: can't-find-visual-studio-code ;
45 : visual-studio-code-editor-command ( file line -- seq )
47 visual-studio-code-invocation
48 [ , ] [ can't-find-visual-studio-code ] if*
50 number>string ":" glue ,
53 M: visual-studio-code-base editor-command
54 visual-studio-code-editor-command ;