Skip to content

Commit e175233

Browse files
committed
minor refactors
1 parent c0ec452 commit e175233

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

src/Atom.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ function __init__()
2222

2323
# HACK: overloading this allows us to open remote files
2424
InteractiveUtils.eval(quote
25-
function InteractiveUtils.edit(path::AbstractString, line::Integer=0)
25+
function InteractiveUtils.edit(path::AbstractString, line::Integer = 0)
2626
if endswith(path, ".jl")
27-
f = Base.find_source_file(path)
28-
f !== nothing && (path = f)
27+
f = Base.find_source_file(path)
28+
f !== nothing && (path = f)
2929
end
30-
$(msg)("openFile", Base.abspath(path), line-1)
30+
$(msg)("openFile", Base.abspath(path), line - 1)
3131
end
3232
end)
3333
end

src/goto.jl

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
147147
end
148148

149-
# entry method
149+
# entry methods
150150
function 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
159158
end
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
176170
end
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
191189
end
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)
198196
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)
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

Comments
 (0)