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