Skip to content

Commit 98c204a

Browse files
committed
Merge pull request godotengine#104828 from van800/rider_fleet
C#: Separate Rider and Fleet options as external editors
2 parents 608e7a2 + 45a07c1 commit 98c204a

File tree

5 files changed

+77
-54
lines changed

5 files changed

+77
-54
lines changed

modules/mono/editor/GodotTools/GodotTools/ExternalEditorId.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum ExternalEditorId : long
88
MonoDevelop,
99
VsCode,
1010
Rider,
11-
CustomEditor
11+
CustomEditor,
12+
Fleet,
1213
}
1314
}

modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ public Error OpenInExternalEditor(Script script, int line, int col)
286286
case ExternalEditorId.VisualStudioForMac:
287287
goto case ExternalEditorId.MonoDevelop;
288288
case ExternalEditorId.Rider:
289+
case ExternalEditorId.Fleet:
289290
{
290291
string scriptPath = ProjectSettings.GlobalizePath(script.ResourcePath);
291-
RiderPathManager.OpenFile(GodotSharpDirs.ProjectSlnPath, scriptPath, line + 1, col);
292+
RiderPathManager.OpenFile(editorId, GodotSharpDirs.ProjectSlnPath, scriptPath, line + 1, col);
292293
return Error.Ok;
293294
}
294295
case ExternalEditorId.MonoDevelop:
@@ -568,22 +569,25 @@ public override void _EnablePlugin()
568569
settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudio}" +
569570
$",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" +
570571
$",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" +
571-
$",JetBrains Rider and Fleet:{(int)ExternalEditorId.Rider}" +
572+
$",JetBrains Rider:{(int)ExternalEditorId.Rider}" +
573+
$",JetBrains Fleet:{(int)ExternalEditorId.Fleet}" +
572574
$",Custom:{(int)ExternalEditorId.CustomEditor}";
573575
}
574576
else if (OS.IsMacOS)
575577
{
576578
settingsHintStr += $",Visual Studio:{(int)ExternalEditorId.VisualStudioForMac}" +
577579
$",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" +
578580
$",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" +
579-
$",JetBrains Rider and Fleet:{(int)ExternalEditorId.Rider}" +
581+
$",JetBrains Rider:{(int)ExternalEditorId.Rider}" +
582+
$",JetBrains Fleet:{(int)ExternalEditorId.Fleet}" +
580583
$",Custom:{(int)ExternalEditorId.CustomEditor}";
581584
}
582585
else if (OS.IsUnixLike)
583586
{
584587
settingsHintStr += $",MonoDevelop:{(int)ExternalEditorId.MonoDevelop}" +
585588
$",Visual Studio Code and VSCodium:{(int)ExternalEditorId.VsCode}" +
586-
$",JetBrains Rider and Fleet:{(int)ExternalEditorId.Rider}" +
589+
$",JetBrains Rider:{(int)ExternalEditorId.Rider}" +
590+
$",JetBrains Fleet:{(int)ExternalEditorId.Fleet}" +
587591
$",Custom:{(int)ExternalEditorId.CustomEditor}";
588592
}
589593

@@ -640,7 +644,6 @@ public override void _EnablePlugin()
640644
_inspectorPluginWeak = WeakRef(inspectorPlugin);
641645

642646
BuildManager.Initialize();
643-
RiderPathManager.Initialize();
644647

645648
GodotIdeManager = new GodotIdeManager();
646649
AddChild(GodotIdeManager);
@@ -664,13 +667,28 @@ public override void _ExitTree()
664667

