]> gitweb.factorcode.org Git - factor.git/blob - basis/editors/visual-studio-code/visual-studio-code.factor
56d4f5a76b7b604d197c95b72110a1baf1e1ad61
[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.VSCodeInsiders" "com.microsoft.VSCode" }
25     [ find-native-bundle ] map-find drop [
26         "Contents/MacOS/Electron" append-path
27     ] [
28         f
29     ] if* ;
30
31 ERROR: can't-find-visual-studio-code ;
32
33 M: linux find-visual-studio-code-invocation
34     {
35         [ "code-insiders" which ]
36         [ "code" which ]
37         [ "Code" which ]
38         [ home "VSCode-linux-x64/Code" append-path ]
39         [ "/usr/share/code/code" ]
40     } [ dup exists? [ drop f ] unless ] map-compose 0|| ;
41
42 M: windows find-visual-studio-code-invocation
43     {
44         [ { "Microsoft VS Code Insiders" } "code-insiders.cmd" find-in-applications ]
45         [ "code.cmd" ]
46     } 0|| ;
47
48 M: visual-studio-code editor-command ( file line -- command )
49     [
50         visual-studio-code-invocation
51         [ , ] [ can't-find-visual-studio-code ] if*
52         "-g" , "-r" ,
53         number>string ":" glue ,
54     ] { } make ;