@codua/codeoutline-win32-x64 0.2.4 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -3
- package/README.zh-CN.md +40 -2
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/affected.lua +145 -0
- package/scripts/codeoutline/automatic_events.lua +202 -0
- package/scripts/codeoutline/cache_repairs.lua +47 -0
- package/scripts/codeoutline/callers.lua +56 -16
- package/scripts/codeoutline/cargo_toml.lua +125 -0
- package/scripts/codeoutline/command.lua +26 -4
- package/scripts/codeoutline/common.lua +65 -9
- package/scripts/codeoutline/completion.lua +221 -65
- package/scripts/codeoutline/coverage.lua +63 -0
- package/scripts/codeoutline/cpp_bindings.lua +151 -0
- package/scripts/codeoutline/cpp_fragments.lua +143 -0
- package/scripts/codeoutline/cpp_implementations.lua +340 -0
- package/scripts/codeoutline/cpp_includes.lua +156 -0
- package/scripts/codeoutline/cpp_macros.lua +279 -0
- package/scripts/codeoutline/cpp_receivers.lua +342 -0
- package/scripts/codeoutline/cpp_types.lua +456 -0
- package/scripts/codeoutline/csharp_bindings.lua +498 -0
- package/scripts/codeoutline/definition_candidates.lua +180 -0
- package/scripts/codeoutline/dispatch_aliases.lua +479 -0
- package/scripts/codeoutline/documents.lua +32 -9
- package/scripts/codeoutline/explore.lua +274 -119
- package/scripts/codeoutline/external_headers.lua +171 -0
- package/scripts/codeoutline/foreign.lua +79 -14
- package/scripts/codeoutline/foreign_lua.lua +146 -19
- package/scripts/codeoutline/function_values.lua +69 -0
- package/scripts/codeoutline/go_methods.lua +931 -0
- package/scripts/codeoutline/go_modules.lua +329 -0
- package/scripts/codeoutline/graph.lua +346 -63
- package/scripts/codeoutline/implementations.lua +403 -0
- package/scripts/codeoutline/index.lua +165 -27
- package/scripts/codeoutline/index_worker.lua +11 -4
- package/scripts/codeoutline/indirect.lua +116 -40
- package/scripts/codeoutline/js_evidence.lua +32 -3
- package/scripts/codeoutline/js_resolution.lua +72 -10
- package/scripts/codeoutline/js_workspace.lua +325 -0
- package/scripts/codeoutline/lang/c.lua +15 -2
- package/scripts/codeoutline/lang/cpp.lua +7 -4
- package/scripts/codeoutline/lang/csharp.lua +15 -3
- package/scripts/codeoutline/lang/js.lua +56 -20
- package/scripts/codeoutline/lang/rust.lua +9 -1
- package/scripts/codeoutline/language_detect.lua +100 -0
- package/scripts/codeoutline/lsp.lua +173 -23
- package/scripts/codeoutline/lua_bindings.lua +228 -54
- package/scripts/codeoutline/lua_callback_loops.lua +210 -0
- package/scripts/codeoutline/lua_literal.lua +38 -0
- package/scripts/codeoutline/main.lua +32 -7
- package/scripts/codeoutline/mcp.lua +52 -9
- package/scripts/codeoutline/navigation.lua +593 -147
- package/scripts/codeoutline/on_demand.lua +93 -0
- package/scripts/codeoutline/ordinary_bindings.lua +396 -0
- package/scripts/codeoutline/parse.lua +18 -2
- package/scripts/codeoutline/parse_pool.lua +1 -1
- package/scripts/codeoutline/parse_worker.lua +1 -1
- package/scripts/codeoutline/python_bindings.lua +112 -0
- package/scripts/codeoutline/query_filters.lua +65 -0
- package/scripts/codeoutline/query_report.lua +135 -8
- package/scripts/codeoutline/resolution.lua +23 -0
- package/scripts/codeoutline/rules.lua +127 -0
- package/scripts/codeoutline/rust_packages.lua +203 -0
- package/scripts/codeoutline/rust_resolution.lua +301 -0
- package/scripts/codeoutline/search_ranking.lua +70 -0
- package/scripts/codeoutline/service.lua +47 -7
- package/scripts/codeoutline/shared_events.lua +369 -0
- package/scripts/codeoutline/static_dispatch.lua +569 -0
- package/scripts/codeoutline/text.lua +3 -2
- package/scripts/codeoutline/ts_implementations.lua +81 -0
- package/scripts/codeoutline/type_bases.lua +61 -0
- package/scripts/codeoutline/type_hierarchy.lua +324 -0
- package/scripts/codeoutline/type_references.lua +290 -0
- package/scripts/codeoutline/type_uses.lua +260 -0
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -11,15 +11,21 @@ local documents = require('codeoutline.documents')
|
|
|
11
11
|
local paths = require('codeoutline.path')
|
|
12
12
|
local control = require('codeoutline.control')
|
|
13
13
|
local lsp = require('codeoutline.lsp')
|
|
14
|
+
local parse = require('codeoutline.parse')
|
|
14
15
|
-- Reference scans stop at a result count or time budget and report truncation.
|
|
15
|
-
local M = { MAX_RESULTS = 1000, MAX_HOVER = 3, SCAN_SECONDS = 3, POSITION_SECONDS = 2,
|
|
16
|
+
local M = { MAX_RESULTS = 1000, MAX_HOVER = 3, SCAN_SECONDS = 3, POSITION_SECONDS = 2,
|
|
17
|
+
MAX_FILE_BYTES = 1048576, CACHE_FILES = 64 }
|
|
16
18
|
|
|
17
19
|
local sessions = {}
|
|
20
|
+
-- Pure per-file binding evidence, shared across navigation requests. Its
|
|
21
|
+
-- existing 16-file/about-8-MiB FIFO is keyed by source-node identity; each
|
|
22
|
+
-- query still validates source before reusing a shared entry.
|
|
23
|
+
local binding_cache = { entries = {}, order = {}, bytes = 0 }
|
|
18
24
|
local ANY = setmetatable({}, { __index = function() return true end })
|
|
19
25
|
-- Bare identifiers bind only nearby, except type names used across files.
|
|
20
26
|
local TYPES = { class = true, struct = true, union = true, interface = true, enum = true, record = true,
|
|
21
|
-
typedef = true, namespace = true, annotation_type = true }
|
|
22
|
-
--
|
|
27
|
+
typedef = true, namespace = true, annotation_type = true, trait = true }
|
|
28
|
+
-- Call hierarchy covers callables; type references use explicit type-site evidence.
|
|
23
29
|
local REFERENCE = { ['function'] = true, method = true, macro = true, constructor = true,
|
|
24
30
|
prototype = true, destructor = true }
|
|
25
31
|
local CALLS = { ['function'] = true, method = true, macro = true, constructor = true,
|
|
@@ -68,13 +74,18 @@ end
|
|
|
68
74
|
-- files. Overlay files and nodes take ids after every resident one; masked
|
|
69
75
|
-- resident nodes drop out of name lists, which keep path and node order.
|
|
70
76
|
-- Nothing is written to the resident tables.
|
|
71
|
-
local function view(session, root)
|
|
77
|
+
local function view(session, root, include_paths, only)
|
|
72
78
|
local idx = service.resident(root)
|
|
73
79
|
local G = idx:symbols()
|
|
74
80
|
local V = setmetatable({ root = root, idx = idx, drafts = {}, disk = {}, dep_cache = {}, new_files = {},
|
|
75
81
|
next_file = G.next_file, next_node = G.next_node, next_dir = G.next_dir }, { __index = G })
|
|
76
82
|
V.js_context = require('codeoutline.js_resolution').context(V)
|
|
83
|
+
V.js_context.include_paths = include_paths
|
|
77
84
|
V.js_context.lua = require('codeoutline.lua_bindings').context(V)
|
|
85
|
+
V.js_context.ordinary = require('codeoutline.ordinary_bindings').context(V, V.js_context, function(f)
|
|
86
|
+
return V.drafts[f] and V.drafts[f].source
|
|
87
|
+
end, { cache = binding_cache, parsed = function(f) return M.full(V, f) end })
|
|
88
|
+
V.js_context.lua.ordinary = V.js_context.ordinary
|
|
78
89
|
for _, name in ipairs({ 'files', 'nodes', 'node_file', 'id_of', 'file_index', 'file_dir' }) do
|
|
79
90
|
V[name] = setmetatable({}, { __index = G[name] })
|
|
80
91
|
end
|
|
@@ -83,6 +94,11 @@ local function view(session, root)
|
|
|
83
94
|
local rel = doc.path and relative(root, doc.path)
|
|
84
95
|
local f = rel and V.file_index[rel]
|
|
85
96
|
if not rel or (f and V.drafts[f]) then return f end
|
|
97
|
+
local hint = f and V.files[f].cpp_fragment
|
|
98
|
+
and not require('codeoutline.language_detect').resolve('', doc.language, false) and V.files[f].language or nil
|
|
99
|
+
if doc.indexed_language ~= hint then
|
|
100
|
+
doc.indexed_language, doc.parsed, doc.full, doc.branch_tokens = hint, nil, nil, nil
|
|
101
|
+
end
|
|
86
102
|
local rec = doc:parse()
|
|
87
103
|
if not rec.language then return nil end
|
|
88
104
|
if f then masked[f] = true
|
|
@@ -138,7 +154,7 @@ local function view(session, root)
|
|
|
138
154
|
local drafts = {}
|
|
139
155
|
for _, doc in pairs(sessions[session] or {}) do drafts[#drafts + 1] = doc end
|
|
140
156
|
table.sort(drafts, function(a, b) return a.uri < b.uri end)
|
|
141
|
-
for _, doc in ipairs(drafts) do V.add(doc) end
|
|
157
|
+
for _, doc in ipairs(drafts) do if not only or doc.uri == only then V.add(doc) end end
|
|
142
158
|
return V
|
|
143
159
|
end
|
|
144
160
|
|
|
@@ -148,20 +164,7 @@ end
|
|
|
148
164
|
local function deps(V, f)
|
|
149
165
|
local entry = V.dep_cache[f]
|
|
150
166
|
if not entry then
|
|
151
|
-
local direct, paired = graph.
|
|
152
|
-
if C_FAMILY[V.files[f].language] then
|
|
153
|
-
local queue = {}
|
|
154
|
-
for g in pairs(direct) do queue[#queue + 1] = g end
|
|
155
|
-
local i = 1
|
|
156
|
-
while i <= #queue and #queue < M.MAX_INCLUDES do
|
|
157
|
-
local more, sources = graph.dependencies(V, queue[i])
|
|
158
|
-
for h in pairs(sources) do paired[h] = true end
|
|
159
|
-
for h in pairs(more) do
|
|
160
|
-
if not direct[h] and h ~= f then direct[h] = true; queue[#queue + 1] = h end
|
|
161
|
-
end
|
|
162
|
-
i = i + 1
|
|
163
|
-
end
|
|
164
|
-
end
|
|
167
|
+
local direct, paired = graph.visible_dependencies(V, f, V.js_context)
|
|
165
168
|
entry = { direct, paired }
|
|
166
169
|
V.dep_cache[f] = entry
|
|
167
170
|
end
|
|
@@ -186,13 +189,25 @@ local function recursive(node, recv)
|
|
|
186
189
|
end
|
|
187
190
|
|
|
188
191
|
-- Targets of one occurrence of name in file f, enclosed by node index from.
|
|
189
|
-
local function resolve_site(V, f, from, name, kind, recv, evidence)
|
|
192
|
+
local function resolve_site(V, f, from, name, kind, recv, evidence, offset, index, cursor_line)
|
|
193
|
+
if kind == 'type' then
|
|
194
|
+
local site = type(evidence) == 'table' and evidence
|
|
195
|
+
if not site then return {}, 'unsupported type position' end
|
|
196
|
+
return require('codeoutline.type_references').resolve(V, f, from > 0 and V.id_of[f][from] or nil, site, V.js_context)
|
|
197
|
+
end
|
|
198
|
+
if index then evidence = V.js_context.ordinary.evidence(f, index) end
|
|
199
|
+
if V.files[f].language == 'go' and offset and evidence ~= 'go:?' and not (evidence and evidence:match('^go:expr:')) then
|
|
200
|
+
if recv then evidence = 'go:recv:' .. offset
|
|
201
|
+
elseif kind == 'member_call' or kind == 'member_symbol' then evidence = 'go:expr:' .. offset end
|
|
202
|
+
end
|
|
190
203
|
local src = from > 0 and V.id_of[f][from] or nil
|
|
191
204
|
local direct, paired = deps(V, f)
|
|
192
205
|
local rkind, accept = kind, nil
|
|
193
206
|
if kind == 'symbol' then rkind, accept = 'call', ANY
|
|
194
207
|
elseif kind == 'member_symbol' then rkind, accept = 'member_call', ANY end
|
|
195
|
-
local
|
|
208
|
+
local site_line = index and V.files[f].refs.line[index] or cursor_line
|
|
209
|
+
local targets, reason, macro_state = graph.resolve(V, f, src, name, rkind, recv or nil, direct, paired, accept, evidence, V.js_context, site_line)
|
|
210
|
+
targets = targets or {}
|
|
196
211
|
if kind == 'symbol' then
|
|
197
212
|
local kept = {}
|
|
198
213
|
for _, id in ipairs(targets) do
|
|
@@ -204,13 +219,29 @@ local function resolve_site(V, f, from, name, kind, recv, evidence)
|
|
|
204
219
|
targets = kept
|
|
205
220
|
end
|
|
206
221
|
-- The resolver never binds a ref to its enclosing node, which hides recursion.
|
|
207
|
-
if #targets == 0 and src and V.nodes[src].name == name and (kind == 'call' or recursive(V.nodes[src], recv)) then
|
|
222
|
+
if #targets == 0 and reason ~= 'unknown or unsupported macro visibility' and src and V.nodes[src].name == name and (kind == 'call' or recursive(V.nodes[src], recv)) then
|
|
208
223
|
targets = { src }
|
|
209
224
|
end
|
|
210
225
|
-- Definitions too far apart to choose between: a visible prototype still
|
|
211
226
|
-- names the function, and going to its definition lists them all.
|
|
212
227
|
if #targets == 0 and (kind == 'call' or kind == 'ref') then
|
|
213
|
-
targets = graph.resolve(V, f, src, name, kind, recv or nil, direct, paired, PROTOTYPE, evidence, V.js_context) or {}
|
|
228
|
+
targets = graph.resolve(V, f, src, name, kind, recv or nil, direct, paired, PROTOTYPE, evidence, V.js_context, site_line) or {}
|
|
229
|
+
end
|
|
230
|
+
-- A native object: the local's initializer chain names the metatable whose
|
|
231
|
+
-- methods the C side registers (`local pool = mod.open()`, then `pool:read()`).
|
|
232
|
+
if #targets == 0 and recv and (kind == 'member_call' or kind == 'member_symbol')
|
|
233
|
+
and V.files[f].language == 'lua' then
|
|
234
|
+
local bindings = require('codeoutline.lua_bindings')
|
|
235
|
+
local ctx = V.js_context.lua
|
|
236
|
+
local rec, T
|
|
237
|
+
if offset and require('codeoutline.foreign').has_candidates(V, ctx) then rec, T = M.full(V, f) end
|
|
238
|
+
if T then
|
|
239
|
+
local target = bindings.receiver(V, rec, T, recv, offset, V.js_context.lua)
|
|
240
|
+
for _, entry in ipairs(bindings.member(V, target, name)) do
|
|
241
|
+
local id = V.id_of[entry.file] and V.id_of[entry.file][entry.index]
|
|
242
|
+
if id then targets[#targets + 1] = id end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
214
245
|
end
|
|
215
246
|
if C_FAMILY[V.files[f].language] then
|
|
216
247
|
-- C binds only what its includes make visible; a lone far definition
|
|
@@ -223,41 +254,60 @@ local function resolve_site(V, f, from, name, kind, recv, evidence)
|
|
|
223
254
|
end
|
|
224
255
|
targets = kept
|
|
225
256
|
end
|
|
226
|
-
return targets
|
|
257
|
+
return targets, reason, evidence, macro_state
|
|
227
258
|
end
|
|
228
259
|
|
|
229
260
|
-- What the cursor names: a declaration, an indexed reference, or another identifier.
|
|
230
|
-
local function find_cursor(doc, offset, strict)
|
|
231
|
-
local rec = doc:parse()
|
|
261
|
+
local function find_cursor(doc, offset, strict, parsed)
|
|
262
|
+
local rec = parsed or doc:parse()
|
|
232
263
|
local function inside(a, b) return a <= offset and (offset < b or (not strict and offset == b)) end
|
|
233
264
|
for n, node in ipairs(rec.nodes) do
|
|
234
265
|
if node.name_start and inside(node.name_start, node.name_end) then
|
|
235
266
|
return { decl = n, name = node.name, first = node.name_start, last = node.name_end }
|
|
236
267
|
end
|
|
237
268
|
end
|
|
269
|
+
for _, site in ipairs(rec.type_sites or {}) do
|
|
270
|
+
if inside(site.first, site.last) then
|
|
271
|
+
return { from = site.from, name = site.name, kind = 'type', recv = site.recv, evidence = site,
|
|
272
|
+
first = site.first, last = site.last }
|
|
273
|
+
end
|
|
274
|
+
end
|
|
238
275
|
local refs = rec.refs
|
|
239
276
|
if refs and refs.start then
|
|
240
277
|
for i = 1, #refs.name do
|
|
241
278
|
local a = refs.start[i]
|
|
242
279
|
if a and inside(a, refs.stop[i]) then
|
|
243
280
|
return { from = refs.from[i], name = refs.name[i], kind = refs.kind[i], recv = refs.recv[i],
|
|
244
|
-
evidence = refs.lua_binding and refs.lua_binding[i] or refs.js_receiver and refs.js_receiver[i],
|
|
245
|
-
first = a, last = refs.stop[i] }
|
|
281
|
+
evidence = refs.binding and refs.binding[i] or refs.lua_binding and refs.lua_binding[i] or refs.js_receiver and refs.js_receiver[i],
|
|
282
|
+
first = a, last = refs.stop[i], index = i }
|
|
246
283
|
end
|
|
247
284
|
end
|
|
248
285
|
end
|
|
249
286
|
end
|
|
250
287
|
|
|
251
|
-
local function cursor(doc, offset)
|
|
288
|
+
local function cursor(doc, offset, V, f, include_inactive)
|
|
252
289
|
local found = find_cursor(doc, offset, true) or find_cursor(doc, offset, false)
|
|
290
|
+
if found and found.decl then return found end
|
|
291
|
+
local rec, T
|
|
292
|
+
if V then rec, T = M.full(V, f) end
|
|
293
|
+
local typed = rec and (find_cursor(doc, offset, true, rec) or find_cursor(doc, offset, false, rec))
|
|
294
|
+
if typed then return typed end
|
|
253
295
|
if found then return found end
|
|
254
|
-
|
|
296
|
+
rec = rec or doc:parse()
|
|
297
|
+
T = T or doc:tokens()
|
|
255
298
|
if not T then return nil end
|
|
256
|
-
local
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
299
|
+
local function token_at(tokens)
|
|
300
|
+
local hit
|
|
301
|
+
for i = 1, tokens.n do
|
|
302
|
+
local a = tokens.s[i] - 1
|
|
303
|
+
if a > offset then break end
|
|
304
|
+
if tokens.k[i] == 'id' and offset <= tokens.e[i] then hit = i end
|
|
305
|
+
end
|
|
306
|
+
return hit
|
|
307
|
+
end
|
|
308
|
+
local t = token_at(T)
|
|
309
|
+
if not t and include_inactive and C_FAMILY[rec.language] then
|
|
310
|
+
T = doc:tokens(true); t = token_at(T)
|
|
261
311
|
end
|
|
262
312
|
if not t then return nil end
|
|
263
313
|
local kind, recv = 'symbol', nil
|
|
@@ -277,20 +327,106 @@ local function cursor(doc, offset)
|
|
|
277
327
|
from, span = n, node.end_byte - node.start_byte
|
|
278
328
|
end
|
|
279
329
|
end
|
|
280
|
-
|
|
330
|
+
local evidence
|
|
331
|
+
if rec.language == 'csharp' then
|
|
332
|
+
local first = t
|
|
333
|
+
while (T:text(first - 1) == '.' or T:text(first - 1) == '::') and T.k[first - 2] == 'id' do first = first - 2 end
|
|
334
|
+
local name = require('codeoutline.csharp_bindings').name(T.src:sub(T.s[first], T.e[t]))
|
|
335
|
+
evidence = name and 'cs:name:' .. name .. '\0' .. (T.s[first] - 1)
|
|
336
|
+
elseif C_FAMILY[rec.language] then
|
|
337
|
+
evidence = require('codeoutline.cpp_receivers').evidence(T, t)
|
|
338
|
+
if not evidence and rec.language == 'cpp' and (not recv or T:text(t - 1) == '::') then
|
|
339
|
+
evidence = require('codeoutline.cpp_types').evidence(T, t)
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
return { from = from, name = T:text(t), kind = kind, recv = recv, first = T.s[t] - 1, last = T.e[t], evidence = evidence }
|
|
281
343
|
end
|
|
282
344
|
|
|
283
345
|
-- Source document for file f: its overlay, else the disk file read once per request.
|
|
284
346
|
local function source_doc(V, f)
|
|
285
|
-
if V.drafts[f] then return V.drafts[f] end
|
|
347
|
+
if V.drafts and V.drafts[f] then return V.drafts[f] end
|
|
348
|
+
local rec = V.files[f]
|
|
349
|
+
local indexed = rec.crc ~= nil and rec or nil
|
|
350
|
+
if not V.disk then return V.root and documents.read(V.root .. '/' .. rec.path, indexed) end
|
|
286
351
|
local doc = V.disk[f]
|
|
287
352
|
if doc == nil then
|
|
288
|
-
doc = documents.read(V.idx:abs(
|
|
353
|
+
doc = documents.read(V.idx:abs(rec.path), indexed) or false
|
|
289
354
|
V.disk[f] = doc
|
|
290
355
|
end
|
|
291
356
|
return doc or nil
|
|
292
357
|
end
|
|
293
358
|
|
|
359
|
+
-- Full parse (record plus tokens) of one file, cached per record. Shared with
|
|
360
|
+
-- completion, which needs tokens for types this index does not store.
|
|
361
|
+
local full_cache, full_order = setmetatable({}, { __mode = 'k' }), {}
|
|
362
|
+
local function cache_full(key, entry)
|
|
363
|
+
if not full_cache[key] then full_order[#full_order + 1] = key end
|
|
364
|
+
full_cache[key] = entry
|
|
365
|
+
while #full_order > M.CACHE_FILES do full_cache[table.remove(full_order, 1)] = nil end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
function M.full(V, f, native)
|
|
369
|
+
local draft = V.drafts and V.drafts[f]
|
|
370
|
+
if draft then
|
|
371
|
+
draft.full = draft.full or {}
|
|
372
|
+
local entry = draft.full
|
|
373
|
+
if not entry.rec or native and not entry.foreign then
|
|
374
|
+
entry.rec, entry.tokens = parse.parse_tokens(draft.path or V.files[f].path, draft.source,
|
|
375
|
+
{ foreign = native, language = draft:parse().language, ordinary_bindings = true })
|
|
376
|
+
entry.foreign = native
|
|
377
|
+
end
|
|
378
|
+
return entry.rec, entry.tokens, draft
|
|
379
|
+
end
|
|
380
|
+
local key = V.files[f]
|
|
381
|
+
local entry = full_cache[key]
|
|
382
|
+
if entry == nil or not entry.tokens or native and not entry.foreign then
|
|
383
|
+
if (key.size or 0) > M.MAX_FILE_BYTES then return nil end
|
|
384
|
+
local doc = source_doc(V, f)
|
|
385
|
+
-- Read/parse failures are transient, unlike a successful empty result.
|
|
386
|
+
if not doc then return nil end
|
|
387
|
+
local rec, tokens = parse.parse_tokens(key.path, doc.source,
|
|
388
|
+
{ foreign = native, language = key.language, ordinary_bindings = true })
|
|
389
|
+
if not rec then return nil end
|
|
390
|
+
entry = { rec = rec, tokens = tokens, foreign = native }
|
|
391
|
+
cache_full(key, entry)
|
|
392
|
+
end
|
|
393
|
+
if not entry then return nil end
|
|
394
|
+
return entry.rec, entry.tokens
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
-- A target's exact positions need a full parse too. Reuse the same bounded
|
|
398
|
+
-- cache as completion/details instead of reparsing large headers on every
|
|
399
|
+
-- definition/hover/reference request. Callers must obtain doc from source_doc
|
|
400
|
+
-- first: it validates the on-disk size/checksum even on a cache hit. Drafts
|
|
401
|
+
-- keep their own versioned parse and never enter this shared cache.
|
|
402
|
+
local function position_record(V, f, doc)
|
|
403
|
+
if V.drafts[f] or (V.files[f].size or #doc.source) > M.MAX_FILE_BYTES then return doc:parse() end
|
|
404
|
+
local key = V.files[f]
|
|
405
|
+
local entry = full_cache[key]
|
|
406
|
+
if not entry then
|
|
407
|
+
entry = { rec = doc:parse() }
|
|
408
|
+
cache_full(key, entry)
|
|
409
|
+
end
|
|
410
|
+
return entry.rec
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
-- Restore display/type details without attaching them to resident index nodes.
|
|
414
|
+
function M.detail(V, f, node)
|
|
415
|
+
if node.sig then return node end
|
|
416
|
+
local rec = M.full(V, f)
|
|
417
|
+
if not rec then return node end
|
|
418
|
+
if not rec.detail_nodes then
|
|
419
|
+
local map = {}
|
|
420
|
+
for n, original in ipairs(V.files[f].nodes) do
|
|
421
|
+
local current = rec.nodes[n]
|
|
422
|
+
if current and current.name == original.name and current.qualified == original.qualified
|
|
423
|
+
and current.line == original.line and current.kind == original.kind then map[original] = current end
|
|
424
|
+
end
|
|
425
|
+
rec.detail_nodes = map
|
|
426
|
+
end
|
|
427
|
+
return rec.detail_nodes[node] or node
|
|
428
|
+
end
|
|
429
|
+
|
|
294
430
|
local function uri_of(V, f)
|
|
295
431
|
local doc = source_doc(V, f)
|
|
296
432
|
return doc and doc.uri or documents.uri(V.idx:abs(V.files[f].path))
|
|
@@ -306,7 +442,7 @@ local function locate(V, id)
|
|
|
306
442
|
local n, f = index_of(V, id)
|
|
307
443
|
local node, doc = V.nodes[id], source_doc(V, f)
|
|
308
444
|
if not doc then return nil end
|
|
309
|
-
local nodes = doc
|
|
445
|
+
local nodes = position_record(V, f, doc).nodes
|
|
310
446
|
local hit = nodes[n]
|
|
311
447
|
if hit and hit.name == node.name and hit.qualified == node.qualified and hit.name_start then return doc, hit end
|
|
312
448
|
hit = nil
|
|
@@ -328,7 +464,7 @@ local function item(V, id)
|
|
|
328
464
|
local loc, doc, hit = location(V, id)
|
|
329
465
|
local node = V.nodes[id]
|
|
330
466
|
local n, f = index_of(V, id)
|
|
331
|
-
return { name = node.name, kind = lsp.symbol_kind(node), detail = node.sig or node.qualified, uri = loc.uri,
|
|
467
|
+
return { name = node.name, kind = lsp.symbol_kind(node), detail = (hit and hit.sig) or node.sig or node.qualified, uri = loc.uri,
|
|
332
468
|
range = hit and doc:range(hit.start_byte, hit.end_byte) or loc.range, selectionRange = loc.range,
|
|
333
469
|
data = { root = V.root, path = V.files[f].path, index = n, name = node.name, qualified = node.qualified } }
|
|
334
470
|
end
|
|
@@ -359,7 +495,7 @@ end
|
|
|
359
495
|
local function site_range(V, f, i)
|
|
360
496
|
local doc = source_doc(V, f)
|
|
361
497
|
if not doc then return nil end
|
|
362
|
-
local refs, indexed = doc
|
|
498
|
+
local refs, indexed = position_record(V, f, doc).refs, V.files[f].refs
|
|
363
499
|
if not refs or not refs.start then return nil end
|
|
364
500
|
local j = i
|
|
365
501
|
if refs.name[i] ~= indexed.name[i] or refs.line[i] ~= indexed.line[i] then
|
|
@@ -388,6 +524,19 @@ local function is_decl(node) return not not graph.is_decl(node) end
|
|
|
388
524
|
-- A declaration and its definitions (prototypes, in-class declarations) as one target.
|
|
389
525
|
local function expand(V, set)
|
|
390
526
|
local out = {}
|
|
527
|
+
local function same_declaration(id, candidate)
|
|
528
|
+
local a, b = V.nodes[id], V.nodes[candidate]
|
|
529
|
+
local f, g = V.node_file[id], V.node_file[candidate]
|
|
530
|
+
local language = V.files[f].language
|
|
531
|
+
if not C_FAMILY[language] then return true end
|
|
532
|
+
local owner_a = language == 'cpp' and require('codeoutline.cpp_types').owner(V, f, a, V.js_context)
|
|
533
|
+
local owner_b = V.files[g].language == 'cpp' and require('codeoutline.cpp_types').owner(V, g, b, V.js_context)
|
|
534
|
+
if owner_a and owner_b then return owner_a == owner_b end
|
|
535
|
+
if not require('codeoutline.cpp_includes').policy(V, f, V.js_context).configured then return true end
|
|
536
|
+
if owner_a or owner_b then return false end
|
|
537
|
+
local source, header = is_decl(a) and g or f, is_decl(a) and f or g
|
|
538
|
+
return graph.directly_includes(V, source, header, V.js_context)
|
|
539
|
+
end
|
|
391
540
|
for id in pairs(set) do
|
|
392
541
|
out[id] = true
|
|
393
542
|
local node = V.nodes[id]
|
|
@@ -395,7 +544,7 @@ local function expand(V, set)
|
|
|
395
544
|
for _, cid in ipairs(V.by_name[node.name]) do
|
|
396
545
|
local c = V.nodes[cid]
|
|
397
546
|
if c.qualified == node.qualified and is_decl(c) ~= is_decl(node)
|
|
398
|
-
and graph.family(V.files[V.node_file[cid]].language) == family then out[cid] = true end
|
|
547
|
+
and graph.family(V.files[V.node_file[cid]].language) == family and same_declaration(id, cid) then out[cid] = true end
|
|
399
548
|
end
|
|
400
549
|
end
|
|
401
550
|
return out
|
|
@@ -415,16 +564,31 @@ local function scan(V, targets, name)
|
|
|
415
564
|
local wanted = { [name] = true }
|
|
416
565
|
for id in pairs(targets) do
|
|
417
566
|
for _, alias in ipairs(require('codeoutline.lua_bindings').aliases(V.nodes[id], V.lua_global_export_tables)) do wanted[alias] = true end
|
|
567
|
+
local f = V.node_file[id]
|
|
568
|
+
if V.files[f].language == 'lua' then
|
|
569
|
+
local n = id - V.id_of[f][1] + 1
|
|
570
|
+
for alias, index in pairs(V.files[f].lua_exports or {}) do if index == n then wanted[alias] = true end end
|
|
571
|
+
end
|
|
418
572
|
end
|
|
419
573
|
local files = {}
|
|
420
574
|
for i, f in ipairs(V.file_order) do files[i] = f end
|
|
421
575
|
for _, f in ipairs(V.new_files) do files[#files + 1] = f end
|
|
576
|
+
local candidates = V.js_context.ordinary.candidates(targets)
|
|
422
577
|
for _, f in ipairs(files) do
|
|
423
578
|
control.check()
|
|
579
|
+
local alias_refs = V.js_context.ordinary.aliases(f, targets, candidates)
|
|
580
|
+
if V.files[f].language == 'rust' then
|
|
581
|
+
for i in pairs(require('codeoutline.rust_resolution').alias_refs(V, f, targets, V.js_context)) do alias_refs[i] = true end
|
|
582
|
+
end
|
|
424
583
|
local refs = V.files[f].refs
|
|
584
|
+
local lua_evidence = refs.lua_binding
|
|
585
|
+
if V.files[f].language == 'lua' and not lua_evidence then
|
|
586
|
+
for _, imp in ipairs(V.files[f].lua_imports or {}) do
|
|
587
|
+
if imp.member and wanted[imp.member] then lua_evidence = V.js_context.ordinary.data(f).refs.lua_binding; break end
|
|
588
|
+
end
|
|
589
|
+
end
|
|
425
590
|
local names = refs.name
|
|
426
591
|
local aliases = {}
|
|
427
|
-
for _, binding in ipairs(V.files[f].js_imports or {}) do aliases[binding.local_name] = true end
|
|
428
592
|
if V.files[f].language == 'kotlin' then
|
|
429
593
|
for _, imp in ipairs(V.files[f].imports) do
|
|
430
594
|
if imp.alias and imp.path:match('([^.]+)$') == name then aliases[imp.alias] = true end
|
|
@@ -432,27 +596,36 @@ local function scan(V, targets, name)
|
|
|
432
596
|
end
|
|
433
597
|
for i = 1, #names do
|
|
434
598
|
if i % 4096 == 0 then control.check() end
|
|
435
|
-
if wanted[names[i]] or aliases[names[i]] or aliases[refs.recv[i]]
|
|
599
|
+
if wanted[names[i]] or aliases[names[i]] or aliases[refs.recv[i]]
|
|
600
|
+
or alias_refs[i]
|
|
601
|
+
or (lua_evidence and lua_evidence[i] ~= '') then
|
|
436
602
|
if os.clock() > deadline then return hits, true end
|
|
437
|
-
for _, dst in ipairs(resolve_site(V, f, refs.from[i], names[i], refs.kind[i], refs.recv[i], refs.
|
|
603
|
+
for _, dst in ipairs(resolve_site(V, f, refs.from[i], names[i], refs.kind[i], refs.recv[i], nil, refs.start and refs.start[i] or nil, i)) do
|
|
438
604
|
if targets[dst] then hits[#hits + 1] = { f, i }; break end
|
|
439
605
|
end
|
|
440
606
|
if #hits >= M.MAX_RESULTS then return hits, true end
|
|
441
607
|
end
|
|
442
608
|
end
|
|
443
609
|
end
|
|
444
|
-
return hits,
|
|
610
|
+
return hits, V.js_context.include_incomplete or V.js_context.workspace_incomplete or V.js_context.go_incomplete or V.js_context.go_methods_incomplete
|
|
611
|
+
or V.js_context.rust_incomplete or false
|
|
445
612
|
end
|
|
446
613
|
|
|
447
614
|
-- Files one import record resolves to, through the graph's dependency
|
|
448
615
|
-- rules: a temporary record holding only that import.
|
|
449
616
|
function M.import_files(V, f, imp)
|
|
450
617
|
local rec = V.files[f]
|
|
451
|
-
|
|
618
|
+
if C_FAMILY[rec.language] then return (require('codeoutline.cpp_includes').resolve(V, f, imp, V.js_context)) end
|
|
619
|
+
if rec.language == 'rust' then
|
|
620
|
+
local files = require('codeoutline.rust_resolution').imports(V, f, imp, V.js_context)
|
|
621
|
+
if files then return files end
|
|
622
|
+
end
|
|
623
|
+
local fake = { path = rec.path, language = rec.language,
|
|
452
624
|
nodes = {}, imports = { imp } }
|
|
453
625
|
rawset(V.files, -1, fake)
|
|
454
|
-
local ok, direct = pcall(graph.dependencies, V, -1)
|
|
626
|
+
local ok, direct = pcall(graph.dependencies, V, -1, V.js_context, true)
|
|
455
627
|
rawset(V.files, -1, nil)
|
|
628
|
+
if not ok and control.is_interrupted(direct) then error(direct, 0) end
|
|
456
629
|
local files = {}
|
|
457
630
|
if ok then for g in pairs(direct) do files[#files + 1] = g end end
|
|
458
631
|
table.sort(files, function(x, y) return V.files[x].path < V.files[y].path end)
|
|
@@ -521,19 +694,22 @@ end
|
|
|
521
694
|
|
|
522
695
|
-- Locations of the files an import on this line names: project files by the
|
|
523
696
|
-- dependency rules, and C/C++ headers found in the include directories.
|
|
524
|
-
local function import_targets(V, f, line
|
|
697
|
+
local function import_targets(V, f, line)
|
|
525
698
|
local rec, result, seen = V.files[f], {}, {}
|
|
526
699
|
local function add(uri)
|
|
527
700
|
if not seen[uri] then seen[uri] = true; result[#result + 1] = { uri = uri, range = line_range(1) } end
|
|
528
701
|
end
|
|
529
702
|
for _, imp in ipairs(rec.imports or {}) do
|
|
530
703
|
if imp.line == line then
|
|
531
|
-
local files
|
|
704
|
+
local files, selected, header
|
|
705
|
+
if C_FAMILY[rec.language] then
|
|
706
|
+
files, selected, header = require('codeoutline.cpp_includes').resolve(V, f, imp, V.js_context)
|
|
707
|
+
if imp.system and not selected then files = {} end
|
|
708
|
+
else files = M.import_files(V, f, imp) end
|
|
532
709
|
for _, g in ipairs(files) do add(uri_of(V, g)) end
|
|
533
|
-
if #files == 0 and
|
|
710
|
+
if #files == 0 and header then add(documents.uri(header)) end
|
|
711
|
+
if #files == 0 and not header and C_FAMILY[rec.language] then
|
|
534
712
|
local dirs = {}
|
|
535
|
-
if not imp.system then dirs[1] = (V.idx:abs(rec.path):match('^(.*)/[^/]*$')) end
|
|
536
|
-
for _, dir in ipairs(include_paths or {}) do dirs[#dirs + 1] = paths.normalize(dir) end
|
|
537
713
|
for _, dir in ipairs(probe_includes()) do dirs[#dirs + 1] = dir end
|
|
538
714
|
for _, dir in ipairs(dirs) do
|
|
539
715
|
local file = dir .. '/' .. imp.path:gsub('\\', '/')
|
|
@@ -548,83 +724,11 @@ end
|
|
|
548
724
|
|
|
549
725
|
-- Project-local declarative rules; read per request so configuration edits are live.
|
|
550
726
|
local function definition_rules(root)
|
|
551
|
-
|
|
552
|
-
if not file then return {} end
|
|
553
|
-
local raw = file:read(65537); file:close()
|
|
554
|
-
assert(#raw <= 65536, '.codeoutline.json exceeds 64 KiB')
|
|
555
|
-
local ok, config = pcall(xutils.json_unpack, raw)
|
|
556
|
-
assert(ok and type(config) == 'table', 'invalid .codeoutline.json')
|
|
557
|
-
local rules = config.definitionRules or {}
|
|
558
|
-
assert(type(rules) == 'table' and #rules <= 32, 'definitionRules must contain at most 32 rules')
|
|
559
|
-
for _, rule in ipairs(rules) do
|
|
560
|
-
assert(type(rule) == 'table' and (rule.language == nil or rule.language == 'lua'),
|
|
561
|
-
'definitionRules currently support language lua')
|
|
562
|
-
assert(type(rule.call) == 'string' and rule.call:match('^[%a_][%w_%.:]*$'),
|
|
563
|
-
'definitionRules.call must be a qualified function name')
|
|
564
|
-
assert(type(rule.argument) == 'number' and rule.argument >= 1 and rule.argument <= 32
|
|
565
|
-
and rule.argument % 1 == 0,
|
|
566
|
-
'definitionRules.argument must be an integer from 1 to 32')
|
|
567
|
-
local kind = rule.targetKind or 'call'
|
|
568
|
-
assert(kind == 'call' or kind == 'declaration' or kind == 'key',
|
|
569
|
-
"definitionRules.targetKind must be 'call', 'declaration' or 'key'")
|
|
570
|
-
if kind ~= 'call' then
|
|
571
|
-
assert(rule.target == nil and rule.targetArgument == nil,
|
|
572
|
-
'declaration and key rules must not set target or targetArgument')
|
|
573
|
-
if rule.qualifiers ~= nil then
|
|
574
|
-
assert(type(rule.qualifiers) == 'table', 'definitionRules.qualifiers must be an array of names')
|
|
575
|
-
local qualifiers = {}
|
|
576
|
-
for _, q in ipairs(rule.qualifiers) do
|
|
577
|
-
assert(type(q) == 'string' and q:match('^[%a_][%w_]*$'),
|
|
578
|
-
'definitionRules.qualifiers must contain plain names')
|
|
579
|
-
qualifiers[q] = true
|
|
580
|
-
end
|
|
581
|
-
rule.qualifiers = qualifiers
|
|
582
|
-
end
|
|
583
|
-
else
|
|
584
|
-
assert(type(rule.target) == 'string' and rule.target:match('^[%a_][%w_%.:]*$'),
|
|
585
|
-
'definitionRules.target must be a qualified function name')
|
|
586
|
-
assert(type(rule.targetArgument) == 'number' and rule.targetArgument >= 1
|
|
587
|
-
and rule.targetArgument <= 32 and rule.targetArgument % 1 == 0,
|
|
588
|
-
'definitionRules.targetArgument must be an integer from 1 to 32')
|
|
589
|
-
end
|
|
590
|
-
end
|
|
591
|
-
return rules
|
|
727
|
+
return require('codeoutline.rules').load(root).definitions
|
|
592
728
|
end
|
|
593
729
|
|
|
594
730
|
-- Decode literals without running source code. Lua long strings and quoted escapes.
|
|
595
|
-
local
|
|
596
|
-
local eq, body = raw:match('^%[(=*)%[(.*)%]%1%]$')
|
|
597
|
-
if eq then return body:gsub('^\r?\n', '', 1) end
|
|
598
|
-
local quote = raw:sub(1, 1)
|
|
599
|
-
if (quote ~= '"' and quote ~= "'") or raw:sub(-1) ~= quote then return nil end
|
|
600
|
-
local escaped = { a = '\a', b = '\b', f = '\f', n = '\n', r = '\r', t = '\t', v = '\v',
|
|
601
|
-
['\\'] = '\\', ['"'] = '"', ["'"] = "'", ['\n'] = '\n' }
|
|
602
|
-
local out, i, stop = {}, 2, #raw - 1
|
|
603
|
-
while i <= stop do
|
|
604
|
-
local c = raw:sub(i, i)
|
|
605
|
-
if c ~= '\\' then out[#out + 1] = c; i = i + 1
|
|
606
|
-
else
|
|
607
|
-
c = raw:sub(i + 1, i + 1); i = i + 2
|
|
608
|
-
if escaped[c] then out[#out + 1] = escaped[c]
|
|
609
|
-
elseif c == 'z' then
|
|
610
|
-
while i <= stop and raw:sub(i, i):match('%s') do i = i + 1 end
|
|
611
|
-
elseif c == '\r' then
|
|
612
|
-
if raw:sub(i, i) == '\n' then i = i + 1 end
|
|
613
|
-
out[#out + 1] = '\n'
|
|
614
|
-
elseif c == 'x' then
|
|
615
|
-
local hex = raw:sub(i, i + 1)
|
|
616
|
-
if not hex:match('^%x%x$') then return nil end
|
|
617
|
-
out[#out + 1] = string.char(tonumber(hex, 16)); i = i + 2
|
|
618
|
-
elseif c:match('%d') then
|
|
619
|
-
local digits = (c .. raw:sub(i, stop)):match('^%d%d?%d?')
|
|
620
|
-
local n = tonumber(digits)
|
|
621
|
-
if n > 255 then return nil end
|
|
622
|
-
out[#out + 1] = string.char(n); i = i + #digits - 1
|
|
623
|
-
else return nil end
|
|
624
|
-
end
|
|
625
|
-
end
|
|
626
|
-
return table.concat(out)
|
|
627
|
-
end
|
|
731
|
+
local string_value = require('codeoutline.lua_literal').decode
|
|
628
732
|
|
|
629
733
|
local function call_name(T, i)
|
|
630
734
|
if T.k[i] ~= 'id' or T:text(i + 1) ~= '(' then return nil end
|
|
@@ -697,9 +801,183 @@ local function call_matches(name, rule_name)
|
|
|
697
801
|
return name:find(':') ~= nil and name:match('([%w_]+)$') == rule_name
|
|
698
802
|
end
|
|
699
803
|
|
|
700
|
-
local function
|
|
804
|
+
local function service_argument(rule)
|
|
805
|
+
if rule.serviceArgument then return rule.serviceArgument end
|
|
806
|
+
if rule.call == 'skynet.call' or rule.call == 'skynet.send' then return 1 end
|
|
807
|
+
return rule.argument - 1
|
|
808
|
+
end
|
|
809
|
+
|
|
810
|
+
-- Service filenames are candidate locations, not proof of a runtime RPC edge.
|
|
811
|
+
-- Keep every exact suffix match if several indexed service roots use the name.
|
|
812
|
+
local function service_files(V, site, rule)
|
|
813
|
+
local arg = site.args[service_argument(rule)]
|
|
814
|
+
if not arg then return nil end
|
|
815
|
+
local name = arg.service
|
|
816
|
+
if not name and (rule.serviceArgument or rule.call:match('^dservice%.')
|
|
817
|
+
or rule.call == 'skynet.call' or rule.call == 'skynet.send'
|
|
818
|
+
or rule.call == 'cluster.call' or rule.call == 'cluster.send') then name = arg.literal end
|
|
819
|
+
if not name or not name:match('^[%w_][%w_/-]*$') then return nil end
|
|
820
|
+
local suffix, result = name .. '.lua', {}
|
|
821
|
+
local function add(file)
|
|
822
|
+
local rec = V.files[file]
|
|
823
|
+
if rec.language == 'lua' and (rec.path == suffix or rec.path:sub(-#suffix - 1) == '/' .. suffix) then result[file] = true end
|
|
824
|
+
end
|
|
825
|
+
for _, file in ipairs(V.file_order) do control.check(); add(file) end
|
|
826
|
+
for _, file in ipairs(V.new_files) do control.check(); add(file) end
|
|
827
|
+
return next(result) and result or nil
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
-- Shared rules reuse graph sites and aliases. String targets navigate to project
|
|
831
|
+
-- declarations: remote services need not be lexical dependencies of the caller.
|
|
832
|
+
local function shared_definition(V, doc, offset, rules)
|
|
833
|
+
local record = doc:parse()
|
|
834
|
+
local language = record.language
|
|
835
|
+
local names, applicable, literals = {}, {}, {}
|
|
836
|
+
local function literal_position(name, argument)
|
|
837
|
+
literals[name] = literals[name] or {}
|
|
838
|
+
literals[name][argument] = true
|
|
839
|
+
end
|
|
840
|
+
for _, rule in ipairs(rules) do
|
|
841
|
+
if rule.shared and (not rule.language or rule.language == language)
|
|
842
|
+
and require('codeoutline.indirect').candidate(record, rule.call) then
|
|
843
|
+
applicable[#applicable + 1] = rule
|
|
844
|
+
names[rule.call] = true
|
|
845
|
+
if rule.register then names[rule.register] = true end
|
|
846
|
+
if rule.kind == 'target' or rule.kind == 'event' then literal_position(rule.call, rule.argument) end
|
|
847
|
+
if rule.kind == 'target' and service_argument(rule) > 0 then literal_position(rule.call, service_argument(rule)) end
|
|
848
|
+
if rule.kind == 'event' then literal_position(rule.register, rule.keyArgument) end
|
|
849
|
+
end
|
|
850
|
+
end
|
|
851
|
+
if #applicable == 0 then return nil end
|
|
852
|
+
local parsed = {}
|
|
853
|
+
local function sites(source)
|
|
854
|
+
if not parsed[source] then
|
|
855
|
+
local record = source:dispatch(names)
|
|
856
|
+
parsed[source] = record and record.dispatch_sites or {}
|
|
857
|
+
-- Preserve the explicit Lua literal contract even when conservative
|
|
858
|
+
-- alias analysis cannot prove a receiver's identity. These sites
|
|
859
|
+
-- belong only to navigation, never to the relationship resolver.
|
|
860
|
+
if language == 'lua' then
|
|
861
|
+
local T = source:tokens()
|
|
862
|
+
local known = {}
|
|
863
|
+
for _, site in ipairs(parsed[source]) do
|
|
864
|
+
for argument in pairs(literals[site.call] or {}) do
|
|
865
|
+
local arg, range = site.args[argument], site.ranges[argument]
|
|
866
|
+
if arg and arg.literal and range then
|
|
867
|
+
known[site.call .. ':' .. argument .. ':' .. range[1]] = true
|
|
868
|
+
end
|
|
869
|
+
end
|
|
870
|
+
end
|
|
871
|
+
for i = 1, T.n do
|
|
872
|
+
if i % 128 == 0 then control.check() end
|
|
873
|
+
local name = call_name(T, i)
|
|
874
|
+
if literals[name] then
|
|
875
|
+
local site = { call = name, args = {}, ranges = {} }
|
|
876
|
+
for argument in pairs(literals[name]) do
|
|
877
|
+
local value, first, last = literal_argument(T, i, argument)
|
|
878
|
+
if value and not known[name .. ':' .. argument .. ':' .. first] then
|
|
879
|
+
site.args[argument] = { literal = value }
|
|
880
|
+
site.ranges[argument] = { first, last }
|
|
881
|
+
end
|
|
882
|
+
end
|
|
883
|
+
if next(site.args) then parsed[source][#parsed[source] + 1] = site end
|
|
884
|
+
end
|
|
885
|
+
end
|
|
886
|
+
end
|
|
887
|
+
end
|
|
888
|
+
return parsed[source]
|
|
889
|
+
end
|
|
890
|
+
local matched = {}
|
|
891
|
+
for _, site in ipairs(sites(doc)) do
|
|
892
|
+
for _, rule in ipairs(applicable) do
|
|
893
|
+
local range, arg = site.ranges[rule.argument], site.args[rule.argument]
|
|
894
|
+
if (site.call == rule.call or site.api == rule.call) and arg and range
|
|
895
|
+
and range[1] <= offset and offset < range[2]
|
|
896
|
+
and (rule.kind == 'callback' and arg.symbol or rule.kind ~= 'callback' and arg.literal) then
|
|
897
|
+
matched[#matched + 1] = { rule = rule, site = site, arg = arg }
|
|
898
|
+
end
|
|
899
|
+
end
|
|
900
|
+
end
|
|
901
|
+
if #matched == 0 then return nil end
|
|
902
|
+
local result, seen, events = {}, {}, {}
|
|
903
|
+
local deadline = os.clock() + M.SCAN_SECONDS
|
|
904
|
+
local function add(loc)
|
|
905
|
+
local key = loc.uri .. ':' .. loc.range.start.line .. ':' .. loc.range.start.character
|
|
906
|
+
if not seen[key] then result[#result + 1] = loc; seen[key] = true end
|
|
907
|
+
return #result >= M.MAX_RESULTS
|
|
908
|
+
end
|
|
909
|
+
local f = V.add(doc)
|
|
910
|
+
local resolver
|
|
911
|
+
for _, match in ipairs(matched) do
|
|
912
|
+
local rule = match.rule
|
|
913
|
+
if rule.kind == 'event' then events[#events + 1] = match
|
|
914
|
+
elseif rule.kind == 'target' then
|
|
915
|
+
local name = match.arg.literal
|
|
916
|
+
local services = language == 'lua' and service_files(V, match.site, rule)
|
|
917
|
+
local short = name:match('([%w_]+)$')
|
|
918
|
+
if short and name:match('^[%a_][%w_%.:>%-]*$') then
|
|
919
|
+
for _, id in ipairs(V.by_name[short]) do
|
|
920
|
+
control.check()
|
|
921
|
+
if os.clock() > deadline then return result, true end
|
|
922
|
+
local node = V.nodes[id]
|
|
923
|
+
if DECLARABLE[node.kind] and V.files[V.node_file[id]].language == language
|
|
924
|
+
and (name == short or node.qualified == name)
|
|
925
|
+
and (not services or services[V.node_file[id]])
|
|
926
|
+
and qualifier_matches(rule, graph.owner(node.qualified or node.name)) then
|
|
927
|
+
if add(location(V, id)) then return result, true end
|
|
928
|
+
end
|
|
929
|
+
end
|
|
930
|
+
end
|
|
931
|
+
else
|
|
932
|
+
resolver = resolver or require('codeoutline.indirect').query(V, { rule }).resolve_targets
|
|
933
|
+
for _, id in ipairs(resolver(f, match.site, match.arg, rule.kind == 'target')) do
|
|
934
|
+
control.check()
|
|
935
|
+
if os.clock() > deadline then return result, true end
|
|
936
|
+
if add(location(V, id)) then return result, true end
|
|
937
|
+
end
|
|
938
|
+
end
|
|
939
|
+
end
|
|
940
|
+
if #events == 0 then return result, false end
|
|
941
|
+
local files = {}
|
|
942
|
+
for _, file in ipairs(V.file_order) do files[#files + 1] = file end
|
|
943
|
+
for _, file in ipairs(V.new_files) do files[#files + 1] = file end
|
|
944
|
+
table.sort(files, function(a, b) return V.files[a].path < V.files[b].path end)
|
|
945
|
+
for _, file in ipairs(files) do
|
|
946
|
+
control.check()
|
|
947
|
+
if os.clock() > deadline then return result, true end
|
|
948
|
+
local candidate = false
|
|
949
|
+
if V.files[file].language == language then
|
|
950
|
+
for _, match in ipairs(events) do
|
|
951
|
+
if require('codeoutline.indirect').candidate(V.files[file], match.rule.register) then candidate = true; break end
|
|
952
|
+
end
|
|
953
|
+
end
|
|
954
|
+
if candidate then
|
|
955
|
+
local source = source_doc(V, file)
|
|
956
|
+
if source then
|
|
957
|
+
for _, site in ipairs(sites(source)) do
|
|
958
|
+
for _, match in ipairs(events) do
|
|
959
|
+
local rule = match.rule
|
|
960
|
+
local arg, range = site.args[rule.keyArgument], site.ranges[rule.keyArgument]
|
|
961
|
+
if (site.call == rule.register or site.api == rule.register) and arg and range
|
|
962
|
+
and arg.literal == match.arg.literal then
|
|
963
|
+
if add({ uri = source.uri, range = source:range(range[1], range[2]) }) then return result, true end
|
|
964
|
+
end
|
|
965
|
+
end
|
|
966
|
+
end
|
|
967
|
+
end
|
|
968
|
+
end
|
|
969
|
+
end
|
|
970
|
+
return result, false
|
|
971
|
+
end
|
|
972
|
+
|
|
973
|
+
local function legacy_definition(V, doc, offset, rules)
|
|
701
974
|
if doc:parse().language ~= 'lua' then return nil end
|
|
702
|
-
local
|
|
975
|
+
local legacy = {}
|
|
976
|
+
for _, rule in ipairs(rules) do
|
|
977
|
+
if (not rule.shared or rule.legacy)
|
|
978
|
+
and (not rule.language or rule.language == 'lua') then legacy[#legacy + 1] = rule end
|
|
979
|
+
end
|
|
980
|
+
rules = legacy
|
|
703
981
|
if #rules == 0 then return nil end
|
|
704
982
|
local tokens = doc:tokens()
|
|
705
983
|
local matched = {}
|
|
@@ -797,28 +1075,129 @@ local function configured_definition(V, doc, offset)
|
|
|
797
1075
|
return result, false
|
|
798
1076
|
end
|
|
799
1077
|
|
|
1078
|
+
local function configured_definition(V, doc, offset)
|
|
1079
|
+
local rules = definition_rules(V.root)
|
|
1080
|
+
if #rules == 0 then return nil end
|
|
1081
|
+
local shared, incomplete = shared_definition(V, doc, offset, rules)
|
|
1082
|
+
local legacy, legacy_incomplete = legacy_definition(V, doc, offset, rules)
|
|
1083
|
+
if shared == nil then return legacy, legacy_incomplete end
|
|
1084
|
+
local seen = {}
|
|
1085
|
+
local function key(loc)
|
|
1086
|
+
return loc.uri .. ':' .. loc.range.start.line .. ':' .. loc.range.start.character
|
|
1087
|
+
end
|
|
1088
|
+
for _, loc in ipairs(shared) do seen[key(loc)] = true end
|
|
1089
|
+
for _, loc in ipairs(legacy or {}) do
|
|
1090
|
+
if not seen[key(loc)] then
|
|
1091
|
+
if #shared >= M.MAX_RESULTS then return shared, true end
|
|
1092
|
+
seen[key(loc)] = true
|
|
1093
|
+
shared[#shared + 1] = loc
|
|
1094
|
+
end
|
|
1095
|
+
end
|
|
1096
|
+
return shared, incomplete or legacy_incomplete or false
|
|
1097
|
+
end
|
|
1098
|
+
|
|
800
1099
|
local function at(req)
|
|
801
1100
|
local doc = request_doc(req)
|
|
802
1101
|
if not doc then return nil end
|
|
803
|
-
local V = view(req.session, req.root)
|
|
1102
|
+
local V = view(req.session, req.root, req.includePaths)
|
|
804
1103
|
local f = V.add(doc)
|
|
805
1104
|
if not f then return nil end
|
|
806
1105
|
local offset = doc:offset(req.position)
|
|
807
|
-
local c = cursor(doc, offset)
|
|
808
|
-
local targets = {}
|
|
1106
|
+
local c = cursor(doc, offset, V, f, req.method == 'lsp_definition')
|
|
1107
|
+
local targets, reason, evidence, macro_state = {}
|
|
809
1108
|
if c and c.decl then targets = { V.id_of[f][c.decl] }
|
|
810
|
-
elseif c then
|
|
1109
|
+
elseif c then
|
|
1110
|
+
c.line = doc:position(c.first).line + 1
|
|
1111
|
+
targets, reason, evidence, macro_state = resolve_site(V, f, c.from, c.name, c.kind, c.recv, c.evidence, c.first, c.index, c.line)
|
|
1112
|
+
c.reason, c.evidence, c.macro_state = reason, evidence, macro_state
|
|
1113
|
+
end
|
|
811
1114
|
return V, doc, c, targets, f, offset
|
|
812
1115
|
end
|
|
813
1116
|
|
|
814
1117
|
local handlers = {}
|
|
815
1118
|
|
|
1119
|
+
-- Best-effort idle work: share the exact caches used by navigation, rather
|
|
1120
|
+
-- than retaining answers that could outlive a document/configuration change.
|
|
1121
|
+
function handlers.lsp_warm(req)
|
|
1122
|
+
local doc = request_doc(req)
|
|
1123
|
+
if not doc or #doc.source > M.MAX_FILE_BYTES then return { files = 0 } end
|
|
1124
|
+
local V = view(req.session, req.root, req.includePaths, req.uri)
|
|
1125
|
+
local f = V.add(doc)
|
|
1126
|
+
if not f then return { files = 0 } end
|
|
1127
|
+
local started, files, bytes = xtimer.now_ms(), 0, 0
|
|
1128
|
+
local function warm(target)
|
|
1129
|
+
control.check()
|
|
1130
|
+
local draft = V.drafts[target]
|
|
1131
|
+
if not draft then
|
|
1132
|
+
local path = paths.key(V.idx:abs(V.files[target].path))
|
|
1133
|
+
for _, candidate in pairs(sessions[req.session] or {}) do
|
|
1134
|
+
if candidate.path and paths.key(candidate.path) == path then draft = candidate; break end
|
|
1135
|
+
end
|
|
1136
|
+
end
|
|
1137
|
+
local size = draft and #draft.source or V.files[target].size or 0
|
|
1138
|
+
if files >= 4 or size > M.MAX_FILE_BYTES or bytes + size > 2 * M.MAX_FILE_BYTES
|
|
1139
|
+
or xtimer.now_ms() - started >= 500 then return false end
|
|
1140
|
+
if draft then V.add(draft) end
|
|
1141
|
+
local rec = M.full(V, target)
|
|
1142
|
+
if not rec then return false end
|
|
1143
|
+
files, bytes = files + 1, bytes + size
|
|
1144
|
+
local lang = rec.language
|
|
1145
|
+
if require('codeoutline.type_uses').languages[lang] or lang == 'python' or lang == 'javascript'
|
|
1146
|
+
or lang == 'lua' then V.js_context.ordinary.data(target) end
|
|
1147
|
+
return true
|
|
1148
|
+
end
|
|
1149
|
+
warm(f)
|
|
1150
|
+
local direct = graph.dependencies(V, f, V.js_context, true)
|
|
1151
|
+
local candidates = {}
|
|
1152
|
+
for target in pairs(direct) do if target ~= f then candidates[#candidates + 1] = target end end
|
|
1153
|
+
table.sort(candidates, function(a, b) return V.files[a].path < V.files[b].path end)
|
|
1154
|
+
for _, target in ipairs(candidates) do
|
|
1155
|
+
if files >= 4 or xtimer.now_ms() - started >= 500 then break end
|
|
1156
|
+
warm(target)
|
|
1157
|
+
end
|
|
1158
|
+
return { files = files }
|
|
1159
|
+
end
|
|
1160
|
+
|
|
1161
|
+
function handlers.lsp_implementation(req)
|
|
1162
|
+
local V, _, _, targets = at(req)
|
|
1163
|
+
if not V then return {} end
|
|
1164
|
+
local relationships = require('codeoutline.implementations').context(V, V.js_context)
|
|
1165
|
+
local result, seen = {}, {}
|
|
1166
|
+
for _, target in ipairs(targets) do
|
|
1167
|
+
for _, id in ipairs(relationships.outgoing(target)) do
|
|
1168
|
+
if not seen[id] then seen[id] = true; result[#result + 1] = (location(V, id)) end
|
|
1169
|
+
end
|
|
1170
|
+
end
|
|
1171
|
+
return result, relationships.incomplete
|
|
1172
|
+
end
|
|
1173
|
+
|
|
816
1174
|
function handlers.lsp_definition(req)
|
|
817
1175
|
local V, doc, c, targets, f, offset = at(req)
|
|
818
1176
|
if not V then return false end
|
|
819
|
-
|
|
1177
|
+
if not c and (V.files[f].language == 'javascript' or V.files[f].language == 'typescript') then
|
|
1178
|
+
local events = require('codeoutline.shared_events').context(V, V.js_context)
|
|
1179
|
+
local found, recognized = events.definition(f, offset, doc:position(offset).line + 1)
|
|
1180
|
+
if recognized then
|
|
1181
|
+
local result = {}; for _, id in ipairs(found) do result[#result + 1] = (location(V, id)) end
|
|
1182
|
+
return result, events.incomplete or V.js_context.workspace_incomplete
|
|
1183
|
+
end
|
|
1184
|
+
end
|
|
1185
|
+
local configured, incomplete
|
|
1186
|
+
-- Rule arguments are strings or referenced values, never the name of a
|
|
1187
|
+
-- call/declaration itself. Avoid collecting dispatch sites for ordinary F12.
|
|
1188
|
+
if not c or not c.decl and c.kind ~= 'call' and c.kind ~= 'member_call' and c.kind ~= 'new' then
|
|
1189
|
+
configured, incomplete = configured_definition(V, doc, offset)
|
|
1190
|
+
end
|
|
820
1191
|
if configured then return configured, incomplete end
|
|
821
1192
|
local line = doc:position(offset).line + 1
|
|
1193
|
+
if #targets == 0 and c and c.kind == 'call' and C_FAMILY[V.files[f].language] then
|
|
1194
|
+
-- Unknown build flags block execution binding, but F12 can still show
|
|
1195
|
+
-- the macro declaration sites that may be active at this call.
|
|
1196
|
+
local _, definitions = require('codeoutline.cpp_macros').resolve(V, f, c.name, line, V.js_context, true)
|
|
1197
|
+
if definitions and #definitions > 0 then targets = definitions end
|
|
1198
|
+
end
|
|
1199
|
+
-- Selecting a loader's member asks for that value, not the imported file.
|
|
1200
|
+
if #targets == 0 and c and type(c.evidence) == 'string' and c.evidence:match('^lua%-value:') then return {} end
|
|
822
1201
|
local importer = false
|
|
823
1202
|
if c and not c.decl then
|
|
824
1203
|
-- `require`/`dofile` themselves name the file they load, not a same-named project function.
|
|
@@ -828,8 +1207,39 @@ function handlers.lsp_definition(req)
|
|
|
828
1207
|
end
|
|
829
1208
|
if #targets == 0 or importer then
|
|
830
1209
|
-- An import line: `require "a.b"`, `dofile("x.lua")`, `#include <x.h>`, `from . import m`.
|
|
831
|
-
local files = import_targets(V, f, line
|
|
832
|
-
if #files > 0 or
|
|
1210
|
+
local files = import_targets(V, f, line)
|
|
1211
|
+
if #files > 0 or importer then
|
|
1212
|
+
return files, V.js_context.include_incomplete or V.js_context.workspace_incomplete or V.js_context.go_incomplete or V.js_context.go_methods_incomplete or V.js_context.rust_incomplete
|
|
1213
|
+
end
|
|
1214
|
+
end
|
|
1215
|
+
if #targets == 0 then
|
|
1216
|
+
if C_FAMILY[V.files[f].language] then
|
|
1217
|
+
local entries, info = require('codeoutline.external_headers').find(V, f, c, V.js_context, probe_includes)
|
|
1218
|
+
if #entries > 0 then
|
|
1219
|
+
local result = {}
|
|
1220
|
+
for _, entry in ipairs(entries) do
|
|
1221
|
+
local header = documents.new(documents.uri(entry.file), entry.source)
|
|
1222
|
+
result[#result + 1] = { uri = header.uri, range = header:range(entry.node.name_start, entry.node.name_end) }
|
|
1223
|
+
end
|
|
1224
|
+
return result, info.truncated
|
|
1225
|
+
end
|
|
1226
|
+
end
|
|
1227
|
+
local ids, info = require('codeoutline.definition_candidates').find(V, f, c, V.js_context)
|
|
1228
|
+
local result, seen, bytes, started = {}, {}, 0, os.clock()
|
|
1229
|
+
local count = 0
|
|
1230
|
+
for _, id in ipairs(ids) do
|
|
1231
|
+
local g = V.node_file[id]
|
|
1232
|
+
local size = V.files[g].size or 0
|
|
1233
|
+
if not seen[g] then
|
|
1234
|
+
if count >= 4 or size > M.MAX_FILE_BYTES or bytes + size > 2 * M.MAX_FILE_BYTES
|
|
1235
|
+
or os.clock() - started >= 0.5 then info.truncated = true; break end
|
|
1236
|
+
seen[g], bytes, count = true, bytes + size, count + 1
|
|
1237
|
+
end
|
|
1238
|
+
local target_doc, hit = locate(V, id)
|
|
1239
|
+
if hit then result[#result + 1] = { uri = target_doc.uri, range = target_doc:range(hit.name_start, hit.name_end) } end
|
|
1240
|
+
end
|
|
1241
|
+
return result, info.truncated or V.js_context.include_incomplete or V.js_context.workspace_incomplete
|
|
1242
|
+
or V.js_context.go_incomplete or V.js_context.go_methods_incomplete or V.js_context.cpp_receivers_incomplete or V.js_context.rust_incomplete
|
|
833
1243
|
end
|
|
834
1244
|
if c.decl and is_decl(V.nodes[targets[1]]) then
|
|
835
1245
|
-- From a declaration, go to its definitions.
|
|
@@ -841,7 +1251,7 @@ function handlers.lsp_definition(req)
|
|
|
841
1251
|
end
|
|
842
1252
|
local result = {}
|
|
843
1253
|
for _, id in ipairs(targets) do result[#result + 1] = (location(V, id)) end
|
|
844
|
-
return result
|
|
1254
|
+
return result, V.js_context.include_incomplete or V.js_context.workspace_incomplete or V.js_context.go_incomplete or V.js_context.go_methods_incomplete or V.js_context.cpp_receivers_incomplete or V.js_context.rust_incomplete
|
|
845
1255
|
end
|
|
846
1256
|
|
|
847
1257
|
-- Follow unmatched delimiters up to the cursor. Commas in nested calls,
|
|
@@ -851,12 +1261,21 @@ function handlers.lsp_signature(req)
|
|
|
851
1261
|
if not doc then return false end
|
|
852
1262
|
local T, offset = doc:tokens(), doc:offset(req.position)
|
|
853
1263
|
if not T then return false end
|
|
1264
|
+
local language = doc:parse().language
|
|
854
1265
|
local stack = {}
|
|
855
1266
|
local close = { [')'] = '(', [']'] = '[', ['}'] = '{' }
|
|
1267
|
+
local lua_blocks = { ['function'] = true, ['if'] = true, ['do'] = true, ['repeat'] = true }
|
|
856
1268
|
for i = 1, T.n do
|
|
857
1269
|
if T.s[i] - 1 >= offset then break end
|
|
858
1270
|
if i % 128 == 0 then control.check() end
|
|
859
|
-
if T.k[i] == '
|
|
1271
|
+
if language == 'lua' and T.k[i] == 'kw' then
|
|
1272
|
+
local s = T:text(i)
|
|
1273
|
+
if lua_blocks[s] then
|
|
1274
|
+
stack[#stack + 1] = { token = i, delimiter = s, block = true, argument = 0 }
|
|
1275
|
+
elseif s == 'end' or s == 'until' then
|
|
1276
|
+
while #stack > 0 do if table.remove(stack).block then break end end
|
|
1277
|
+
end
|
|
1278
|
+
elseif T.k[i] == 'op' then
|
|
860
1279
|
local s = T:text(i)
|
|
861
1280
|
if s == '(' or s == '[' or s == '{' then
|
|
862
1281
|
stack[#stack + 1] = { token = i, delimiter = s, argument = 0 }
|
|
@@ -868,9 +1287,12 @@ function handlers.lsp_signature(req)
|
|
|
868
1287
|
end
|
|
869
1288
|
end
|
|
870
1289
|
local call
|
|
871
|
-
local kotlin =
|
|
1290
|
+
local kotlin = language == 'kotlin'
|
|
872
1291
|
for i = #stack, 1, -1 do
|
|
873
1292
|
local entry = stack[i]
|
|
1293
|
+
-- A callback body is not an argument-editing context for its caller.
|
|
1294
|
+
-- Inner calls can still supply help; after `end` the outer call resumes.
|
|
1295
|
+
if entry.delimiter == 'function' then break end
|
|
874
1296
|
local name_token = entry.token - 1
|
|
875
1297
|
if kotlin and entry.delimiter == '(' and T:text(name_token) == '>' then
|
|
876
1298
|
local depth, k = 1, name_token - 1
|
|
@@ -896,7 +1318,7 @@ function handlers.lsp_signature(req)
|
|
|
896
1318
|
for _, id in ipairs(targets) do
|
|
897
1319
|
local node = V.nodes[id]
|
|
898
1320
|
local foreign = require('codeoutline.foreign').signature(node, doc:parse().language, T:text(name_token))
|
|
899
|
-
local label = node.sig
|
|
1321
|
+
local label = M.detail(V, V.node_file[id], node).sig
|
|
900
1322
|
if foreign and not seen[foreign.label] then
|
|
901
1323
|
foreign.activeParameter = #foreign.parameters > 0 and math.min(call.argument, #foreign.parameters - 1) or nil
|
|
902
1324
|
signatures[#signatures + 1] = foreign
|
|
@@ -943,7 +1365,7 @@ function handlers.lsp_hover(req)
|
|
|
943
1365
|
local node, rec = V.nodes[id], V.files[V.node_file[id]]
|
|
944
1366
|
local foreign = require('codeoutline.foreign').signature(node, doc:parse().language, doc.source:sub(c.first + 1, c.last))
|
|
945
1367
|
parts[#parts + 1] = '```' .. (foreign and doc:parse().language or rec.language or '') .. '\n'
|
|
946
|
-
.. (foreign and foreign.label or node.sig or node.qualified) .. '\n```'
|
|
1368
|
+
.. (foreign and foreign.label or M.detail(V, V.node_file[id], node).sig or node.qualified) .. '\n```'
|
|
947
1369
|
parts[#parts + 1] = node.kind .. ' `' .. node.qualified .. '` — ' .. rec.path .. ':' .. node.line
|
|
948
1370
|
end
|
|
949
1371
|
return { contents = { kind = 'markdown', value = table.concat(parts, '\n\n') }, range = doc:range(c.first, c.last) }
|
|
@@ -964,7 +1386,7 @@ local function positions_left(t0, incomplete)
|
|
|
964
1386
|
end
|
|
965
1387
|
|
|
966
1388
|
function handlers.lsp_incoming(req)
|
|
967
|
-
local V = view(req.session, req.root)
|
|
1389
|
+
local V = view(req.session, req.root, req.includePaths)
|
|
968
1390
|
local id = relocate(V, req.data)
|
|
969
1391
|
if not id then return {} end
|
|
970
1392
|
local name = V.nodes[id].name
|
|
@@ -988,7 +1410,7 @@ function handlers.lsp_incoming(req)
|
|
|
988
1410
|
end
|
|
989
1411
|
|
|
990
1412
|
function handlers.lsp_outgoing(req)
|
|
991
|
-
local V = view(req.session, req.root)
|
|
1413
|
+
local V = view(req.session, req.root, req.includePaths)
|
|
992
1414
|
local f = type(req.data) == 'table' and type(req.data.path) == 'string' and V.file_index[req.data.path]
|
|
993
1415
|
if not f then return {} end
|
|
994
1416
|
if not V.drafts[f] then
|
|
@@ -1005,7 +1427,7 @@ function handlers.lsp_outgoing(req)
|
|
|
1005
1427
|
for i = 1, #refs.name do
|
|
1006
1428
|
if i % 128 == 0 then control.check() end
|
|
1007
1429
|
if refs.from[i] == from then
|
|
1008
|
-
for _, dst in ipairs(resolve_site(V, f, from, refs.name[i], refs.kind[i], refs.recv[i], refs.
|
|
1430
|
+
for _, dst in ipairs(resolve_site(V, f, from, refs.name[i], refs.kind[i], refs.recv[i], nil, refs.start and refs.start[i] or nil, i)) do
|
|
1009
1431
|
local group = groups[dst]
|
|
1010
1432
|
if not group then
|
|
1011
1433
|
group = { to = item(V, dst), fromRanges = {} }
|
|
@@ -1017,13 +1439,36 @@ function handlers.lsp_outgoing(req)
|
|
|
1017
1439
|
end
|
|
1018
1440
|
end
|
|
1019
1441
|
end
|
|
1020
|
-
return result
|
|
1442
|
+
return result, V.js_context.include_incomplete or V.js_context.workspace_incomplete or V.js_context.go_incomplete or V.js_context.go_methods_incomplete or V.js_context.cpp_receivers_incomplete or V.js_context.rust_incomplete
|
|
1021
1443
|
end
|
|
1022
1444
|
|
|
1023
1445
|
function handlers.lsp_references(req)
|
|
1024
1446
|
local V, _, c, targets = at(req)
|
|
1025
|
-
if not V
|
|
1447
|
+
if not V then return {} end
|
|
1448
|
+
if #targets == 0 then return {}, V.js_context.workspace_incomplete or V.js_context.go_incomplete or V.js_context.go_methods_incomplete or V.js_context.cpp_receivers_incomplete or V.js_context.rust_incomplete end
|
|
1026
1449
|
local set = {}
|
|
1450
|
+
local type_ids = {}
|
|
1451
|
+
for _, id in ipairs(targets) do if TYPES[V.nodes[id].kind] then type_ids[#type_ids + 1] = id end end
|
|
1452
|
+
if #type_ids > 0 then
|
|
1453
|
+
local engine = require('codeoutline.type_references')
|
|
1454
|
+
for _, id in ipairs(type_ids) do
|
|
1455
|
+
if not engine.kinds[V.nodes[id].kind] or not require('codeoutline.type_uses').languages[V.files[V.node_file[id]].language] then
|
|
1456
|
+
return { error = 'Type references currently support explicit C/C++, C#, Java, Kotlin, TypeScript, Go and Rust positions' }
|
|
1457
|
+
end
|
|
1458
|
+
end
|
|
1459
|
+
local details = engine.query(V, { query_source = function(_, path)
|
|
1460
|
+
local source = source_doc(V, V.file_index[path]); return source and source.source, false
|
|
1461
|
+
end }, type_ids, { cache = binding_cache, max_nodes = M.MAX_RESULTS, include_paths = req.includePaths,
|
|
1462
|
+
time_limit_ms = 600, max_files = 16 })
|
|
1463
|
+
local result = {}
|
|
1464
|
+
if req.includeDeclaration then for _, target in ipairs(details.targets) do result[#result + 1] = location(V, target.id) end end
|
|
1465
|
+
for _, ref in ipairs(details.references) do
|
|
1466
|
+
if #result >= M.MAX_RESULTS then details.incomplete = true; break end
|
|
1467
|
+
local source = source_doc(V, V.file_index[ref.file])
|
|
1468
|
+
if source then result[#result + 1] = { uri = uri_of(V, V.file_index[ref.file]), range = source:range(ref.first, ref.last) } end
|
|
1469
|
+
end
|
|
1470
|
+
return result, details.incomplete
|
|
1471
|
+
end
|
|
1027
1472
|
for _, id in ipairs(targets) do
|
|
1028
1473
|
if not REFERENCE[V.nodes[id].kind] then
|
|
1029
1474
|
return { error = 'References currently support functions, methods, constructors and macros only' }
|
|
@@ -1031,7 +1476,8 @@ function handlers.lsp_references(req)
|
|
|
1031
1476
|
set[id] = true
|
|
1032
1477
|
end
|
|
1033
1478
|
set = expand(V, set)
|
|
1034
|
-
local
|
|
1479
|
+
local language = V.files[V.node_file[targets[1]]].language
|
|
1480
|
+
local name = (language == 'kotlin' or language == 'csharp') and V.nodes[targets[1]].name or c.name
|
|
1035
1481
|
local hits, incomplete = scan(V, set, name)
|
|
1036
1482
|
local result, t0 = {}, os.clock()
|
|
1037
1483
|
if req.includeDeclaration then
|