@@ -120,7 +120,7 @@ const PathItemsMaps = Dict{String, Vector{ToplevelItem}}
120
120
"""
121
121
Atom.SYMBOLSCACHE
122
122
123
- "module" (`String`) ⟶ "path" (`String`) ⟶ "symbols" (`Vector{ToplevelItem}`) map
123
+ "module" (`String`) ⟶ "path" (`String`) ⟶ "symbols" (`Vector{ToplevelItem}`) map.
124
124
125
125
!!! note
126
126
"module" should be canonical, i.e.: should be identical to names that are
@@ -146,57 +146,55 @@ function toplevelgotoitems(word, mod, path, text)
146
146
return ret
147
147
end
148
148
149
- # entry method
149
+ # entry methods
150
150
function collecttoplevelitems (mod:: Module , path:: String , text:: String )
151
- pathitemsmaps = PathItemsMaps ()
152
151
return if mod == Main || isuntitled (path)
153
152
# for `Main` module and unsaved editors, always use CSTPraser-based approach
154
153
# with a given buffer text, and don't check module validity
155
- _collecttoplevelitems! (nothing , path, text, pathitemsmaps )
154
+ __collecttoplevelitems (nothing , path, text)
156
155
else
157
- _collecttoplevelitems! (mod, pathitemsmaps )
156
+ _collecttoplevelitems (mod)
158
157
end
159
158
end
159
+ # when `path === nothing`, e.g.: called from docpane/workspace
160
+ collecttoplevelitems (mod:: Module , path:: Nothing , text:: String ) = _collecttoplevelitems (mod)
160
161
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 )
169
163
entrypath, paths = modulefiles (mod)
170
164
return if entrypath != = nothing # Revise-like approach
171
- _collecttoplevelitems! (stripdotprefixes (string (mod)), entrypath, paths, pathitemsmaps )
165
+ __collecttoplevelitems (stripdotprefixes (string (mod)), [ entrypath; paths] )
172
166
else # if Revise-like approach fails, fallback to CSTParser-based approach
173
167
entrypath, line = moduledefinition (mod)
174
- _collecttoplevelitems! (stripdotprefixes (string (mod)), entrypath, pathitemsmaps )
168
+ __collecttoplevelitems (stripdotprefixes (string (mod)), entrypath)
175
169
end
176
170
end
177
171
178
172
# 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
+
180
178
# ignore toplevel items outside of `mod`
181
179
items = toplevelitems (read (entrypath, String); mod = mod)
182
180
push! (pathitemsmaps, entrypath => items)
183
181
182
+ # collect symbols in included files (always in `mod`)
184
183
for path in paths
185
- # collect symbols in included files (always in `mod`)
186
184
items = toplevelitems (read (path, String); mod = mod, inmod = true )
187
185
push! (pathitemsmaps, path => items)
188
186
end
189
187
190
188
pathitemsmaps
191
189
end
192
190
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 )
195
193
isfile′ (entrypath) || return
196
194
text = read (entrypath, String)
197
- _collecttoplevelitems! (mod, entrypath, text, pathitemsmaps; inmod = inmod)
195
+ __collecttoplevelitems (mod, entrypath, text, pathitemsmaps; inmod = inmod)
198
196
end
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 )
200
198
items = toplevelitems (text; mod = mod, inmod = inmod)
201
199
push! (pathitemsmaps, entrypath => items)
202
200
@@ -209,7 +207,7 @@ function _collecttoplevelitems!(mod::Union{Nothing, String}, entrypath::String,
209
207
nextentrypath = joinpath (dirname (entrypath), nextfile)
210
208
isfile′ (nextentrypath) || continue
211
209
# `nextentrypath` is always in `mod`
212
- _collecttoplevelitems! (mod, nextentrypath, pathitemsmaps; inmod = true )
210
+ __collecttoplevelitems (mod, nextentrypath, pathitemsmaps; inmod = true )
213
211
end
214
212
end
215
213
end
@@ -300,7 +298,7 @@ function regeneratesymbols()
300
298
key == " __PackagePrecompilationStatementModule" && continue # will cause error
301
299
302
300
@logmsg - 1 " Symbols: $key ($i / $total )" progress= i/ total _id= id
303
- SYMBOLSCACHE[key] = collecttoplevelitems (mod, nothing , " " )
301
+ SYMBOLSCACHE[key] = _collecttoplevelitems (mod)
304
302
catch err
305
303
@error err
306
304
end
@@ -310,7 +308,7 @@ function regeneratesymbols()
310
308
try
311
309
@logmsg - 1 " Symbols: $pkg ($(i + loadedlen) / $total )" progress= (i+ loadedlen)/ total _id= id
312
310
path = Base. find_package (pkg)
313
- SYMBOLSCACHE[pkg] = _collecttoplevelitems! (pkg, path, PathItemsMaps () )
311
+ SYMBOLSCACHE[pkg] = __collecttoplevelitems (pkg, path)
314
312
catch err
315
313
@error err
316
314
end
0 commit comments