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 TUPLE: visual-studio-code ;
13 editor-class [ T{ visual-studio-code } ] initialize
15 HOOK: find-visual-studio-code-path editor-class ( -- path )
17 M: visual-studio-code find-visual-studio-code-path
23 [ "~/VSCode-linux-x64/Code" ]
24 [ "/usr/share/code/code" ]
25 } [ dup file-exists? [ drop f ] unless ] map-compose 0|| ] }
27 "com.microsoft.VSCode" find-native-bundle
28 [ "Contents/MacOS/Electron" append-path ] [ f ] if* ] }
29 { windows [ "code.cmd" ] }
32 : visual-studio-code-invocation ( -- path )
34 [ \ visual-studio-code-invocation get ]
35 [ find-visual-studio-code-path ]
39 ERROR: can't-find-visual-studio-code ;
41 : visual-studio-code-editor-command ( file line -- seq )
43 visual-studio-code-invocation
44 [ , ] [ can't-find-visual-studio-code ] if*
46 number>string ":" glue ,
49 M: visual-studio-code editor-command
50 visual-studio-code-editor-command ;