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