소스 검색

Mono: Fix regression: external editors not working on Windows

Ignacio Etcheverry 6 년 전
부모
커밋
c0cdbb7938

+ 10 - 1
modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs

@@ -298,7 +298,16 @@ namespace GodotTools
                     if (line >= 0)
                         scriptPath += $";{line + 1};{col}";
 
-                    GetMonoDevelopInstance(GodotSharpDirs.ProjectSlnPath).Execute(scriptPath);
+                    try
+                    {
+                        GetMonoDevelopInstance(GodotSharpDirs.ProjectSlnPath).Execute(scriptPath);
+                    }
+                    catch (FileNotFoundException)
+                    {
+                        string editorName = editor == ExternalEditor.VisualStudioForMac ? "Visual Studio" : "MonoDevelop";
+                        GD.PushError($"Cannot find code editor: {editorName}");
+                        return Error.FileNotFound;
+                    }
 
                     break;
                 }

+ 13 - 9
modules/mono/editor/GodotTools/GodotTools/MonoDevelopInstance.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Collections.Generic;
 using System.Diagnostics;
 using GodotTools.Internals;
+using GodotTools.Utils;
 
 namespace GodotTools
 {
@@ -30,7 +31,7 @@ namespace GodotTools
 
             if (Utils.OS.IsOSX())
             {
-                string bundleId = CodeEditorBundleIds[editorId];
+                string bundleId = BundleIds[editorId];
 
                 if (Internal.IsOsxAppBundleInstalled(bundleId))
                 {
@@ -47,12 +48,12 @@ namespace GodotTools
                 }
                 else
                 {
-                    command = CodeEditorPaths[editorId];
+                    command = OS.PathWhich(ExecutableNames[editorId]);
                 }
             }
             else
             {
-                command = CodeEditorPaths[editorId];
+                command = OS.PathWhich(ExecutableNames[editorId]);
             }
 
             args.Add("--ipc-tcp");
@@ -70,6 +71,9 @@ namespace GodotTools
                 args.Add("\"" + Path.GetFullPath(filePath.NormalizePath()) + cursor + "\"");
             }
 
+            if (command == null)
+                throw new FileNotFoundException();
+
             if (newWindow)
             {
                 process = Process.Start(new ProcessStartInfo
@@ -99,20 +103,20 @@ namespace GodotTools
             this.editorId = editorId;
         }
 
-        private static readonly IReadOnlyDictionary<EditorId, string> CodeEditorPaths;
-        private static readonly IReadOnlyDictionary<EditorId, string> CodeEditorBundleIds;
+        private static readonly IReadOnlyDictionary<EditorId, string> ExecutableNames;
+        private static readonly IReadOnlyDictionary<EditorId, string> BundleIds;
 
         static MonoDevelopInstance()
         {
             if (Utils.OS.IsOSX())
             {
-                CodeEditorPaths = new Dictionary<EditorId, string>
+                ExecutableNames = new Dictionary<EditorId, string>
                 {
                     // Rely on PATH
                     {EditorId.MonoDevelop, "monodevelop"},
                     {EditorId.VisualStudioForMac, "VisualStudio"}
                 };
-                CodeEditorBundleIds = new Dictionary<EditorId, string>
+                BundleIds = new Dictionary<EditorId, string>
                 {
                     // TODO EditorId.MonoDevelop
                     {EditorId.VisualStudioForMac, "com.microsoft.visual-studio"}
@@ -120,7 +124,7 @@ namespace GodotTools
             }
             else if (Utils.OS.IsWindows())
             {
-                CodeEditorPaths = new Dictionary<EditorId, string>
+                ExecutableNames = new Dictionary<EditorId, string>
                 {
                     // XamarinStudio is no longer a thing, and the latest version is quite old
                     // MonoDevelop is available from source only on Windows. The recommendation
@@ -131,7 +135,7 @@ namespace GodotTools
             }
             else if (Utils.OS.IsUnix())
             {
-                CodeEditorPaths = new Dictionary<EditorId, string>
+                ExecutableNames = new Dictionary<EditorId, string>
                 {
                     // Rely on PATH
                     {EditorId.MonoDevelop, "monodevelop"}

+ 3 - 2
modules/mono/editor/GodotTools/GodotTools/Utils/CollectionExtensions.cs

@@ -10,8 +10,9 @@ namespace GodotTools.Utils
         {
             foreach (T elem in enumerable)
             {
-                if (predicate(elem) != null)
-                    return elem;
+                T result = predicate(elem);
+                if (result != null)
+                    return result;
             }
 
             return orElse;