1
1
using System ;
2
- using System . Diagnostics ;
3
2
using System . IO ;
4
3
using System . Linq ;
5
4
using System . Threading . Tasks ;
@@ -19,56 +18,63 @@ public partial class EditorElement
19
18
20
19
public async Task GoToDefinition ( MouseButtonEventArgs e )
21
20
{
22
- var word = GetWordAtMousePosition ( e ) ;
23
- if ( word . Trim ( ) . Length == 0 )
21
+ try
24
22
{
25
- return ;
26
- }
23
+ var word = GetWordAtMousePosition ( e ) ;
24
+ if ( word . Trim ( ) . Length == 0 )
25
+ {
26
+ return ;
27
+ }
27
28
28
- e . Handled = true ;
29
+ e . Handled = true ;
29
30
30
- // First search across all scripting directories
31
+ // First search across all scripting directories
31
32
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 )
38
35
{
39
- var file = Path . GetFullPath ( Path . Combine ( cfg , "include" , sm . File ) ) + ".inc" ;
36
+ var config = Program . Configs [ Program . SelectedConfig ] . SMDirectories ;
40
37
41
- if ( ! File . Exists ( file ) )
38
+ foreach ( var cfg in config )
42
39
{
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
+ }
44
59
}
60
+ }
45
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 )
67
+ {
68
+ editor . TextArea . Caret . Offset = sm . Index ;
69
+ editor . TextArea . Caret . BringCaretToView ( ) ;
46
70
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 ) ;
59
72
}
60
73
}
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 )
67
75
{
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 ;
72
78
}
73
79
}
74
80
@@ -106,12 +112,10 @@ private SMBaseDefinition MatchDefinition(SMDefinition smDef, string word, MouseB
106
112
}
107
113
108
114
// variables
109
- sm ??= smDef . Variables . FirstOrDefault ( i =>
110
- i . Name . Equals ( word ) ) ;
115
+ sm ??= smDef . Variables . FirstOrDefault ( i => i . Name . Equals ( word ) ) ;
111
116
112
117
// constants
113
- sm ??= smDef . Constants . FirstOrDefault ( i =>
114
- i . Name . Equals ( word ) ) ;
118
+ sm ??= smDef . Constants . FirstOrDefault ( i => i . Name . Equals ( word ) ) ;
115
119
116
120
// defines
117
121
sm ??= smDef . Defines . FirstOrDefault ( i => i . Name . Equals ( word ) ) ;
@@ -123,8 +127,7 @@ private SMBaseDefinition MatchDefinition(SMDefinition smDef, string word, MouseB
123
127
{
124
128
foreach ( var smEnum in smDef . Enums )
125
129
{
126
- var str = smEnum . Entries . FirstOrDefault (
127
- i => i . Equals ( word ) ) ;
130
+ var str = smEnum . Entries . FirstOrDefault ( i => i . Equals ( word ) ) ;
128
131
129
132
if ( str == null )
130
133
{
@@ -137,24 +140,18 @@ private SMBaseDefinition MatchDefinition(SMDefinition smDef, string word, MouseB
137
140
}
138
141
139
142
// 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 ) ) ;
142
144
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 ) ) ;
145
146
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 ) ) ;
148
148
149
149
// 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 ) ) ;
152
151
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 ) ) ;
155
153
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 ) ) ;
158
155
159
156
// structs?
160
157
sm ??= smDef . Structs . FirstOrDefault ( i => i . Name . Equals ( word , StringComparison . InvariantCultureIgnoreCase ) ) ;
0 commit comments