@@ -32,7 +32,7 @@ function gotosymbol(
3232 localitems = localgotoitem (word, path, column, row, startrow, context)
3333 isempty (localitems) || return Dict (
3434 :error => false ,
35- :items => map (Dict, localitems),
35+ :items => map (Dict, localitems)
3636 )
3737 end
3838
@@ -66,7 +66,7 @@ Dict(gotoitem::GotoItem) = Dict(
6666# ## local goto
6767
6868function localgotoitem (word, path, column, row, startrow, context)
69- word = first (split (word, ' .' )) # ignore dot accessors
69+ word = first (split (word, ' .' )) # always ignore dot accessors
7070 position = row - startrow
7171 ls = locals (context, position, column)
7272 filter! (ls) do l
@@ -86,31 +86,31 @@ localgotoitem(word, ::Nothing, column, row, startrow, context) = [] # when `path
8686function globalgotoitems (word, mod, text, path)
8787 mod = getmodule (mod)
8888
89- moduleitems = modulegotoitems (word, mod)
90- isempty (moduleitems) || return moduleitems
89+ # strip a dot-accessed module if exists
90+ identifiers = split (word, ' .' )
91+ head = string (identifiers[1 ])
92+ if head ≠ word && getfield′ (mod, head) isa Module
93+ # if `head` is a module, update `word` and `mod`
94+ nextword = join (identifiers[2 : end ], ' .' )
95+ return globalgotoitems (nextword, head, text, path)
96+ end
97+
98+ val = getfield′ (mod, word)
99+ val isa Module && return [GotoItem (val)] # module goto
91100
92101 toplevelitems = toplevelgotoitems (word, mod, text, path)
93102
94- # only append methods that are not caught by `toplevelgotoitems`
103+ # append method gotos that are not caught by `toplevelgotoitems`
104+ ml = methods (val)
95105 files = map (item -> item. file, toplevelitems)
96- methoditems = filter! (item -> item. file ∉ files, methodgotoitems (mod, word))
97-
106+ methoditems = filter! (item -> item. file ∉ files, methodgotoitems (ml))
98107 append! (toplevelitems, methoditems)
99108end
100109
101110# # module goto
102111
103- function modulegotoitems (word, mod):: Vector{GotoItem}
104- mod = getfield′ (mod, Symbol (word))
105- return mod isa Module ? [GotoItem (mod)] : []
106- end
107-
108112function GotoItem (mod:: Module )
109- file, line = if mod == Main
110- MAIN_MODULE_LOCATION[]
111- else
112- moduledefinition (mod)
113- end
113+ file, line = mod == Main ? MAIN_MODULE_LOCATION[] : moduledefinition (mod)
114114 GotoItem (string (mod), file, line - 1 )
115115end
116116
@@ -120,16 +120,6 @@ const PathItemsMaps = Dict{String, Vector{ToplevelItem}}
120120const SYMBOLSCACHE = Dict {String, PathItemsMaps} ()
121121
122122function toplevelgotoitems (word, mod, text, path)
123- # strip a dot-accessed module if exists
124- identifiers = split (word, ' .' )
125- head = identifiers[1 ]
126- if head ≠ word && (val = getfield′ (mod, string (head))) isa Module
127- # if `head` is a module, update `word` and `mod`
128- nextword = join (identifiers[2 : end ], ' .' )
129- nextmod = val
130- return toplevelgotoitems (nextword, nextmod, text, path)
131- end
132-
133123 key = string (mod)
134124 pathitemsmaps = if haskey (SYMBOLSCACHE, key)
135125 SYMBOLSCACHE[key]
@@ -139,8 +129,8 @@ function toplevelgotoitems(word, mod, text, path)
139129
140130 ismacro (word) && (word = lstrip (word, ' @' ))
141131 ret = Vector {GotoItem} ()
142- for (path, items) ∈ pathitemsmaps
143- for item ∈ filter (item -> filtertoplevelitem (word, item), items)
132+ for (path, items) in pathitemsmaps
133+ for item in filter (item -> filtertoplevelitem (word, item), items)
144134 push! (ret, GotoItem (path, item))
145135 end
146136 end
169159function _searchtoplevelitems (mod:: Module , pathitemsmaps:: PathItemsMaps )
170160 entrypath, paths = modulefiles (mod) # Revise-like approach
171161 if entrypath != = nothing
172- for p ∈ [entrypath; paths]
162+ for p in [entrypath; paths]
173163 _searchtoplevelitems (p, pathitemsmaps)
174164 end
175165 else # if Revise-like approach fails, fallback to CSTParser-based approach
@@ -188,14 +178,13 @@ function _searchtoplevelitems(path::String, pathitemsmaps::PathItemsMaps)
188178 push! (pathitemsmaps, pathitemsmap)
189179end
190180
191- # module-walk by CSTParser-based , looking for toplevel `installed` calls
181+ # module-walk based on CSTParser, looking for toplevel `installed` calls
192182function _searchtoplevelitems (text:: String , path:: String , pathitemsmaps:: PathItemsMaps )
193183 parsed = CSTParser. parse (text, true )
194184 items = toplevelitems (parsed, text)
195- pathitemsmap = path => items
196- push! (pathitemsmaps, pathitemsmap)
185+ push! (pathitemsmaps, path => items)
197186
198- # looking for toplevel `installed ` calls
187+ # looking for toplevel `include ` calls
199188 for item in items
200189 if item isa ToplevelCall
201190 expr = item. expr
@@ -278,7 +267,7 @@ function regeneratesymbols()
278267 unloadedlen = length (unloaded)
279268 total = loadedlen + unloadedlen
280269
281- for (i, mod) ∈ enumerate (Base. loaded_modules_array ())
270+ for (i, mod) in enumerate (Base. loaded_modules_array ())
282271 try
283272 modstr = string (mod)
284273 modstr == " __PackagePrecompilationStatementModule" && continue # will cause error
@@ -292,7 +281,7 @@ function regeneratesymbols()
292281 end
293282 end
294283
295- for (i, pkg) ∈ enumerate (unloaded)
284+ for (i, pkg) in enumerate (unloaded)
296285 try
297286 path = Base. find_package (pkg)
298287 text = read (path, String)
@@ -311,27 +300,19 @@ end
311300
312301# # method goto
313302
314- function methodgotoitems (mod, word):: Vector{GotoItem}
315- ms = @errs getmethods (mod, word)
316- if ms isa EvalError
317- []
318- else
319- map (GotoItem, aggregatemethods (ms))
320- end
321- end
303+ methodgotoitems (ml) = map (GotoItem, aggregatemethods (ml))
322304
323305# aggregate methods with default arguments to the ones with full arguments
324- aggregatemethods (f) = aggregatemethods (methods (f))
325- aggregatemethods (ms:: MethodList ) = aggregatemethods (collect (ms))
326- function aggregatemethods (ms:: Vector{Method} )
327- ms = sort (ms, by = m -> m. nargs, rev = true )
306+ function aggregatemethods (ml)
307+ ms = collect (ml)
308+ sort! (ms, by = m -> m. nargs, rev = true )
328309 unique (m -> (m. file, m. line), ms)
329310end
330311
331312function GotoItem (m:: Method )
332313 _, link = view (m)
333314 sig = sprint (show, m)
334- text = replace (sig, r" in .* at .*$ " => " " )
315+ text = replace (sig, methodloc_regex => s " \g <sig> " )
335316 file = link. file
336317 line = link. line - 1
337318 secondary = join (link. contents)
0 commit comments