2019-12-06 11:30:49 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using Godot;
|
|
|
|
using GodotTools.Internals;
|
|
|
|
|
|
|
|
namespace GodotTools.Ides.Rider
|
|
|
|
{
|
2019-12-11 14:46:28 +01:00
|
|
|
public static class RiderPathManager
|
2019-12-06 11:30:49 +01:00
|
|
|
{
|
2020-02-26 20:56:52 +01:00
|
|
|
public static readonly string EditorPathSettingName = "mono/editor/editor_path_optional";
|
2019-12-11 14:46:28 +01:00
|
|
|
|
|
|
|
private static string GetRiderPathFromSettings()
|
2019-12-06 11:30:49 +01:00
|
|
|
{
|
2019-12-11 14:46:28 +01:00
|
|
|
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
|
2020-02-26 20:56:52 +01:00
|
|
|
if (editorSettings.HasSetting(EditorPathSettingName))
|
|
|
|
return (string)editorSettings.GetSetting(EditorPathSettingName);
|
2019-12-11 14:46:28 +01:00
|
|
|
return null;
|
2019-12-06 11:30:49 +01:00
|
|
|
}
|
|
|
|
|
2019-12-11 14:46:28 +01:00
|
|
|
public static void Initialize()
|
2019-12-06 11:30:49 +01:00
|
|
|
{
|
2019-12-11 14:46:28 +01:00
|
|
|
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
|
|
|
|
var editor = (ExternalEditorId)editorSettings.GetSetting("mono/editor/external_editor");
|
|
|
|
if (editor == ExternalEditorId.Rider)
|
|
|
|
{
|
2020-02-26 20:56:52 +01:00
|
|
|
if (!editorSettings.HasSetting(EditorPathSettingName))
|
2019-12-11 14:46:28 +01:00
|
|
|
{
|
2020-02-26 20:56:52 +01:00
|
|
|
Globals.EditorDef(EditorPathSettingName, "Optional");
|
2019-12-11 14:46:28 +01:00
|
|
|
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
|
|
|
|
{
|
|
|
|
["type"] = Variant.Type.String,
|
2020-02-26 20:56:52 +01:00
|
|
|
["name"] = EditorPathSettingName,
|
2019-12-11 14:46:28 +01:00
|
|
|
["hint"] = PropertyHint.File,
|
|
|
|
["hint_string"] = ""
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-26 20:56:52 +01:00
|
|
|
var riderPath = (string)editorSettings.GetSetting(EditorPathSettingName);
|
2019-12-11 14:46:28 +01:00
|
|
|
if (IsRiderAndExists(riderPath))
|
|
|
|
{
|
2020-02-26 20:56:52 +01:00
|
|
|
Globals.EditorDef(EditorPathSettingName, riderPath);
|
2019-12-11 14:46:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var paths = RiderPathLocator.GetAllRiderPaths();
|
|
|
|
|
|
|
|
if (!paths.Any())
|
|
|
|
return;
|
|
|
|
|
|
|
|
var newPath = paths.Last().Path;
|
2020-02-26 20:56:52 +01:00
|
|
|
Globals.EditorDef(EditorPathSettingName, newPath);
|
|
|
|
editorSettings.SetSetting(EditorPathSettingName, newPath);
|
2019-12-11 14:46:28 +01:00
|
|
|
}
|
2019-12-06 11:30:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 15:33:14 +01:00
|
|
|
public static bool IsExternalEditorSetToRider(EditorSettings editorSettings)
|
|
|
|
{
|
|
|
|
return editorSettings.HasSetting(EditorPathSettingName) && IsRider((string) editorSettings.GetSetting(EditorPathSettingName));
|
|
|
|
}
|
|
|
|
|
2020-02-26 20:56:52 +01:00
|
|
|
public static bool IsRider(string path)
|
2019-12-11 14:46:28 +01:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
return false;
|
2019-12-06 11:30:49 +01:00
|
|
|
|
2019-12-11 14:46:28 +01:00
|
|
|
var fileInfo = new FileInfo(path);
|
|
|
|
var filename = fileInfo.Name.ToLowerInvariant();
|
|
|
|
return filename.StartsWith("rider", StringComparison.Ordinal);
|
|
|
|
}
|
2019-12-06 11:30:49 +01:00
|
|
|
|
2019-12-11 14:46:28 +01:00
|
|
|
private static string CheckAndUpdatePath(string riderPath)
|
|
|
|
{
|
|
|
|
if (IsRiderAndExists(riderPath))
|
|
|
|
{
|
|
|
|
return riderPath;
|
|
|
|
}
|
2019-12-06 11:30:49 +01:00
|
|
|
|
2019-12-11 14:46:28 +01:00
|
|
|
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
|
|
|
|
var paths = RiderPathLocator.GetAllRiderPaths();
|
2019-12-06 11:30:49 +01:00
|
|
|
|
2019-12-11 14:46:28 +01:00
|
|
|
if (!paths.Any())
|
|
|
|
return null;
|
2019-12-06 11:30:49 +01:00
|
|
|
|
2019-12-11 14:46:28 +01:00
|
|
|
var newPath = paths.Last().Path;
|
2020-02-26 20:56:52 +01:00
|
|
|
editorSettings.SetSetting(EditorPathSettingName, newPath);
|
|
|
|
Globals.EditorDef(EditorPathSettingName, newPath);
|
2019-12-11 14:46:28 +01:00
|
|
|
return newPath;
|
|
|
|
}
|
2019-12-06 11:30:49 +01:00
|
|
|
|
2019-12-11 14:46:28 +01:00
|
|
|
private static bool IsRiderAndExists(string riderPath)
|
|
|
|
{
|
|
|
|
return !string.IsNullOrEmpty(riderPath) && IsRider(riderPath) && new FileInfo(riderPath).Exists;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void OpenFile(string slnPath, string scriptPath, int line)
|
|
|
|
{
|
|
|
|
var pathFromSettings = GetRiderPathFromSettings();
|
|
|
|
var path = CheckAndUpdatePath(pathFromSettings);
|
|
|
|
|
|
|
|
var args = new List<string>();
|
|
|
|
args.Add(slnPath);
|
|
|
|
if (line >= 0)
|
|
|
|
{
|
|
|
|
args.Add("--line");
|
2021-01-28 22:41:12 +01:00
|
|
|
args.Add((line + 1).ToString()); // https://github.com/JetBrains/godot-support/issues/61
|
2019-12-11 14:46:28 +01:00
|
|
|
}
|
|
|
|
args.Add(scriptPath);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Utils.OS.RunProcess(path, args);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
GD.PushError($"Error when trying to run code editor: JetBrains Rider. Exception message: '{e.Message}'");
|
|
|
|
}
|
|
|
|
}
|
2019-12-06 11:30:49 +01:00
|
|
|
}
|
|
|
|
}
|