@@ -120,7 +120,7 @@ const PathItemsMaps = Dict{String, Vector{ToplevelItem}}
120120"""
121121 Atom.SYMBOLSCACHE
122122
123- "module" (`String`) ⟶ "path" (`String`) ⟶ "symbols" (`Vector{ToplevelItem}`) map
123+ "module" (`String`) ⟶ "path" (`String`) ⟶ "symbols" (`Vector{ToplevelItem}`) map.
124124
125125!!! note
126126 "module" should be canonical, i.e.: should be identical to names that are
@@ -146,57 +146,55 @@ function toplevelgotoitems(word, mod, path, text)
146146 return ret
147147end
148148
149- # entry method
149+ # entry methods
150150function collecttoplevelitems (mod:: Module , path:: String , text:: String )
151- pathitemsmaps = PathItemsMaps ()
152151 return if mod == Main || isuntitled (path)
153152 # for `Main` module and unsaved editors, always use CSTPraser-based approach
154153 # with a given buffer text, and don't check module validity
155- _collecttoplevelitems! (nothing , path, text, pathitemsmaps )
154+ __collecttoplevelitems (nothing , path, text)
156155 else
157- _collecttoplevelitems! (mod, pathitemsmaps )
156+ _collecttoplevelitems (mod)
158157 end
159158end
159+ # when `path === nothing`, e.g.: called from docpane/workspace
160+ collecttoplevelitems (mod:: Module , path:: Nothing , text:: String ) = _collecttoplevelitems (mod)
160161
161- # entry method when called from docpane/workspace
162- function collecttoplevelitems (mod:: Module , path:: Nothing , text:: String )
163- pathitemsmaps = PathItemsMaps ()
164- _collecttoplevelitems! (mod, pathitemsmaps)
165- end
166-
167- # sub entry method
168- function _collecttoplevelitems! (mod:: Module , pathitemsmaps:: PathItemsMaps )
162+ function _collecttoplevelitems (mod:: Module )
169163 entrypath, paths = modulefiles (mod)
170164 return if entrypath != = nothing # Revise-like approach
171- _collecttoplevelitems! (stripdotprefixes (string (mod)), entrypath, paths, pathitemsmaps )
165+ __collecttoplevelitems (stripdotprefixes (string (mod)), [ entrypath; paths] )
172166 else # if Revise-like approach fails, fallback to CSTParser-based approach
173167 entrypath, line = moduledefinition (mod)
174- _collecttoplevelitems! (stripdotprefixes (string (mod)), entrypath, pathitemsmaps )
168+ __collecttoplevelitems (stripdotprefixes (string (mod)), entrypath)
175169 end
176170end
177171
178172# module-walk via Revise-like approach
179- function _collecttoplevelitems! (mod:: Union{Nothing, String} , entrypath:: String , paths:: Vector{String} , pathitemsmaps:: PathItemsMaps )
173+ function __collecttoplevelitems (mod:: Union{Nothing, String} , paths:: Vector{String} )
174+ pathitemsmaps = PathItemsMaps ()
175+
176+ entrypath, paths = paths[1 ], paths[2 : end ]
177+
180178 # ignore toplevel items outside of `mod`
181179 items = toplevelitems (read (entrypath, String); mod = mod)
182180 push! (pathitemsmaps, entrypath => items)
183181
182+ # collect symbols in included files (always in `mod`)
184183 for path in paths
185- # collect symbols in included files (always in `mod`)
186184 items = toplevelitems (read (path, String); mod = mod, inmod = true )
187185 push! (pathitemsmaps, path => items)
188186 end
189187
190188 pathitemsmaps
191189end
192190
193- # module-walk based on CSTParser, looking for toplevel `installed ` calls
194- function _collecttoplevelitems! (mod:: Union{Nothing, String} , entrypath:: String , pathitemsmaps:: PathItemsMaps ; inmod = false )
191+ # module-walk based on CSTParser, looking for toplevel `included ` calls
192+ function __collecttoplevelitems (mod:: Union{Nothing, String} , entrypath:: String , pathitemsmaps:: PathItemsMaps = PathItemsMaps () ; inmod = false )
195193 isfile′ (entrypath) || return
196194 text = read (entrypath, String)
197- _collecttoplevelitems! (mod, entrypath, text, pathitemsmaps; inmod = inmod)
195+ __collecttoplevelitems (mod, entrypath, text, pathitemsmaps; inmod = inmod)
198196end
199- function _collecttoplevelitems! (mod:: Union{Nothing, String} , entrypath:: String , text:: String , pathitemsmaps:: PathItemsMaps ; inmod = false )
197+ function __collecttoplevelitems (mod:: Union{Nothing, String} , entrypath:: String , text:: String , pathitemsmaps:: PathItemsMaps = PathItemsMaps () ; inmod = false )
200198 items = toplevelitems (text; mod = mod, inmod = inmod)
201199 push! (pathitemsmaps, entrypath => items)
202200
@@ -209,7 +207,7 @@ function _collecttoplevelitems!(mod::Union{Nothing, String}, entrypath::String,
209207 nextentrypath = joinpath (dirname (entrypath), nextfile)
210208 isfile′ (nextentrypath) || continue
211209 # `nextentrypath` is always in `mod`
212- _collecttoplevelitems! (mod, nextentrypath, pathitemsmaps; inmod = true )
210+ __collecttoplevelitems (mod, nextentrypath, pathitemsmaps; inmod = true )
213211 end
214212 end
215213 end
@@ -300,7 +298,7 @@ function regeneratesymbols()
300298 key == " __PackagePrecompilationStatementModule" && continue # will cause error
301299
302300 @logmsg - 1 " Symbols: $key ($i / $total )" progress= i/ total _id= id
303- SYMBOLSCACHE[key] = collecttoplevelitems (mod, nothing , " " )
301+ SYMBOLSCACHE[key] = _collecttoplevelitems (mod)
304302 catch err
305303 @error err
306304 end
@@ -310,7 +308,7 @@ function regeneratesymbols()
310308 try
311309 @logmsg - 1 " Symbols: $pkg ($(i + loadedlen) / $total )" progress= (i+ loadedlen)/ total _id= id
312310 path = Base. find_package (pkg)
313- SYMBOLSCACHE[pkg] = _collecttoplevelitems! (pkg, path, PathItemsMaps () )
311+ SYMBOLSCACHE[pkg] = __collecttoplevelitems (pkg, path)
314312 catch err
315313 @error err
316314 end
0 commit comments