@@ -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