]> gitweb.factorcode.org Git - factor.git/commitdiff
editors.visual-studio-code: try and simplify.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 14 Nov 2020 19:10:41 +0000 (11:10 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 14 Nov 2020 19:10:41 +0000 (11:10 -0800)
multi-methods might be more expressive, but this is easier to read
with current syntax.

basis/editors/visual-studio-code-insiders/visual-studio-code-insiders.factor
basis/editors/visual-studio-code/visual-studio-code.factor

index 78e50cfc85e74de51c57a2336c1f377f794d2c76..deffec04829a10c03336d32a8264b6d95a9dd748 100644 (file)
@@ -1,6 +1,20 @@
 ! Copyright (C) 2020 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: editors editors.visual-studio-code namespaces ;
+USING: combinators editors editors.visual-studio-code
+io.pathnames io.standard-paths kernel namespaces system
+tools.which ;
 IN: editors.visual-studio-code-insiders
 
-visual-studio-code-insiders editor-class set-global
+TUPLE: visual-studio-code-insiders < visual-studio-code ;
+
+T{ visual-studio-code-insiders } editor-class set-global
+
+M: visual-studio-code-insiders find-visual-studio-code-path
+    os {
+        { linux [ "code-insiders" which ] }
+        { macosx [
+            "com.microsoft.VSCodeInsiders" find-native-bundle
+            [ "Contents/MacOS/Electron" append-path ] [ f ] if* ] }
+        { windows [
+            { "Microsoft VS Code Insiders" } "code-insiders.cmd" find-in-applications ] }
+    } case ;
index ab9c1e64b04838c875c3daa7b1e2a5db7b6a6dca..45c819c2e89961ffe6a796854ce04b76715cade8 100644 (file)
@@ -1,56 +1,42 @@
 ! Copyright (C) 2015 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators.short-circuit editors
+USING: combinators combinators.short-circuit editors
 generalizations io.files io.pathnames io.standard-paths kernel
-make math.parser memoize namespaces sequences system tools.which ;
+make math.parser namespaces sequences system tools.which ;
 IN: editors.visual-studio-code
 
 ! Command line arguments
 ! https://code.visualstudio.com/docs/editor/command-line
 
-SINGLETONS: visual-studio-code visual-studio-code-insiders ;
-visual-studio-code editor-class set-global
-
-HOOK: find-visual-studio-code-invocation os ( -- array )
-
-: visual-studio-code-invocation ( -- array )
+TUPLE:  visual-studio-code ;
+T{ visual-studio-code } editor-class set-global
+
+HOOK: find-visual-studio-code-path editor-class ( -- path )
+
+M: visual-studio-code find-visual-studio-code-path
+    os {
+        { linux [
+            {
+                [ "code" which ]
+                [ "Code" which ]
+                [ home "VSCode-linux-x64/Code" append-path ]
+                [ "/usr/share/code/code" ]
+            } [ dup exists? [ drop f ] unless ] map-compose 0|| ] }
+        { macosx [
+            "com.microsoft.VSCode" find-native-bundle
+            [ "Contents/MacOS/Electron" append-path ] [ f ] if* ] }
+        { windows [ "code.cmd" ] }
+    } case ;
+
+: visual-studio-code-invocation ( -- path )
     {
         [ \ visual-studio-code-invocation get ]
-        [ find-visual-studio-code-invocation ]
+        [ find-visual-studio-code-path ]
         [ "code" ]
     } 0|| ;
 
-M: macosx find-visual-studio-code-invocation
-    editor-class get visual-studio-code-insiders =
-    { "com.microsoft.VSCodeInsiders" }
-    { "com.microsoft.VSCode" }
-    ? [ find-native-bundle ] map-find drop [
-        "Contents/MacOS/Electron" append-path
-    ] [
-        f
-    ] if* ;
-
 ERROR: can't-find-visual-studio-code ;
 
-M: linux find-visual-studio-code-invocation
-    editor-class get visual-studio-code-insiders = [
-        "code-insiders" which
-    ] [
-        {
-            [ "code" which ]
-            [ "Code" which ]
-            [ home "VSCode-linux-x64/Code" append-path ]
-            [ "/usr/share/code/code" ]
-        } [ dup exists? [ drop f ] unless ] map-compose 0||
-    ] if ;
-
-M: windows find-visual-studio-code-invocation
-    editor-class get visual-studio-code-insiders = [
-        { "Microsoft VS Code Insiders" } "code-insiders.cmd" find-in-applications
-    ] [
-        "code.cmd"
-    ] if ;
-
 : visual-studio-code-editor-command ( file line -- seq )
     [
         visual-studio-code-invocation
@@ -61,6 +47,3 @@ M: windows find-visual-studio-code-invocation
 
 M: visual-studio-code editor-command
     visual-studio-code-editor-command ;
-
-M: visual-studio-code-insiders editor-command
-    visual-studio-code-editor-command ;
\ No newline at end of file