summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-09-14 23:39:40 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-09-14 23:39:40 +0200
commit26493ca5bb29700cc937a906c1adc7db41df0134 (patch)
tree557dd2f7b4b37d7377282180560cceff1b98832f
parentb467afe65d826f9215f962fe7d78d6bbc1101624 (diff)
parent5f6524ad445a1ac072429e4e3c42eab84c0a869d (diff)
downloadredot-engine-26493ca5bb29700cc937a906c1adc7db41df0134.tar.gz
Merge pull request #78516 from raulsntos/dotnet/check-rider-path-is-empty
C#: Check if JetBrains Rider editor path is empty
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs49
1 files changed, 31 insertions, 18 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
index fbbd01dafd..a0ab381b9b 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
@@ -5,10 +5,14 @@ using Godot;
using GodotTools.Internals;
using JetBrains.Rider.PathLocator;
+#nullable enable
+
namespace GodotTools.Ides.Rider
{
public static class RiderPathManager
{
+ private const string EditorPathSettingName = "dotnet/editor/editor_path_optional";
+
private static readonly RiderPathLocator RiderPathLocator;
private static readonly RiderFileOpener RiderFileOpener;
@@ -19,13 +23,14 @@ namespace GodotTools.Ides.Rider
RiderFileOpener = new RiderFileOpener(riderLocatorEnvironment);
}
- public static readonly string EditorPathSettingName = "dotnet/editor/editor_path_optional";
-
- private static string GetRiderPathFromSettings()
+ private static string? GetRiderPathFromSettings()
{
var editorSettings = EditorInterface.Singleton.GetEditorSettings();
if (editorSettings.HasSetting(EditorPathSettingName))
+ {
return (string)editorSettings.GetSetting(EditorPathSettingName);
+ }
+
return null;
}
@@ -37,7 +42,7 @@ namespace GodotTools.Ides.Rider
{
if (!editorSettings.HasSetting(EditorPathSettingName))
{
- Globals.EditorDef(EditorPathSettingName, "Optional");
+ Globals.EditorDef(EditorPathSettingName, "");
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
{
["type"] = (int)Variant.Type.String,
@@ -55,9 +60,10 @@ namespace GodotTools.Ides.Rider
}
var paths = RiderPathLocator.GetAllRiderPaths();
-
- if (!paths.Any())
+ if (paths.Length == 0)
+ {
return;
+ }
string newPath = paths.Last().Path;
Globals.EditorDef(EditorPathSettingName, newPath);
@@ -67,18 +73,16 @@ namespace GodotTools.Ides.Rider
public static bool IsRider(string path)
{
- if (string.IsNullOrEmpty(path))
- return false;
-
if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
+ {
return false;
+ }
var fileInfo = new FileInfo(path);
- string filename = fileInfo.Name.ToLowerInvariant();
- return filename.StartsWith("rider", StringComparison.Ordinal);
+ return fileInfo.Name.StartsWith("rider", StringComparison.OrdinalIgnoreCase);
}
- private static string CheckAndUpdatePath(string riderPath)
+ private static string? CheckAndUpdatePath(string? riderPath)
{
if (File.Exists(riderPath))
{
@@ -87,11 +91,14 @@ namespace GodotTools.Ides.Rider
var allInfos = RiderPathLocator.GetAllRiderPaths();
if (allInfos.Length == 0)
+ {
return null;
- var riderInfos = allInfos.Where(info => IsRider(info.Path)).ToArray();
- string newPath = riderInfos.Length > 0
- ? riderInfos[riderInfos.Length - 1].Path
- : allInfos[allInfos.Length - 1].Path;
+ }
+
+ // 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;
+
var editorSettings = EditorInterface.Singleton.GetEditorSettings();
editorSettings.SetSetting(EditorPathSettingName, newPath);
Globals.EditorDef(EditorPathSettingName, newPath);
@@ -100,8 +107,14 @@ namespace GodotTools.Ides.Rider
public static void OpenFile(string slnPath, string scriptPath, int line, int column)
{
- string pathFromSettings = GetRiderPathFromSettings();
- string path = CheckAndUpdatePath(pathFromSettings);
+ string? pathFromSettings = GetRiderPathFromSettings();
+ string? path = CheckAndUpdatePath(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.");
+ return;
+ }
+
RiderFileOpener.OpenFile(path, slnPath, scriptPath, line, column);
}
}