]> gitweb.factorcode.org Git - factor.git/blob - basis/editors/visual-studio-code/visual-studio-code.factor
867a3c42e6204782e1658ece00392178830dc37b
[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 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
7
8 ! Command line arguments
9 ! https://code.visualstudio.com/docs/editor/command-line
10
11 TUPLE: visual-studio-code ;
12 T{ visual-studio-code } editor-class set-global
13
14 HOOK: find-visual-studio-code-path editor-class ( -- path )
15
16 M: visual-studio-code find-visual-studio-code-path
17     os {
18         { linux [
19             {
20                 [ "code" which ]
21                 [ "Code" which ]
22                 [ "~/VSCode-linux-x64/Code" ]
23                 [ "/usr/share/code/code" ]
24             } [ dup file-exists? [ drop f ] unless ] map-compose 0|| ] }
25         { macosx [
26             "com.microsoft.VSCode" find-native-bundle
27             [ "Contents/MacOS/Electron" append-path ] [ f ] if* ] }
28         { windows [ "code.cmd" ] }
29     } case ;
30
31 : visual-studio-code-invocation ( -- path )
32     {
33         [ \ visual-studio-code-invocation get ]
34         [ find-visual-studio-code-path ]
35         [ "code" ]
36     } 0|| ;
37
38 ERROR: can't-find-visual-studio-code ;
39
40 : visual-studio-code-editor-command ( file line -- seq )
41     [
42         visual-studio-code-invocation
43         [ , ] [ can't-find-visual-studio-code ] if*
44         "-g" , "-r" ,
45         number>string ":" glue ,
46     ] { } make ;
47
48 M: visual-studio-code editor-command
49     visual-studio-code-editor-command ;