@@ -62,8 +62,13 @@ local function searchInAllFiles(suri, searcher, notify)
6262end
6363
6464--- @async
65- local function searchField (source , pushResult , defMap , fileNotify )
65+ local function searchWord (source , pushResult , defMap , fileNotify )
6666 local key = guide .getKeyName (source )
67+ if not key then
68+ return
69+ end
70+
71+ local global = vm .getGlobalNode (source )
6772
6873 --- @param src parser.object
6974 local function checkDef (src )
@@ -75,42 +80,53 @@ local function searchField(source, pushResult, defMap, fileNotify)
7580 end
7681 end
7782
78- local pat = ' [:.]%s*' .. key
79-
8083 --- @async
8184 local function findWord (uri )
8285 local text = files .getText (uri )
8386 if not text then
8487 return
8588 end
86- if not text :match (pat ) then
89+ if not text :match (key ) then
8790 return
8891 end
8992 local state = files .getState (uri )
9093 if not state then
9194 return
9295 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
114130 end
115131
116132 searchInAllFiles (guide .getUri (source ), findWord , fileNotify )
@@ -165,18 +181,35 @@ local nodeSwitch = util.switch()
165181 return
166182 end
167183
168- searchField (source , pushResult , defMap , fileNotify )
184+ searchWord (source , pushResult , defMap , fileNotify )
169185 end )
170186 : case ' tablefield'
171187 : case ' tableindex'
188+ : case ' doc.field.name'
172189 --- @async
173190 : call (function (source , pushResult , defMap , fileNotify )
174- searchField (source , pushResult , defMap , fileNotify )
191+ searchWord (source , pushResult , defMap , fileNotify )
175192 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'
177210 --- @async
178211 : call (function (source , pushResult , defMap , fileNotify )
179- searchField (source , pushResult , defMap , fileNotify )
212+ searchWord (source , pushResult , defMap , fileNotify )
180213 end )
181214 : case ' function'
182215 : case ' doc.type.function'
@@ -216,7 +249,6 @@ function searchByParentNode(source, pushResult, defMap, fileNotify)
216249 nodeSwitch (source .type , source , pushResult , defMap , fileNotify )
217250end
218251
219- --- @async
220252local function searchByGlobal (source , pushResult )
221253 if source .type == ' field'
222254 or source .type == ' method'
0 commit comments