diff --git a/modules/mono/editor/GodotTools/GodotTools/ExternalEditorId.cs b/modules/mono/editor/GodotTools/GodotTools/ExternalEditorId.cs index 049cc58512b..ba52380357b 100644 --- a/modules/mono/editor/GodotTools/GodotTools/ExternalEditorId.cs +++ b/modules/mono/editor/GodotTools/GodotTools/ExternalEditorId.cs @@ -8,6 +8,7 @@ namespace GodotTools MonoDevelop, VsCode, Rider, - CustomEditor + CustomEditor, + Fleet, } } diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index e1dc1be9794..50aa6811b0b 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -286,9 +286,10 @@ namespace GodotTools case ExternalEditorId.VisualStudioForMac: goto case ExternalEditorId.MonoDevelop; case ExternalEditorId.Rider: + case ExternalEditorId.Fleet: { string scriptPath = ProjectSettings.GlobalizePath(script.ResourcePath); - RiderPathManager.OpenFile(GodotSharpDirs.ProjectSlnPath, scriptPath, line + 1, col); + RiderPathManager.OpenFile(editorId, GodotSharpDirs.ProjectSlnPath, scriptPath, line + 1, col); return Error.Ok; } case ExternalEditorId.MonoDevelop: @@ -568,7 +569,8 @@ namespace GodotTools settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudio}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" + - $",JetBrains Rider and Fleet:{(int)ExternalEditorId.Rider}" + + $",JetBrains Rider:{(int)ExternalEditorId.Rider}" + + $",JetBrains Fleet:{(int)ExternalEditorId.Fleet}" + $",Custom:{(int)ExternalEditorId.CustomEditor}"; } else if (OS.IsMacOS) @@ -576,14 +578,16 @@ namespace GodotTools settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" + - $",JetBrains Rider and Fleet:{(int)ExternalEditorId.Rider}" + + $",JetBrains Rider:{(int)ExternalEditorId.Rider}" + + $",JetBrains Fleet:{(int)ExternalEditorId.Fleet}" + $",Custom:{(int)ExternalEditorId.CustomEditor}"; } else if (OS.IsUnixLike) { settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" + - $",JetBrains Rider and Fleet:{(int)ExternalEditorId.Rider}" + + $",JetBrains Rider:{(int)ExternalEditorId.Rider}" + + $",JetBrains Fleet:{(int)ExternalEditorId.Fleet}" + $",Custom:{(int)ExternalEditorId.CustomEditor}"; } @@ -640,7 +644,6 @@ namespace GodotTools _inspectorPluginWeak = WeakRef(inspectorPlugin); BuildManager.Initialize(); - RiderPathManager.Initialize(); GodotIdeManager = new GodotIdeManager(); AddChild(GodotIdeManager); @@ -664,13 +667,28 @@ namespace GodotTools private void OnSettingsChanged() { - // We want to force NoConsoleLogging to true when the VerbosityLevel is at Detailed or above. - // At that point, there's so much info logged that it doesn't make sense to display it in - // the tiny editor window, and it'd make the editor hang or crash anyway. - var verbosityLevel = _editorSettings.GetSetting(Settings.VerbosityLevel).As(); - var hideConsoleLog = (bool)_editorSettings.GetSetting(Settings.NoConsoleLogging); - if (verbosityLevel >= VerbosityLevelId.Detailed && !hideConsoleLog) - _editorSettings.SetSetting(Settings.NoConsoleLogging, Variant.From(true)); + var changedSettings = _editorSettings.GetChangedSettings(); + if (changedSettings.Contains(Settings.VerbosityLevel)) + { + // We want to force NoConsoleLogging to true when the VerbosityLevel is at Detailed or above. + // At that point, there's so much info logged that it doesn't make sense to display it in + // the tiny editor window, and it'd make the editor hang or crash anyway. + var verbosityLevel = _editorSettings.GetSetting(Settings.VerbosityLevel).As(); + var hideConsoleLog = (bool)_editorSettings.GetSetting(Settings.NoConsoleLogging); + if (verbosityLevel >= VerbosityLevelId.Detailed && !hideConsoleLog) + _editorSettings.SetSetting(Settings.NoConsoleLogging, Variant.From(true)); + } + + if (changedSettings.Contains(Settings.ExternalEditor) && !changedSettings.Contains(RiderPathManager.EditorPathSettingName)) + { + var editor = _editorSettings.GetSetting(Settings.ExternalEditor).As(); + if (editor != ExternalEditorId.Fleet && editor != ExternalEditorId.Rider) + { + return; + } + + RiderPathManager.InitializeIfNeeded(editor); + } } protected override void Dispose(bool disposing) diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj b/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj index c82da741bd1..e027b7df0cf 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj +++ b/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj @@ -34,7 +34,7 @@ - + diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs index 6563bfbb06c..8456ac3e78b 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs @@ -66,6 +66,8 @@ namespace GodotTools.Ides return "VisualStudioCode"; case ExternalEditorId.Rider: return "Rider"; + case ExternalEditorId.Fleet: + return "Fleet"; case ExternalEditorId.VisualStudioForMac: return "VisualStudioForMac"; case ExternalEditorId.MonoDevelop: @@ -107,6 +109,7 @@ namespace GodotTools.Ides case ExternalEditorId.VisualStudio: case ExternalEditorId.VsCode: case ExternalEditorId.Rider: + case ExternalEditorId.Fleet: case ExternalEditorId.CustomEditor: throw new NotSupportedException(); case ExternalEditorId.VisualStudioForMac: diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs index 5c54d2d9ba8..94a3bc2ab75 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs @@ -9,7 +9,7 @@ namespace GodotTools.Ides.Rider { public static class RiderPathManager { - private const string EditorPathSettingName = "dotnet/editor/editor_path_optional"; + internal const string EditorPathSettingName = "dotnet/editor/editor_path_optional"; private static readonly RiderPathLocator RiderPathLocator; private static readonly RiderFileOpener RiderFileOpener; @@ -32,44 +32,40 @@ namespace GodotTools.Ides.Rider return null; } - public static void Initialize() + public static void InitializeIfNeeded(ExternalEditorId editor) { var editorSettings = EditorInterface.Singleton.GetEditorSettings(); - var editor = editorSettings.GetSetting(GodotSharpEditor.Settings.ExternalEditor).As(); - if (editor == ExternalEditorId.Rider) + if (!editorSettings.HasSetting(EditorPathSettingName)) { - if (!editorSettings.HasSetting(EditorPathSettingName)) + Globals.EditorDef(EditorPathSettingName, ""); + editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary { - Globals.EditorDef(EditorPathSettingName, ""); - editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary - { - ["type"] = (int)Variant.Type.String, - ["name"] = EditorPathSettingName, - ["hint"] = (int)PropertyHint.File, - ["hint_string"] = "" - }); - } - - var riderPath = (string)editorSettings.GetSetting(EditorPathSettingName); - if (File.Exists(riderPath)) - { - Globals.EditorDef(EditorPathSettingName, riderPath); - return; - } - - var paths = RiderPathLocator.GetAllRiderPaths(); - if (paths.Length == 0) - { - return; - } - - string newPath = paths.Last().Path; - Globals.EditorDef(EditorPathSettingName, newPath); - editorSettings.SetSetting(EditorPathSettingName, newPath); + ["type"] = (int)Variant.Type.String, + ["name"] = EditorPathSettingName, + ["hint"] = (int)PropertyHint.File, + ["hint_string"] = "" + }); } + + var editorPath = (string)editorSettings.GetSetting(EditorPathSettingName); + if (File.Exists(editorPath) && IsMatch(editor, editorPath)) + { + Globals.EditorDef(EditorPathSettingName, editorPath); + return; + } + + var paths = RiderPathLocator.GetAllRiderPaths().Where(info => IsMatch(editor, info.Path)).ToArray(); + if (paths.Length == 0) + { + return; + } + + string newPath = paths.Last().Path; + Globals.EditorDef(EditorPathSettingName, newPath); + editorSettings.SetSetting(EditorPathSettingName, newPath); } - public static bool IsRider(string path) + private static bool IsMatch(ExternalEditorId editorId, string path) { if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1) { @@ -77,14 +73,15 @@ namespace GodotTools.Ides.Rider } var fileInfo = new FileInfo(path); - return fileInfo.Name.StartsWith("rider", StringComparison.OrdinalIgnoreCase); + var name = editorId == ExternalEditorId.Fleet ? "fleet" : "rider"; + return fileInfo.Name.StartsWith(name, StringComparison.OrdinalIgnoreCase); } - private static string? CheckAndUpdatePath(string? riderPath) + private static string? CheckAndUpdatePath(ExternalEditorId editorId, string? idePath) { - if (File.Exists(riderPath)) + if (File.Exists(idePath)) { - return riderPath; + return idePath; } var allInfos = RiderPathLocator.GetAllRiderPaths(); @@ -93,9 +90,13 @@ namespace GodotTools.Ides.Rider return null; } - // RiderPathLocator includes Rider and Fleet locations, prefer Rider when available. - var preferredInfo = allInfos.LastOrDefault(info => IsRider(info.Path), allInfos[allInfos.Length - 1]); - string newPath = preferredInfo.Path; + // RiderPathLocator includes Rider and Fleet locations. + var matchingIde = allInfos.LastOrDefault(info => IsMatch(editorId, info.Path)); + var newPath = matchingIde.Path; + if (string.IsNullOrEmpty(newPath)) + { + return null; + } var editorSettings = EditorInterface.Singleton.GetEditorSettings(); editorSettings.SetSetting(EditorPathSettingName, newPath); @@ -103,10 +104,10 @@ namespace GodotTools.Ides.Rider return newPath; } - public static void OpenFile(string slnPath, string scriptPath, int line, int column) + public static void OpenFile(ExternalEditorId editorId, string slnPath, string scriptPath, int line, int column) { - string? pathFromSettings = GetRiderPathFromSettings(); - string? path = CheckAndUpdatePath(pathFromSettings); + var pathFromSettings = GetRiderPathFromSettings(); + var path = CheckAndUpdatePath(editorId, pathFromSettings); if (string.IsNullOrEmpty(path)) { GD.PushError($"Error when trying to run code editor: JetBrains Rider or Fleet. Could not find path to the editor.");