]> gitweb.factorcode.org Git - factor.git/blob - basis/editors/visual-studio-code/visual-studio-code.factor
5ac6c00bfd3e58cd0c864d3f2591cf27d2d09c66
[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.short-circuit editors
4 generalizations io.files io.pathnames io.standard-paths kernel
5 make math.parser memoize 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 visual-studio-code editor-class set-global
13
14 HOOK: find-visual-studio-code-invocation os ( -- array )
15
16 : visual-studio-code-invocation ( -- array )
17     {
18         [ \ visual-studio-code-invocation get ]
19         [ find-visual-studio-code-invocation ]
20         [ "code" ]
21     } 0|| ;
22
23 M: macosx find-visual-studio-code-invocation
24     "com.microsoft.VSCode" find-native-bundle [
25         "Contents/MacOS/Electron" append-path
26     ] [
27         f
28     ] if* ;
29
30 ERROR: can't-find-visual-studio-code ;
31
32 M: linux find-visual-studio-code-invocation
33     {
34         [ "code" which ]
35         [ "Code" which ]
36         [ home "VSCode-linux-x64/Code" append-path ]
37         [ "/usr/share/code/code" ]
38     } [ dup exists? [ drop f ] unless ] map-compose 0|| ;
39
40 M: windows find-visual-studio-code-invocation
41     {
42         [ { "Microsoft VS Code" } "code.exe" find-in-applications ]
43         [ "code.cmd" ]
44     } 0|| ;
45
46 M: visual-studio-code editor-command ( file line -- command )
47     [
48         visual-studio-code-invocation
49         [ , ] [ can't-find-visual-studio-code ] if*
50         "-g" , "-r" ,
51         number>string ":" glue ,
52     ] { } make ;