Skip to content

Commit

Permalink
support Rider and Fleet open file args, fix godotengine#78832 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
van800 committed Jul 27, 2023
1 parent 41a7f6b commit 6ec0e03
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public Error OpenInExternalEditor(Script script, int line, int col)
case ExternalEditorId.Rider:
{
string scriptPath = ProjectSettings.GlobalizePath(script.ResourcePath);
RiderPathManager.OpenFile(GodotSharpDirs.ProjectSlnPath, scriptPath, line);
RiderPathManager.OpenFile(GodotSharpDirs.ProjectSlnPath, scriptPath, line, col);
return Error.Ok;
}
case ExternalEditorId.MonoDevelop:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3.0" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="JetBrains.Rider.PathLocator" Version="1.0.1" />
<PackageReference Include="JetBrains.Rider.PathLocator" Version="1.0.3" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<Reference Include="GodotSharp">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ public void Error(string message, Exception e = null)
else
GD.PushError(message, e);
}

public void Verbose(string message, Exception e = null)
{
// do nothing, since IDK how to write only to the log, without spamming the output
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Godot;
Expand All @@ -11,10 +10,12 @@ namespace GodotTools.Ides.Rider
public static class RiderPathManager
{
private static readonly RiderPathLocator RiderPathLocator;

private static readonly RiderFileOpener RiderFileOpener;
static RiderPathManager()
{
RiderPathLocator = new RiderPathLocator(new RiderLocatorEnvironment());
var riderLocatorEnvironment = new RiderLocatorEnvironment();
RiderPathLocator = new RiderPathLocator(riderLocatorEnvironment);
RiderFileOpener = new RiderFileOpener(riderLocatorEnvironment);
}

public static readonly string EditorPathSettingName = "dotnet/editor/editor_path_optional";
Expand Down Expand Up @@ -46,7 +47,7 @@ public static void Initialize()
}

var riderPath = (string)editorSettings.GetSetting(EditorPathSettingName);
if (IsRiderAndExists(riderPath))
if (Exists(riderPath))
{
Globals.EditorDef(EditorPathSettingName, riderPath);
return;
Expand All @@ -63,12 +64,6 @@ public static void Initialize()
}
}

public static bool IsExternalEditorSetToRider(EditorSettings editorSettings)
{
return editorSettings.HasSetting(EditorPathSettingName) &&
IsRider((string)editorSettings.GetSetting(EditorPathSettingName));
}

public static bool IsRider(string path)
{
if (string.IsNullOrEmpty(path))
Expand All @@ -84,49 +79,31 @@ public static bool IsRider(string path)

private static string CheckAndUpdatePath(string riderPath)
{
if (IsRiderAndExists(riderPath))
if (Exists(riderPath))
{
return riderPath;
}

var allInfos = RiderPathLocator.GetAllRiderPaths();
if (!allInfos.Any()) return null;
var riderInfos = allInfos.Where(info => IsRider(info.Path)).ToArray();
var newPath = riderInfos.Any() ? riderInfos.Last().Path : allInfos.Last().Path;
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
var paths = RiderPathLocator.GetAllRiderPaths();

if (!paths.Any())
return null;

string newPath = paths.Last().Path;
editorSettings.SetSetting(EditorPathSettingName, newPath);
Globals.EditorDef(EditorPathSettingName, newPath);
return newPath;
}

private static bool IsRiderAndExists(string riderPath)
private static bool Exists(string path)
{
return !string.IsNullOrEmpty(riderPath) && IsRider(riderPath) && new FileInfo(riderPath).Exists;
return !string.IsNullOrEmpty(path) && new FileInfo(path).Exists;
}

public static void OpenFile(string slnPath, string scriptPath, int line)
public static void OpenFile(string slnPath, string scriptPath, int line, int column)
{
string pathFromSettings = GetRiderPathFromSettings();
string path = CheckAndUpdatePath(pathFromSettings);

var args = new List<string>();
args.Add(slnPath);
if (line >= 0)
{
args.Add("--line");
args.Add((line + 1).ToString()); // https://github.com/JetBrains/godot-support/issues/61
}
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}'");
}
RiderFileOpener.OpenFile(path, slnPath, scriptPath, line, column);
}
}
}

0 comments on commit 6ec0e03

Please sign in to comment.