665668
private void OnSettingsChanged()
666669
{
667-
// We want to force NoConsoleLogging to true when the VerbosityLevel is at Detailed or above.
668-
// At that point, there's so much info logged that it doesn't make sense to display it in
669-
// the tiny editor window, and it'd make the editor hang or crash anyway.
670-
var verbosityLevel = _editorSettings.GetSetting(Settings.VerbosityLevel).As<VerbosityLevelId>();
671-
var hideConsoleLog = (bool)_editorSettings.GetSetting(Settings.NoConsoleLogging);
672-
if (verbosityLevel >= VerbosityLevelId.Detailed && !hideConsoleLog)
673-
_editorSettings.SetSetting(Settings.NoConsoleLogging, Variant.From(true));
670+
var changedSettings = _editorSettings.GetChangedSettings();
671+
if (changedSettings.Contains(Settings.VerbosityLevel))
672+
{
673+
// We want to force NoConsoleLogging to true when the VerbosityLevel is at Detailed or above.
674+
// At that point, there's so much info logged that it doesn't make sense to display it in
675+
// the tiny editor window, and it'd make the editor hang or crash anyway.
676+
var verbosityLevel = _editorSettings.GetSetting(Settings.VerbosityLevel).As<VerbosityLevelId>();
677+
var hideConsoleLog = (bool)_editorSettings.GetSetting(Settings.NoConsoleLogging);
678+
if (verbosityLevel >= VerbosityLevelId.Detailed && !hideConsoleLog)
679+
_editorSettings.SetSetting(Settings.NoConsoleLogging, Variant.From(true));
680+
}
681+
682+
if (changedSettings.Contains(Settings.ExternalEditor) && !changedSettings.Contains(RiderPathManager.EditorPathSettingName))
683+
{
684+
var editor = _editorSettings.GetSetting(Settings.ExternalEditor).As<ExternalEditorId>();
685+
if (editor != ExternalEditorId.Fleet && editor != ExternalEditorId.Rider)
686+
{
687+
return;
688+
}
689+
690+
RiderPathManager.InitializeIfNeeded(editor);
691+
}
674692
}
675693

676694
protected override void Dispose(bool disposing)

modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<ItemGroup>
3636
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3.0" ExcludeAssets="runtime" PrivateAssets="all" />
37-
<PackageReference Include="JetBrains.Rider.PathLocator" Version="1.0.9" />
37+
<PackageReference Include="JetBrains.Rider.PathLocator" Version="1.0.12" />
3838
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
3939
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
4040
<Reference Include="GodotSharp">

modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ private string GetExternalEditorIdentity(ExternalEditorId editorId)
6666
return "VisualStudioCode";
6767
case ExternalEditorId.Rider:
6868
return "Rider";
69+
case ExternalEditorId.Fleet:
70+
return "Fleet";
6971
case ExternalEditorId.VisualStudioForMac:
7072
return "VisualStudioForMac";
7173
case ExternalEditorId.MonoDevelop:
@@ -107,6 +109,7 @@ private void LaunchIde(ExternalEditorId editorId, string editorIdentity)
107109
case ExternalEditorId.VisualStudio:
108110
case ExternalEditorId.VsCode:
109111
case ExternalEditorId.Rider:
112+
case ExternalEditorId.Fleet:
110113
case ExternalEditorId.CustomEditor:
111114
throw new NotSupportedException();
112115
case ExternalEditorId.VisualStudioForMac:

modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GodotTools.Ides.Rider
99
{
1010
public static class RiderPathManager
1111
{
12-
private const string EditorPathSettingName = "dotnet/editor/editor_path_optional";
12+
internal const string EditorPathSettingName = "dotnet/editor/editor_path_optional";
1313

1414
private static readonly RiderPathLocator RiderPathLocator;
1515
private static readonly RiderFileOpener RiderFileOpener;
@@ -32,59 +32,56 @@ static RiderPathManager()
3232
return null;
3333
}
3434

35-
public static void Initialize()
35+
public static void InitializeIfNeeded(ExternalEditorId editor)
3636
{
3737
var editorSettings = EditorInterface.Singleton.GetEditorSettings();
38-
var editor = editorSettings.GetSetting(GodotSharpEditor.Settings.ExternalEditor).As<ExternalEditorId>();
39-
if (editor == ExternalEditorId.Rider)
38+
if (!editorSettings.HasSetting(EditorPathSettingName))
4039
{
41-
if (!editorSettings.HasSetting(EditorPathSettingName))
40+
Globals.EditorDef(EditorPathSettingName, "");
41+
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
4242
{
43-
Globals.EditorDef(EditorPathSettingName, "");
44-
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
45-
{
46-
["type"] = (int)Variant.Type.String,
47-
["name"] = EditorPathSettingName,
48-
["hint"] = (int)PropertyHint.File,
49-
["hint_string"] = ""
50-
});
51-
}
52-
53-
var riderPath = (string)editorSettings.GetSetting(EditorPathSettingName);
54-
if (File.Exists(riderPath))
55-
{
56-
Globals.EditorDef(EditorPathSettingName, riderPath);
57-
return;
58-
}
43+
["type"] = (int)Variant.Type.String,
44+
["name"] = EditorPathSettingName,
45+
["hint"] = (int)PropertyHint.File,
46+
["hint_string"] = ""
47+
});
48+
}
5949

