11using System ;
2- using System . Diagnostics ;
32using System . IO ;
43using System . Linq ;
54using System . Threading . Tasks ;
@@ -19,56 +18,63 @@ public partial class EditorElement
1918
2019 public async Task GoToDefinition ( MouseButtonEventArgs e )
2120 {
22- var word = GetWordAtMousePosition ( e ) ;
23- if ( word . Trim ( ) . Length == 0 )
21+ try
2422 {
25- return ;
26- }
23+ var word = GetWordAtMousePosition ( e ) ;
24+ if ( word . Trim ( ) . Length == 0 )
25+ {
26+ return ;
27+ }
2728
28- e . Handled = true ;
29+ e . Handled = true ;
2930
30- // First search across all scripting directories
31+ // First search across all scripting directories
3132
32- var sm = MatchDefinition ( Program . Configs [ Program . SelectedConfig ] . GetSMDef ( ) , word , e ) ;
33- if ( sm != null )
34- {
35- var config = Program . Configs [ Program . SelectedConfig ] . SMDirectories ;
36-
37- foreach ( var cfg in config )
33+ var sm = MatchDefinition ( Program . Configs [ Program . SelectedConfig ] . GetSMDef ( ) , word , e ) ;
34+ if ( sm != null )
3835 {
39- var file = Path . GetFullPath ( Path . Combine ( cfg , "include" , sm . File ) ) + ".inc" ;
36+ var config = Program . Configs [ Program . SelectedConfig ] . SMDirectories ;
4037
41- if ( ! File . Exists ( file ) )
38+ foreach ( var cfg in config )
4239 {
43- file = Path . GetFullPath ( Path . Combine ( cfg , sm . File ) ) + ".inc" ;
40+ var file = Path . GetFullPath ( Path . Combine ( cfg , "include" , sm . File ) ) + ".inc" ;
41+
42+ if ( ! File . Exists ( file ) )
43+ {
44+ file = Path . GetFullPath ( Path . Combine ( cfg , sm . File ) ) + ".inc" ;
45+ }
46+
47+ await Task . Delay ( 100 ) ;
48+ if ( Program . MainWindow . TryLoadSourceFile ( file , out var newEditor , true , false , true ) && newEditor != null )
49+ {
50+ newEditor . editor . TextArea . Caret . Offset = sm . Index ;
51+ newEditor . editor . TextArea . Caret . BringCaretToView ( ) ;
52+ newEditor . editor . TextArea . Selection = Selection . Create ( newEditor . editor . TextArea , sm . Index , sm . Index + sm . Length ) ;
53+ return ;
54+ }
55+ else
56+ {
57+ continue ;
58+ }
4459 }
60+ }
4561
62+ // If not, try to match variables in the current file
63+ // (shit solution to fix some symbols getting read first inside of the file inaproppiately)
64+
65+ sm = MatchDefinition ( currentSmDef , word , e , true ) ;
66+ if ( sm != null )
67+ {
68+ editor . TextArea . Caret . Offset = sm . Index ;
69+ editor . TextArea . Caret . BringCaretToView ( ) ;
4670 await Task . Delay ( 100 ) ;
47- if ( Program . MainWindow . TryLoadSourceFile ( file , out var newEditor , true , false , true ) && newEditor != null )
48- {
49- newEditor . editor . TextArea . Caret . Offset = sm . Index ;
50- newEditor . editor . TextArea . Caret . BringCaretToView ( ) ;
51- newEditor . editor . TextArea . Selection = Selection . Create ( newEditor . editor . TextArea , sm . Index , sm . Index + sm . Length ) ;
52- return ;
53- }
54- else
55- {
56- LoggingControl . LogAction ( $ "File { file } not found!") ;
57- continue ;
58- }
71+ editor . TextArea . Selection = Selection . Create ( editor . TextArea , sm . Index , sm . Index + sm . Length ) ;
5972 }
6073 }
61-
62- // If not, try to match variables in the current file
63- // (shit solution to fix some symbols getting read first inside of the file inaproppiately)
64-
65- sm = MatchDefinition ( currentSmDef , word , e , true ) ;
66- if ( sm != null )
74+ catch ( Exception ex )
6775 {
68- editor . TextArea . Caret . Offset = sm . Index ;
69- editor . TextArea . Caret . BringCaretToView ( ) ;
70- await Task . Delay ( 100 ) ;
71- editor . TextArea . Selection = Selection . Create ( editor . TextArea , sm . Index , sm . Index + sm . Length ) ;
76+ LoggingControl . LogAction ( $ "Exception caught on go to definition: { ex . Message } . Report this bug!") ;
77+ return ;
7278 }
7379 }
7480
@@ -106,12 +112,10 @@ private SMBaseDefinition MatchDefinition(SMDefinition smDef, string word, MouseB
106112 }
107113
108114 // variables
109- sm ??= smDef . Variables . FirstOrDefault ( i =>
110- i . Name . Equals ( word ) ) ;
115+ sm ??= smDef . Variables . FirstOrDefault ( i => i . Name . Equals ( word ) ) ;
111116
112117 // constants
113- sm ??= smDef . Constants . FirstOrDefault ( i =>
114- i . Name . Equals ( word ) ) ;
118+ sm ??= smDef . Constants . FirstOrDefault ( i => i . Name . Equals ( word ) ) ;
115119
116120 // defines
117121 sm ??= smDef . Defines . FirstOrDefault ( i => i . Name . Equals ( word ) ) ;
@@ -123,8 +127,7 @@ private SMBaseDefinition MatchDefinition(SMDefinition smDef, string word, MouseB
123127 {
124128 foreach ( var smEnum in smDef . Enums )
125129 {
126- var str = smEnum . Entries . FirstOrDefault (
127- i => i . Equals ( word ) ) ;
130+ var str = smEnum . Entries . FirstOrDefault ( i => i . Equals ( word ) ) ;
128131
129132 if ( str == null )
130133 {
@@ -137,24 +140,18 @@ private SMBaseDefinition MatchDefinition(SMDefinition smDef, string word, MouseB
137140 }
138141
139142 // enum structs
140- sm ??= smDef . EnumStructs . FirstOrDefault ( i =>
141- i . Name . Equals ( word , StringComparison . InvariantCultureIgnoreCase ) ) ;
143+ sm ??= smDef . EnumStructs . FirstOrDefault ( i => i . Name . Equals ( word , StringComparison . InvariantCultureIgnoreCase ) ) ;
142144
143- sm ??= smDef . EnumStructs . FirstOrDefault (
144- i => i . Fields . Any ( j => j . Name == word ) ) ;
145+ sm ??= smDef . EnumStructs . FirstOrDefault ( i => i . Fields . Any ( j => j . Name == word ) ) ;
145146
146- sm ??= smDef . EnumStructs . FirstOrDefault (
147- i => i . Methods . Any ( j => j . Name == word ) ) ;
147+ sm ??= smDef . EnumStructs . FirstOrDefault ( i => i . Methods . Any ( j => j . Name == word ) ) ;
148148
149149 // methodmaps
150- sm ??= smDef . Methodmaps . FirstOrDefault (
151- i => i . Name . Equals ( word , StringComparison . InvariantCultureIgnoreCase ) ) ;
150+ sm ??= smDef . Methodmaps . FirstOrDefault ( i => i . Name . Equals ( word , StringComparison . InvariantCultureIgnoreCase ) ) ;
152151
153- sm ??= smDef . Methodmaps . FirstOrDefault (
154- i => i . Fields . Any ( j => j . Name == word ) ) ;
152+ sm ??= smDef . Methodmaps . FirstOrDefault ( i => i . Fields . Any ( j => j . Name == word ) ) ;
155153
156- sm ??= smDef . Methodmaps . FirstOrDefault (
157- i => i . Methods . Any ( j => j . Name == word ) ) ;
154+ sm ??= smDef . Methodmaps . FirstOrDefault ( i => i . Methods . Any ( j => j . Name == word ) ) ;
158155
159156 // structs?
160157 sm ??= smDef . Structs . FirstOrDefault ( i => i . Name . Equals ( word , StringComparison . InvariantCultureIgnoreCase ) ) ;
0 commit comments