@@ -32,7 +32,7 @@ function gotosymbol(
32
32
localitems = localgotoitem (word, path, column, row, startrow, context)
33
33
isempty (localitems) || return Dict (
34
34
:error => false ,
35
- :items => map (Dict, localitems),
35
+ :items => map (Dict, localitems)
36
36
)
37
37
end
38
38
@@ -66,7 +66,7 @@ Dict(gotoitem::GotoItem) = Dict(
66
66
# ## local goto
67
67
68
68
function localgotoitem (word, path, column, row, startrow, context)
69
- word = first (split (word, ' .' )) # ignore dot accessors
69
+ word = first (split (word, ' .' )) # always ignore dot accessors
70
70
position = row - startrow
71
71
ls = locals (context, position, column)
72
72
filter! (ls) do l
@@ -86,31 +86,31 @@ localgotoitem(word, ::Nothing, column, row, startrow, context) = [] # when `path
86
86
function globalgotoitems (word, mod, text, path)
87
87
mod = getmodule (mod)
88
88
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
91
100
92
101
toplevelitems = toplevelgotoitems (word, mod, text, path)
93
102
94
- # only append methods that are not caught by `toplevelgotoitems`
103
+ # append method gotos that are not caught by `toplevelgotoitems`
104
+ ml = methods (val)
95
105
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))
98
107
append! (toplevelitems, methoditems)
99
108
end
100
109
101
110
# # module goto
102
111
103
- function modulegotoitems (word, mod):: Vector{GotoItem}
104
- mod = getfield′ (mod, Symbol (word))
105
- return mod isa Module ? [GotoItem (mod)] : []
106
- end
107
-
108
112
function 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)
114
114
GotoItem (string (mod), file, line - 1 )
115
115
end
116
116
@@ -120,16 +120,6 @@ const PathItemsMaps = Dict{String, Vector{ToplevelItem}}
120
120
const SYMBOLSCACHE = Dict {String, PathItemsMaps} ()
121
121
122
122
function 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
-
133
123
key = string (mod)
134
124
pathitemsmaps = if haskey (SYMBOLSCACHE, key)
135
125
SYMBOLSCACHE[key]
@@ -139,8 +129,8 @@ function toplevelgotoitems(word, mod, text, path)
139
129
140
130
ismacro (word) && (word = lstrip (word, ' @' ))
141
131
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)
144
134
push! (ret, GotoItem (path, item))
145
135
end
146
136
end
169
159
function _searchtoplevelitems (mod:: Module , pathitemsmaps:: PathItemsMaps )
170
160
entrypath, paths = modulefiles (mod) # Revise-like approach
171
161
if entrypath != = nothing
172
- for p ∈ [entrypath; paths]
162
+ for p in [entrypath; paths]
173
163
_searchtoplevelitems (p, pathitemsmaps)
174
164
end
175
165
else # if Revise-like approach fails, fallback to CSTParser-based approach
@@ -188,14 +178,13 @@ function _searchtoplevelitems(path::String, pathitemsmaps::PathItemsMaps)
188
178
push! (pathitemsmaps, pathitemsmap)
189
179
end
190
180
191
- # module-walk by CSTParser-based , looking for toplevel `installed` calls
181
+ # module-walk based on CSTParser, looking for toplevel `installed` calls
192
182
function _searchtoplevelitems (text:: String , path:: String , pathitemsmaps:: PathItemsMaps )
193
183
parsed = CSTParser. parse (text, true )
194
184
items = toplevelitems (parsed, text)
195
- pathitemsmap = path => items
196
- push! (pathitemsmaps, pathitemsmap)
185
+ push! (pathitemsmaps, path => items)
197
186
198
- # looking for toplevel `installed ` calls
187
+ # looking for toplevel `include ` calls
199
188
for item in items
200
189
if item isa ToplevelCall
201
190
expr = item. expr
@@ -278,7 +267,7 @@ function regeneratesymbols()
278
267
unloadedlen = length (unloaded)
279
268
total = loadedlen + unloadedlen
280
269
281
- for (i, mod) ∈ enumerate (Base. loaded_modules_array ())
270
+ for (i, mod) in enumerate (Base. loaded_modules_array ())
282
271
try
283
272
modstr = string (mod)
284
273
modstr == " __PackagePrecompilationStatementModule" && continue # will cause error
@@ -292,7 +281,7 @@ function regeneratesymbols()
292
281
end
293
282
end
294
283
295
- for (i, pkg) ∈ enumerate (unloaded)
284
+ for (i, pkg) in enumerate (unloaded)
296
285
try
297
286
path = Base. find_package (pkg)
298
287
text = read (path, String)
@@ -311,27 +300,19 @@ end
311
300
312
301
# # method goto
313
302
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))
322
304
323
305
# 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 )
328
309
unique (m -> (m. file, m. line), ms)
329
310
end
330
311
331
312
function GotoItem (m:: Method )
332
313
_, link = view (m)
333
314
sig = sprint (show, m)
334
- text = replace (sig, r" in .* at .*$ " => " " )
315
+ text = replace (sig, methodloc_regex => s " \g <sig> " )
335
316
file = link. file
336
317
line = link. line - 1
337
318
secondary = join (link. contents)
0 commit comments