@@ -62,8 +62,13 @@ local function searchInAllFiles(suri, searcher, notify)
62
62
end
63
63
64
64
--- @async
65
- local function searchField (source , pushResult , defMap , fileNotify )
65
+ local function searchWord (source , pushResult , defMap , fileNotify )
66
66
local key = guide .getKeyName (source )
67
+ if not key then
68
+ return
69
+ end
70
+
71
+ local global = vm .getGlobalNode (source )
67
72
68
73
--- @param src parser.object
69
74
local function checkDef (src )
@@ -75,42 +80,53 @@ local function searchField(source, pushResult, defMap, fileNotify)
75
80
end
76
81
end
77
82
78
- local pat = ' [:.]%s*' .. key
79
-
80
83
--- @async
81
84
local function findWord (uri )
82
85
local text = files .getText (uri )
83
86
if not text then
84
87
return
85
88
end
86
- if not text :match (pat ) then
89
+ if not text :match (key ) then
87
90
return
88
91
end
89
92
local state = files .getState (uri )
90
93
if not state then
91
94
return
92
95
end
93
- --- @async
94
- guide .eachSourceTypes (state .ast , {' getfield' , ' setfield' }, function (src )
95
- if src .field and src .field [1 ] == key then
96
- checkDef (src )
97
- await .delay ()
98
- end
99
- end )
100
- --- @async
101
- guide .eachSourceTypes (state .ast , {' getmethod' , ' setmethod' }, function (src )
102
- if src .method and src .method [1 ] == key then
103
- checkDef (src )
104
- await .delay ()
105
- end
106
- end )
107
- --- @async
108
- guide .eachSourceTypes (state .ast , {' getindex' , ' setindex' }, function (src )
109
- if src .index and src .index .type == ' string' and src .index [1 ] == key then
110
- checkDef (src )
111
- await .delay ()
112
- end
113
- end )
96
+
97
+ if global then
98
+ local globalName = global :asKeyName ()
99
+ --- @async
100
+ guide .eachSourceTypes (state .ast , {' getglobal' , ' setglobal' , ' setfield' , ' getfield' , ' setmethod' , ' getmethod' , ' setindex' , ' getindex' , ' doc.type.name' , ' doc.class.name' , ' doc.alias.name' }, function (src )
101
+ local myGlobal = vm .getGlobalNode (src )
102
+ if myGlobal and myGlobal :asKeyName () == globalName then
103
+ pushResult (src )
104
+ await .delay ()
105
+ end
106
+ end )
107
+ else
108
+ --- @async
109
+ guide .eachSourceTypes (state .ast , {' getfield' , ' setfield' }, function (src )
110
+ if src .field and src .field [1 ] == key then
111
+ checkDef (src )
112
+ await .delay ()
113
+ end
114
+ end )
115
+ --- @async
116
+ guide .eachSourceTypes (state .ast , {' getmethod' , ' setmethod' }, function (src )
117
+ if src .method and src .method [1 ] == key then
118
+ checkDef (src )
119
+ await .delay ()
120
+ end
121
+ end )
122
+ --- @async
123
+ guide .eachSourceTypes (state .ast , {' getindex' , ' setindex' }, function (src )
124
+ if src .index and src .index .type == ' string' and src .index [1 ] == key then
125
+ checkDef (src )
126
+ await .delay ()
127
+ end
128
+ end )
129
+ end
114
130
end
115
131
116
132
searchInAllFiles (guide .getUri (source ), findWord , fileNotify )
@@ -165,18 +181,35 @@ local nodeSwitch = util.switch()
165
181
return
166
182
end
167
183
168
- searchField (source , pushResult , defMap , fileNotify )
184
+ searchWord (source , pushResult , defMap , fileNotify )
169
185
end )
170
186
: case ' tablefield'
171
187
: case ' tableindex'
188
+ : case ' doc.field.name'
172
189
--- @async
173
190
: call (function (source , pushResult , defMap , fileNotify )
174
- searchField (source , pushResult , defMap , fileNotify )
191
+ searchWord (source , pushResult , defMap , fileNotify )
175
192
end )
176
- : case ' doc.field.name'
193
+ : case ' setglobal'
194
+ : case ' getglobal'
195
+ --- @async
196
+ : call (function (source , pushResult , defMap , fileNotify )
197
+ searchWord (source , pushResult , defMap , fileNotify )
198
+ end )
199
+ : case ' doc.alias.name'
200
+ : case ' doc.class.name'
201
+ : case ' doc.enum.name'
202
+ --- @async
203
+ : call (function (source , pushResult , defMap , fileNotify )
204
+ searchWord (source .parent , pushResult , defMap , fileNotify )
205
+ end )
206
+ : case ' doc.alias'
207
+ : case ' doc.class'
208
+ : case ' doc.enum'
209
+ : case ' doc.type.name'
177
210
--- @async
178
211
: call (function (source , pushResult , defMap , fileNotify )
179
- searchField (source , pushResult , defMap , fileNotify )
212
+ searchWord (source , pushResult , defMap , fileNotify )
180
213
end )
181
214
: case ' function'
182
215
: case ' doc.type.function'
@@ -216,7 +249,6 @@ function searchByParentNode(source, pushResult, defMap, fileNotify)
216
249
nodeSwitch (source .type , source , pushResult , defMap , fileNotify )
217
250
end
218
251
219
- --- @async
220
252
local function searchByGlobal (source , pushResult )
221
253
if source .type == ' field'
222
254
or source .type == ' method'
0 commit comments