Merge pull request #104828 from van800/rider_fleet

C#: Separate Rider and Fleet options as external editors
This commit is contained in:
Thaddeus Crews 2025-04-11 09:51:13 -05:00
commit 98c204a8f0
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
5 changed files with 79 additions and 56 deletions

View file

@ -8,6 +8,7 @@ namespace GodotTools
MonoDevelop, MonoDevelop,
VsCode, VsCode,
Rider, Rider,
CustomEditor CustomEditor,
Fleet,
} }
} }

View file

@ -286,9 +286,10 @@ namespace GodotTools
case ExternalEditorId.VisualStudioForMac: case ExternalEditorId.VisualStudioForMac:
goto case ExternalEditorId.MonoDevelop; goto case ExternalEditorId.MonoDevelop;
case ExternalEditorId.Rider: case ExternalEditorId.Rider:
case ExternalEditorId.Fleet:
{ {
string scriptPath = ProjectSettings.GlobalizePath(script.ResourcePath); 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; return Error.Ok;
} }
case ExternalEditorId.MonoDevelop: case ExternalEditorId.MonoDevelop:
@ -568,7 +569,8 @@ namespace GodotTools
settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudio}" + settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudio}" +
$",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" +
$",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" + $",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}"; $",Custom:{(int)ExternalEditorId.CustomEditor}";
} }
else if (OS.IsMacOS) else if (OS.IsMacOS)
@ -576,14 +578,16 @@ namespace GodotTools
settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" + settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" +
$",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" +
$",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" + $",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}"; $",Custom:{(int)ExternalEditorId.CustomEditor}";
} }
else if (OS.IsUnixLike) else if (OS.IsUnixLike)
{ {
settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" + settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" +
$",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" + $",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}"; $",Custom:{(int)ExternalEditorId.CustomEditor}";
} }
@ -640,7 +644,6 @@ namespace GodotTools
_inspectorPluginWeak = WeakRef(inspectorPlugin); _inspectorPluginWeak = WeakRef(inspectorPlugin);
BuildManager.Initialize(); BuildManager.Initialize();
RiderPathManager.Initialize();
GodotIdeManager = new GodotIdeManager(); GodotIdeManager = new GodotIdeManager();
AddChild(GodotIdeManager); AddChild(GodotIdeManager);
@ -664,13 +667,28 @@ namespace GodotTools
private void OnSettingsChanged() private void OnSettingsChanged()
{ {
// We want to force NoConsoleLogging to true when the VerbosityLevel is at Detailed or above. var changedSettings = _editorSettings.GetChangedSettings();
// At that point, there's so much info logged that it doesn't make sense to display it in if (changedSettings.Contains(Settings.VerbosityLevel))
// the tiny editor window, and it'd make the editor hang or crash anyway. {
var verbosityLevel = _editorSettings.GetSetting(Settings.VerbosityLevel).As<VerbosityLevelId>(); // We want to force NoConsoleLogging to true when the VerbosityLevel is at Detailed or above.
var hideConsoleLog = (bool)_editorSettings.GetSetting(Settings.NoConsoleLogging); // At that point, there's so much info logged that it doesn't make sense to display it in
if (verbosityLevel >= VerbosityLevelId.Detailed && !hideConsoleLog) // the tiny editor window, and it'd make the editor hang or crash anyway.
_editorSettings.SetSetting(Settings.NoConsoleLogging, Variant.From(true)); var verbosityLevel = _editorSettings.GetSetting(Settings.VerbosityLevel).As<VerbosityLevelId>();
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<ExternalEditorId>();
if (editor != ExternalEditorId.Fleet && editor != ExternalEditorId.Rider)
{
return;
}
RiderPathManager.InitializeIfNeeded(editor);
}
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)

View file

@ -34,7 +34,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3.0" ExcludeAssets="runtime" PrivateAssets="all" /> <PackageReference Include="JetBrains.Annotations" Version="2019.1.3.0" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="JetBrains.Rider.PathLocator" Version="1.0.9" /> <PackageReference Include="JetBrains.Rider.PathLocator" Version="1.0.12" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<Reference Include="GodotSharp"> <Reference Include="GodotSharp">