60-
var paths = RiderPathLocator.GetAllRiderPaths();
61-
if (paths.Length == 0)
62-
{
63-
return;
64-
}
50+
var editorPath = (string)editorSettings.GetSetting(EditorPathSettingName);
51+
if (File.Exists(editorPath) && IsMatch(editor, editorPath))
52+
{
53+
Globals.EditorDef(EditorPathSettingName, editorPath);
54+
return;
55+
}
6556

66-
string newPath = paths.Last().Path;
67-
Globals.EditorDef(EditorPathSettingName, newPath);
68-
editorSettings.SetSetting(EditorPathSettingName, newPath);
57+
var paths = RiderPathLocator.GetAllRiderPaths().Where(info => IsMatch(editor, info.Path)).ToArray();
58+
if (paths.Length == 0)
59+
{
60+
return;
6961
}
62+
63+
string newPath = paths.Last().Path;
64+
Globals.EditorDef(EditorPathSettingName, newPath);
65+
editorSettings.SetSetting(EditorPathSettingName, newPath);
7066
}
7167

72-
public static bool IsRider(string path)
68+
private static bool IsMatch(ExternalEditorId editorId, string path)
7369
{
7470
if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
7571
{
7672
return false;
7773
}
7874

7975
var fileInfo = new FileInfo(path);
80-
return fileInfo.Name.StartsWith("rider", StringComparison.OrdinalIgnoreCase);
76+
var name = editorId == ExternalEditorId.Fleet ? "fleet" : "rider";
77+
return fileInfo.Name.StartsWith(name, StringComparison.OrdinalIgnoreCase);
8178
}
8279

83-
private static string? CheckAndUpdatePath(string? riderPath)
80+
private static string? CheckAndUpdatePath(ExternalEditorId editorId, string? idePath)
8481
{
85-
if (File.Exists(riderPath))
82+
if (File.Exists(idePath))
8683
{
87-
return riderPath;
84+
return idePath;
8885
}
8986

9087
var allInfos = RiderPathLocator.GetAllRiderPaths();
@@ -93,20 +90,24 @@ public static bool IsRider(string path)
9390
return null;
9491
}
9592

96-
// RiderPathLocator includes Rider and Fleet locations, prefer Rider when available.
97-
var preferredInfo = allInfos.LastOrDefault(info => IsRider(info.Path), allInfos[allInfos.Length - 1]);
98-
string newPath = preferredInfo.Path;
93+
// RiderPathLocator includes Rider and Fleet locations.
94+
var matchingIde = allInfos.LastOrDefault(info => IsMatch(editorId, info.Path));
95+
var newPath = matchingIde.Path;
96+
if (string.IsNullOrEmpty(newPath))
97+
{
98+
return null;
99+
}
99100

100101
var editorSettings = EditorInterface.Singleton.GetEditorSettings();
101102
editorSettings.SetSetting(EditorPathSettingName, newPath);
102103
Globals.EditorDef(EditorPathSettingName, newPath);
103104
return newPath;
104105
}
105106

106-
public static void OpenFile(string slnPath, string scriptPath, int line, int column)
107+
public static void OpenFile(ExternalEditorId editorId, string slnPath, string scriptPath, int line, int column)
107108
{
108-
string? pathFromSettings = GetRiderPathFromSettings();
109-
string? path = CheckAndUpdatePath(pathFromSettings);
109+
var pathFromSettings = GetRiderPathFromSettings();
110+
var path = CheckAndUpdatePath(editorId, pathFromSettings);
110111
if (string.IsNullOrEmpty(path))
111112
{
112113
GD.PushError($"Error when trying to run code editor: JetBrains Rider or Fleet. Could not find path to the editor.");

0 commit comments

Comments
 (0)