mirror of
https://github.com/godotengine/godot
synced 2024-09-15 22:48:13 +00:00
C#: Check if JetBrains Rider editor path is empty
This commit is contained in:
parent
3ed4497113
commit
5f6524ad44
|
@ -5,10 +5,14 @@ using Godot;
|
||||||
using GodotTools.Internals;
|
using GodotTools.Internals;
|
||||||
using JetBrains.Rider.PathLocator;
|
using JetBrains.Rider.PathLocator;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace GodotTools.Ides.Rider
|
namespace GodotTools.Ides.Rider
|
||||||
{
|
{
|
||||||
public static class RiderPathManager
|
public static class RiderPathManager
|
||||||
{
|
{
|
||||||
|
private 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;
|
||||||
|
|
||||||
|
@ -19,13 +23,14 @@ namespace GodotTools.Ides.Rider
|
||||||
RiderFileOpener = new RiderFileOpener(riderLocatorEnvironment);
|
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();
|
var editorSettings = EditorInterface.Singleton.GetEditorSettings();
|
||||||
if (editorSettings.HasSetting(EditorPathSettingName))
|
if (editorSettings.HasSetting(EditorPathSettingName))
|
||||||
|
{
|
||||||
return (string)editorSettings.GetSetting(EditorPathSettingName);
|
return (string)editorSettings.GetSetting(EditorPathSettingName);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +42,7 @@ namespace GodotTools.Ides.Rider
|
||||||
{
|
{
|
||||||
if (!editorSettings.HasSetting(EditorPathSettingName))
|
if (!editorSettings.HasSetting(EditorPathSettingName))
|
||||||
{
|
{
|
||||||
Globals.EditorDef(EditorPathSettingName, "Optional");
|
Globals.EditorDef(EditorPathSettingName, "");
|
||||||
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
|
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
|
||||||
{
|
{
|
||||||
["type"] = (int)Variant.Type.String,
|
["type"] = (int)Variant.Type.String,
|
||||||
|
@ -55,9 +60,10 @@ namespace GodotTools.Ides.Rider
|
||||||
}
|
}
|
||||||
|
|
||||||
var paths = RiderPathLocator.GetAllRiderPaths();
|
var paths = RiderPathLocator.GetAllRiderPaths();
|
||||||
|
if (paths.Length == 0)
|
||||||
if (!paths.Any())
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string newPath = paths.Last().Path;
|
string newPath = paths.Last().Path;
|
||||||
Globals.EditorDef(EditorPathSettingName, newPath);
|
Globals.EditorDef(EditorPathSettingName, newPath);
|
||||||
|
@ -67,18 +73,16 @@ namespace GodotTools.Ides.Rider
|
||||||
|
|
||||||
public static bool IsRider(string path)
|
public static bool IsRider(string path)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
|
if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var fileInfo = new FileInfo(path);
|
var fileInfo = new FileInfo(path);
|
||||||
string filename = fileInfo.Name.ToLowerInvariant();
|
return fileInfo.Name.StartsWith("rider", StringComparison.OrdinalIgnoreCase);
|
||||||
return filename.StartsWith("rider", StringComparison.Ordinal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CheckAndUpdatePath(string riderPath)
|
private static string? CheckAndUpdatePath(string? riderPath)
|
||||||
{
|
{
|
||||||
if (File.Exists(riderPath))
|
if (File.Exists(riderPath))
|
||||||
{
|
{
|
||||||
|
@ -87,11 +91,14 @@ namespace GodotTools.Ides.Rider
|
||||||
|
|
||||||
var allInfos = RiderPathLocator.GetAllRiderPaths();
|
var allInfos = RiderPathLocator.GetAllRiderPaths();
|
||||||
if (allInfos.Length == 0)
|
if (allInfos.Length == 0)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
var riderInfos = allInfos.Where(info => IsRider(info.Path)).ToArray();
|
}
|
||||||
string newPath = riderInfos.Length > 0
|
|
||||||
? riderInfos[riderInfos.Length - 1].Path
|
// RiderPathLocator includes Rider and Fleet locations, prefer Rider when available.
|
||||||
: allInfos[allInfos.Length - 1].Path;
|
var preferredInfo = allInfos.LastOrDefault(info => IsRider(info.Path), allInfos[allInfos.Length - 1]);
|
||||||
|
string newPath = preferredInfo.Path;
|
||||||
|
|
||||||
var editorSettings = EditorInterface.Singleton.GetEditorSettings();
|
var editorSettings = EditorInterface.Singleton.GetEditorSettings();
|
||||||
editorSettings.SetSetting(EditorPathSettingName, newPath);
|
editorSettings.SetSetting(EditorPathSettingName, newPath);
|
||||||
Globals.EditorDef(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)
|
public static void OpenFile(string slnPath, string scriptPath, int line, int column)
|
||||||
{
|
{
|
||||||
string pathFromSettings = GetRiderPathFromSettings();
|
string? pathFromSettings = GetRiderPathFromSettings();
|
||||||
string path = CheckAndUpdatePath(pathFromSettings);
|
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);
|
RiderFileOpener.OpenFile(path, slnPath, scriptPath, line, column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue