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,
VsCode,
Rider,
CustomEditor
CustomEditor,
Fleet,
}
}

View file

@ -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<VerbosityLevelId>();
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<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)

View file

@ -34,7 +34,7 @@
<ItemGroup>
<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="Newtonsoft.Json" Version="13.0.1" />
<Reference Include="GodotSharp">

View file

@ -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:

View file

@ -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<ExternalEditorId>();
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.");