View file

@ -66,6 +66,8 @@ namespace GodotTools.Ides
return "VisualStudioCode"; return "VisualStudioCode";
case ExternalEditorId.Rider: case ExternalEditorId.Rider:
return "Rider"; return "Rider";
case ExternalEditorId.Fleet:
return "Fleet";
case ExternalEditorId.VisualStudioForMac: case ExternalEditorId.VisualStudioForMac:
return "VisualStudioForMac"; return "VisualStudioForMac";
case ExternalEditorId.MonoDevelop: case ExternalEditorId.MonoDevelop:
@ -107,6 +109,7 @@ namespace GodotTools.Ides
case ExternalEditorId.VisualStudio: case ExternalEditorId.VisualStudio:
case ExternalEditorId.VsCode: case ExternalEditorId.VsCode:
case ExternalEditorId.Rider: case ExternalEditorId.Rider:
case ExternalEditorId.Fleet:
case ExternalEditorId.CustomEditor: case ExternalEditorId.CustomEditor:
throw new NotSupportedException(); throw new NotSupportedException();
case ExternalEditorId.VisualStudioForMac: case ExternalEditorId.VisualStudioForMac:

View file

@ -9,7 +9,7 @@ namespace GodotTools.Ides.Rider
{ {
public static class RiderPathManager 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 RiderPathLocator RiderPathLocator;
private static readonly RiderFileOpener RiderFileOpener; private static readonly RiderFileOpener RiderFileOpener;
@ -32,44 +32,40 @@ namespace GodotTools.Ides.Rider
return null; return null;
} }
public static void Initialize() public static void InitializeIfNeeded(ExternalEditorId editor)
{ {
var editorSettings = EditorInterface.Singleton.GetEditorSettings(); var editorSettings = EditorInterface.Singleton.GetEditorSettings();
var editor = editorSettings.GetSetting(GodotSharpEditor.Settings.ExternalEditor).As<ExternalEditorId>(); if (!editorSettings.HasSetting(EditorPathSettingName))
if (editor == ExternalEditorId.Rider)
{ {
if (!editorSettings.HasSetting(EditorPathSettingName)) Globals.EditorDef(EditorPathSettingName, "");
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
{ {
Globals.EditorDef(EditorPathSettingName, ""); ["type"] = (int)Variant.Type.String,
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary ["name"] = EditorPathSettingName,
{ ["hint"] = (int)PropertyHint.File,
["type"] = (int)Variant.Type.String, ["hint_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);
} }
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) if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
{ {
@ -77,14 +73,15 @@ namespace GodotTools.Ides.Rider
} }
var fileInfo = new FileInfo(path); 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(); var allInfos = RiderPathLocator.GetAllRiderPaths();
@ -93,9 +90,13 @@ namespace GodotTools.Ides.Rider
return null; return null;
} }
// RiderPathLocator includes Rider and Fleet locations, prefer Rider when available. // RiderPathLocator includes Rider and Fleet locations.
var preferredInfo = allInfos.LastOrDefault(info => IsRider(info.Path), allInfos[allInfos.Length - 1]); var matchingIde = allInfos.LastOrDefault(info => IsMatch(editorId, info.Path));
string newPath = preferredInfo.Path; var newPath = matchingIde.Path;
if (string.IsNullOrEmpty(newPath))
{
return null;
}
var editorSettings = EditorInterface.Singleton.GetEditorSettings(); var editorSettings = EditorInterface.Singleton.GetEditorSettings();
editorSettings.SetSetting(EditorPathSettingName, newPath); editorSettings.SetSetting(EditorPathSettingName, newPath);
@ -103,10 +104,10 @@ namespace GodotTools.Ides.Rider
return newPath; 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(); var pathFromSettings = GetRiderPathFromSettings();
string? path = CheckAndUpdatePath(pathFromSettings); var path = CheckAndUpdatePath(editorId, pathFromSettings);
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
GD.PushError($"Error when trying to run code editor: JetBrains Rider or Fleet. Could not find path to the editor."); GD.PushError($"Error when trying to run code editor: JetBrains Rider or Fleet. Could not find path to the editor.");