@codua/codeoutline-win32-x64 0.2.6 → 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 +48 -7
- package/scripts/codeoutline/completion.lua +126 -22
- package/scripts/codeoutline/coverage.lua +63 -0
- package/scripts/codeoutline/cpp_bindings.lua +46 -11
- 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 +275 -28
- package/scripts/codeoutline/definition_candidates.lua +180 -0
- package/scripts/codeoutline/dispatch_aliases.lua +10 -5
- package/scripts/codeoutline/documents.lua +22 -9
- package/scripts/codeoutline/explore.lua +243 -122
- package/scripts/codeoutline/external_headers.lua +171 -0
- 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 +322 -67
- package/scripts/codeoutline/implementations.lua +403 -0
- package/scripts/codeoutline/index.lua +161 -28
- package/scripts/codeoutline/index_worker.lua +11 -4
- package/scripts/codeoutline/indirect.lua +4 -2
- package/scripts/codeoutline/js_evidence.lua +2 -1
- package/scripts/codeoutline/js_resolution.lua +40 -12
- 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 +1 -1
- 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 +151 -47
- package/scripts/codeoutline/lua_callback_loops.lua +210 -0
- package/scripts/codeoutline/main.lua +32 -7
- package/scripts/codeoutline/mcp.lua +52 -9
- package/scripts/codeoutline/navigation.lua +284 -64
- package/scripts/codeoutline/on_demand.lua +93 -0
- package/scripts/codeoutline/ordinary_bindings.lua +210 -34
- 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 +2 -2
- package/scripts/codeoutline/query_filters.lua +65 -0
- package/scripts/codeoutline/query_report.lua +56 -19
- package/scripts/codeoutline/resolution.lua +23 -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 +46 -11
- 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
|
@@ -13,15 +13,19 @@ local control = require('codeoutline.control')
|
|
|
13
13
|
local lsp = require('codeoutline.lsp')
|
|
14
14
|
local parse = require('codeoutline.parse')
|
|
15
15
|
-- Reference scans stop at a result count or time budget and report truncation.
|
|
16
|
-
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
17
|
MAX_FILE_BYTES = 1048576, CACHE_FILES = 64 }
|
|
18
18
|
|
|
19
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 }
|
|
20
24
|
local ANY = setmetatable({}, { __index = function() return true end })
|
|
21
25
|
-- Bare identifiers bind only nearby, except type names used across files.
|
|
22
26
|
local TYPES = { class = true, struct = true, union = true, interface = true, enum = true, record = true,
|
|
23
|
-
typedef = true, namespace = true, annotation_type = true }
|
|
24
|
-
--
|
|
27
|
+
typedef = true, namespace = true, annotation_type = true, trait = true }
|
|
28
|
+
-- Call hierarchy covers callables; type references use explicit type-site evidence.
|
|
25
29
|
local REFERENCE = { ['function'] = true, method = true, macro = true, constructor = true,
|
|
26
30
|
prototype = true, destructor = true }
|
|
27
31
|
local CALLS = { ['function'] = true, method = true, macro = true, constructor = true,
|
|
@@ -70,16 +74,18 @@ end
|
|
|
70
74
|
-- files. Overlay files and nodes take ids after every resident one; masked
|
|
71
75
|
-- resident nodes drop out of name lists, which keep path and node order.
|
|
72
76
|
-- Nothing is written to the resident tables.
|
|
73
|
-
local function view(session, root)
|
|
77
|
+
local function view(session, root, include_paths, only)
|
|
74
78
|
local idx = service.resident(root)
|
|
75
79
|
local G = idx:symbols()
|
|
76
80
|
local V = setmetatable({ root = root, idx = idx, drafts = {}, disk = {}, dep_cache = {}, new_files = {},
|
|
77
81
|
next_file = G.next_file, next_node = G.next_node, next_dir = G.next_dir }, { __index = G })
|
|
78
82
|
V.js_context = require('codeoutline.js_resolution').context(V)
|
|
83
|
+
V.js_context.include_paths = include_paths
|
|
79
84
|
V.js_context.lua = require('codeoutline.lua_bindings').context(V)
|
|
80
85
|
V.js_context.ordinary = require('codeoutline.ordinary_bindings').context(V, V.js_context, function(f)
|
|
81
86
|
return V.drafts[f] and V.drafts[f].source
|
|
82
|
-
end)
|
|
87
|
+
end, { cache = binding_cache, parsed = function(f) return M.full(V, f) end })
|
|
88
|
+
V.js_context.lua.ordinary = V.js_context.ordinary
|
|
83
89
|
for _, name in ipairs({ 'files', 'nodes', 'node_file', 'id_of', 'file_index', 'file_dir' }) do
|
|
84
90
|
V[name] = setmetatable({}, { __index = G[name] })
|
|
85
91
|
end
|
|
@@ -88,6 +94,11 @@ local function view(session, root)
|
|
|
88
94
|
local rel = doc.path and relative(root, doc.path)
|
|
89
95
|
local f = rel and V.file_index[rel]
|
|
90
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
|
|
91
102
|
local rec = doc:parse()
|
|
92
103
|
if not rec.language then return nil end
|
|
93
104
|
if f then masked[f] = true
|
|
@@ -143,7 +154,7 @@ local function view(session, root)
|
|
|
143
154
|
local drafts = {}
|
|
144
155
|
for _, doc in pairs(sessions[session] or {}) do drafts[#drafts + 1] = doc end
|
|
145
156
|
table.sort(drafts, function(a, b) return a.uri < b.uri end)
|
|
146
|
-
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
|
|
147
158
|
return V
|
|
148
159
|
end
|
|
149
160
|
|
|
@@ -153,20 +164,7 @@ end
|
|
|
153
164
|
local function deps(V, f)
|
|
154
165
|
local entry = V.dep_cache[f]
|
|
155
166
|
if not entry then
|
|
156
|
-
local direct, paired = graph.
|
|
157
|
-
if C_FAMILY[V.files[f].language] then
|
|
158
|
-
local queue = {}
|
|
159
|
-
for g in pairs(direct) do queue[#queue + 1] = g end
|
|
160
|
-
local i = 1
|
|
161
|
-
while i <= #queue and #queue < M.MAX_INCLUDES do
|
|
162
|
-
local more, sources = graph.dependencies(V, queue[i])
|
|
163
|
-
for h in pairs(sources) do paired[h] = true end
|
|
164
|
-
for h in pairs(more) do
|
|
165
|
-
if not direct[h] and h ~= f then direct[h] = true; queue[#queue + 1] = h end
|
|
166
|
-
end
|
|
167
|
-
i = i + 1
|
|
168
|
-
end
|
|
169
|
-
end
|
|
167
|
+
local direct, paired = graph.visible_dependencies(V, f, V.js_context)
|
|
170
168
|
entry = { direct, paired }
|
|
171
169
|
V.dep_cache[f] = entry
|
|
172
170
|
end
|
|
@@ -191,14 +189,25 @@ local function recursive(node, recv)
|
|
|
191
189
|
end
|
|
192
190
|
|
|
193
191
|
-- Targets of one occurrence of name in file f, enclosed by node index from.
|
|
194
|
-
local function resolve_site(V, f, from, name, kind, recv, evidence, offset, index)
|
|
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
|
|
195
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
|
|
196
203
|
local src = from > 0 and V.id_of[f][from] or nil
|
|
197
204
|
local direct, paired = deps(V, f)
|
|
198
205
|
local rkind, accept = kind, nil
|
|
199
206
|
if kind == 'symbol' then rkind, accept = 'call', ANY
|
|
200
207
|
elseif kind == 'member_symbol' then rkind, accept = 'member_call', ANY end
|
|
201
|
-
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 {}
|
|
202
211
|
if kind == 'symbol' then
|
|
203
212
|
local kept = {}
|
|
204
213
|
for _, id in ipairs(targets) do
|
|
@@ -210,13 +219,13 @@ local function resolve_site(V, f, from, name, kind, recv, evidence, offset, inde
|
|
|
210
219
|
targets = kept
|
|
211
220
|
end
|
|
212
221
|
-- The resolver never binds a ref to its enclosing node, which hides recursion.
|
|
213
|
-
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
|
|
214
223
|
targets = { src }
|
|
215
224
|
end
|
|
216
225
|
-- Definitions too far apart to choose between: a visible prototype still
|
|
217
226
|
-- names the function, and going to its definition lists them all.
|
|
218
227
|
if #targets == 0 and (kind == 'call' or kind == 'ref') then
|
|
219
|
-
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 {}
|
|
220
229
|
end
|
|
221
230
|
-- A native object: the local's initializer chain names the metatable whose
|
|
222
231
|
-- methods the C side registers (`local pool = mod.open()`, then `pool:read()`).
|
|
@@ -245,18 +254,24 @@ local function resolve_site(V, f, from, name, kind, recv, evidence, offset, inde
|
|
|
245
254
|
end
|
|
246
255
|
targets = kept
|
|
247
256
|
end
|
|
248
|
-
return targets
|
|
257
|
+
return targets, reason, evidence, macro_state
|
|
249
258
|
end
|
|
250
259
|
|
|
251
260
|
-- What the cursor names: a declaration, an indexed reference, or another identifier.
|
|
252
|
-
local function find_cursor(doc, offset, strict)
|
|
253
|
-
local rec = doc:parse()
|
|
261
|
+
local function find_cursor(doc, offset, strict, parsed)
|
|
262
|
+
local rec = parsed or doc:parse()
|
|
254
263
|
local function inside(a, b) return a <= offset and (offset < b or (not strict and offset == b)) end
|
|
255
264
|
for n, node in ipairs(rec.nodes) do
|
|
256
265
|
if node.name_start and inside(node.name_start, node.name_end) then
|
|
257
266
|
return { decl = n, name = node.name, first = node.name_start, last = node.name_end }
|
|
258
267
|
end
|
|
259
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
|
|
260
275
|
local refs = rec.refs
|
|
261
276
|
if refs and refs.start then
|
|
262
277
|
for i = 1, #refs.name do
|
|
@@ -270,16 +285,29 @@ local function find_cursor(doc, offset, strict)
|
|
|
270
285
|
end
|
|
271
286
|
end
|
|
272
287
|
|
|
273
|
-
local function cursor(doc, offset)
|
|
288
|
+
local function cursor(doc, offset, V, f, include_inactive)
|
|
274
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
|
|
275
295
|
if found then return found end
|
|
276
|
-
|
|
296
|
+
rec = rec or doc:parse()
|
|
297
|
+
T = T or doc:tokens()
|
|
277
298
|
if not T then return nil end
|
|
278
|
-
local
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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)
|
|
283
311
|
end
|
|
284
312
|
if not t then return nil end
|
|
285
313
|
local kind, recv = 'symbol', nil
|
|
@@ -305,6 +333,11 @@ local function cursor(doc, offset)
|
|
|
305
333
|
while (T:text(first - 1) == '.' or T:text(first - 1) == '::') and T.k[first - 2] == 'id' do first = first - 2 end
|
|
306
334
|
local name = require('codeoutline.csharp_bindings').name(T.src:sub(T.s[first], T.e[t]))
|
|
307
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
|
|
308
341
|
end
|
|
309
342
|
return { from = from, name = T:text(t), kind = kind, recv = recv, first = T.s[t] - 1, last = T.e[t], evidence = evidence }
|
|
310
343
|
end
|
|
@@ -326,36 +359,57 @@ end
|
|
|
326
359
|
-- Full parse (record plus tokens) of one file, cached per record. Shared with
|
|
327
360
|
-- completion, which needs tokens for types this index does not store.
|
|
328
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
|
+
|
|
329
368
|
function M.full(V, f, native)
|
|
330
369
|
local draft = V.drafts and V.drafts[f]
|
|
331
370
|
if draft then
|
|
332
371
|
draft.full = draft.full or {}
|
|
333
372
|
local entry = draft.full
|
|
334
373
|
if not entry.rec or native and not entry.foreign then
|
|
335
|
-
entry.rec, entry.tokens = parse.parse_tokens(draft.path or V.files[f].path, draft.source,
|
|
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 })
|
|
336
376
|
entry.foreign = native
|
|
337
377
|
end
|
|
338
378
|
return entry.rec, entry.tokens, draft
|
|
339
379
|
end
|
|
340
380
|
local key = V.files[f]
|
|
341
381
|
local entry = full_cache[key]
|
|
342
|
-
if entry == nil or native and not entry.foreign then
|
|
343
|
-
local fresh = entry == nil
|
|
382
|
+
if entry == nil or not entry.tokens or native and not entry.foreign then
|
|
344
383
|
if (key.size or 0) > M.MAX_FILE_BYTES then return nil end
|
|
345
384
|
local doc = source_doc(V, f)
|
|
346
385
|
-- Read/parse failures are transient, unlike a successful empty result.
|
|
347
386
|
if not doc then return nil end
|
|
348
|
-
local rec, tokens = parse.parse_tokens(key.path, doc.source,
|
|
387
|
+
local rec, tokens = parse.parse_tokens(key.path, doc.source,
|
|
388
|
+
{ foreign = native, language = key.language, ordinary_bindings = true })
|
|
349
389
|
if not rec then return nil end
|
|
350
390
|
entry = { rec = rec, tokens = tokens, foreign = native }
|
|
351
|
-
|
|
352
|
-
if fresh then full_order[#full_order + 1] = key end
|
|
353
|
-
if #full_order > M.CACHE_FILES then full_cache[table.remove(full_order, 1)] = nil end
|
|
391
|
+
cache_full(key, entry)
|
|
354
392
|
end
|
|
355
393
|
if not entry then return nil end
|
|
356
394
|
return entry.rec, entry.tokens
|
|
357
395
|
end
|
|
358
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
|
+
|
|
359
413
|
-- Restore display/type details without attaching them to resident index nodes.
|
|
360
414
|
function M.detail(V, f, node)
|
|
361
415
|
if node.sig then return node end
|
|
@@ -388,7 +442,7 @@ local function locate(V, id)
|
|
|
388
442
|
local n, f = index_of(V, id)
|
|
389
443
|
local node, doc = V.nodes[id], source_doc(V, f)
|
|
390
444
|
if not doc then return nil end
|
|
391
|
-
local nodes = doc
|
|
445
|
+
local nodes = position_record(V, f, doc).nodes
|
|
392
446
|
local hit = nodes[n]
|
|
393
447
|
if hit and hit.name == node.name and hit.qualified == node.qualified and hit.name_start then return doc, hit end
|
|
394
448
|
hit = nil
|
|
@@ -441,7 +495,7 @@ end
|
|
|
441
495
|
local function site_range(V, f, i)
|
|
442
496
|
local doc = source_doc(V, f)
|
|
443
497
|
if not doc then return nil end
|
|
444
|
-
local refs, indexed = doc
|
|
498
|
+
local refs, indexed = position_record(V, f, doc).refs, V.files[f].refs
|
|
445
499
|
if not refs or not refs.start then return nil end
|
|
446
500
|
local j = i
|
|
447
501
|
if refs.name[i] ~= indexed.name[i] or refs.line[i] ~= indexed.line[i] then
|
|
@@ -470,6 +524,19 @@ local function is_decl(node) return not not graph.is_decl(node) end
|
|
|
470
524
|
-- A declaration and its definitions (prototypes, in-class declarations) as one target.
|
|
471
525
|
local function expand(V, set)
|
|
472
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
|
|
473
540
|
for id in pairs(set) do
|
|
474
541
|
out[id] = true
|
|
475
542
|
local node = V.nodes[id]
|
|
@@ -477,7 +544,7 @@ local function expand(V, set)
|
|
|
477
544
|
for _, cid in ipairs(V.by_name[node.name]) do
|
|
478
545
|
local c = V.nodes[cid]
|
|
479
546
|
if c.qualified == node.qualified and is_decl(c) ~= is_decl(node)
|
|
480
|
-
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
|
|
481
548
|
end
|
|
482
549
|
end
|
|
483
550
|
return out
|
|
@@ -497,6 +564,11 @@ local function scan(V, targets, name)
|
|
|
497
564
|
local wanted = { [name] = true }
|
|
498
565
|
for id in pairs(targets) do
|
|
499
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
|
|
500
572
|
end
|
|
501
573
|
local files = {}
|
|
502
574
|
for i, f in ipairs(V.file_order) do files[i] = f end
|
|
@@ -505,7 +577,16 @@ local function scan(V, targets, name)
|
|
|
505
577
|
for _, f in ipairs(files) do
|
|
506
578
|
control.check()
|
|
507
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
|
|
508
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
|
|
509
590
|
local names = refs.name
|
|
510
591
|
local aliases = {}
|
|
511
592
|
if V.files[f].language == 'kotlin' then
|
|
@@ -517,7 +598,7 @@ local function scan(V, targets, name)
|
|
|
517
598
|
if i % 4096 == 0 then control.check() end
|
|
518
599
|
if wanted[names[i]] or aliases[names[i]] or aliases[refs.recv[i]]
|
|
519
600
|
or alias_refs[i]
|
|
520
|
-
or (
|
|
601
|
+
or (lua_evidence and lua_evidence[i] ~= '') then
|
|
521
602
|
if os.clock() > deadline then return hits, true end
|
|
522
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
|
|
523
604
|
if targets[dst] then hits[#hits + 1] = { f, i }; break end
|
|
@@ -526,18 +607,25 @@ local function scan(V, targets, name)
|
|
|
526
607
|
end
|
|
527
608
|
end
|
|
528
609
|
end
|
|
529
|
-
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
|
|
530
612
|
end
|
|
531
613
|
|
|
532
614
|
-- Files one import record resolves to, through the graph's dependency
|
|
533
615
|
-- rules: a temporary record holding only that import.
|
|
534
616
|
function M.import_files(V, f, imp)
|
|
535
617
|
local rec = V.files[f]
|
|
536
|
-
|
|
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,
|
|
537
624
|
nodes = {}, imports = { imp } }
|
|
538
625
|
rawset(V.files, -1, fake)
|
|
539
|
-
local ok, direct = pcall(graph.dependencies, V, -1)
|
|
626
|
+
local ok, direct = pcall(graph.dependencies, V, -1, V.js_context, true)
|
|
540
627
|
rawset(V.files, -1, nil)
|
|
628
|
+
if not ok and control.is_interrupted(direct) then error(direct, 0) end
|
|
541
629
|
local files = {}
|
|
542
630
|
if ok then for g in pairs(direct) do files[#files + 1] = g end end
|
|
543
631
|
table.sort(files, function(x, y) return V.files[x].path < V.files[y].path end)
|
|
@@ -606,19 +694,22 @@ end
|
|
|
606
694
|
|
|
607
695
|
-- Locations of the files an import on this line names: project files by the
|
|
608
696
|
-- dependency rules, and C/C++ headers found in the include directories.
|
|
609
|
-
local function import_targets(V, f, line
|
|
697
|
+
local function import_targets(V, f, line)
|
|
610
698
|
local rec, result, seen = V.files[f], {}, {}
|
|
611
699
|
local function add(uri)
|
|
612
700
|
if not seen[uri] then seen[uri] = true; result[#result + 1] = { uri = uri, range = line_range(1) } end
|
|
613
701
|
end
|
|
614
702
|
for _, imp in ipairs(rec.imports or {}) do
|
|
615
703
|
if imp.line == line then
|
|
616
|
-
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
|
|
617
709
|
for _, g in ipairs(files) do add(uri_of(V, g)) end
|
|
618
|
-
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
|
|
619
712
|
local dirs = {}
|
|
620
|
-
if not imp.system then dirs[1] = (V.idx:abs(rec.path):match('^(.*)/[^/]*$')) end
|
|
621
|
-
for _, dir in ipairs(include_paths or {}) do dirs[#dirs + 1] = paths.normalize(dir) end
|
|
622
713
|
for _, dir in ipairs(probe_includes()) do dirs[#dirs + 1] = dir end
|
|
623
714
|
for _, dir in ipairs(dirs) do
|
|
624
715
|
local file = dir .. '/' .. imp.path:gsub('\\', '/')
|
|
@@ -1008,22 +1099,89 @@ end
|
|
|
1008
1099
|
local function at(req)
|
|
1009
1100
|
local doc = request_doc(req)
|
|
1010
1101
|
if not doc then return nil end
|
|
1011
|
-
local V = view(req.session, req.root)
|
|
1102
|
+
local V = view(req.session, req.root, req.includePaths)
|
|
1012
1103
|
local f = V.add(doc)
|
|
1013
1104
|
if not f then return nil end
|
|
1014
1105
|
local offset = doc:offset(req.position)
|
|
1015
|
-
local c = cursor(doc, offset)
|
|
1016
|
-
local targets = {}
|
|
1106
|
+
local c = cursor(doc, offset, V, f, req.method == 'lsp_definition')
|
|
1107
|
+
local targets, reason, evidence, macro_state = {}
|
|
1017
1108
|
if c and c.decl then targets = { V.id_of[f][c.decl] }
|
|
1018
|
-
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
|
|
1019
1114
|
return V, doc, c, targets, f, offset
|
|
1020
1115
|
end
|
|
1021
1116
|
|
|
1022
1117
|
local handlers = {}
|
|
1023
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
|
+
|
|
1024
1174
|
function handlers.lsp_definition(req)
|
|
1025
1175
|
local V, doc, c, targets, f, offset = at(req)
|
|
1026
1176
|
if not V then return false end
|
|
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
|
|
1027
1185
|
local configured, incomplete
|
|
1028
1186
|
-- Rule arguments are strings or referenced values, never the name of a
|
|
1029
1187
|
-- call/declaration itself. Avoid collecting dispatch sites for ordinary F12.
|
|
@@ -1032,6 +1190,14 @@ function handlers.lsp_definition(req)
|
|
|
1032
1190
|
end
|
|
1033
1191
|
if configured then return configured, incomplete end
|
|
1034
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
|
|
1035
1201
|
local importer = false
|
|
1036
1202
|
if c and not c.decl then
|
|
1037
1203
|
-- `require`/`dofile` themselves name the file they load, not a same-named project function.
|
|
@@ -1041,8 +1207,39 @@ function handlers.lsp_definition(req)
|
|
|
1041
1207
|
end
|
|
1042
1208
|
if #targets == 0 or importer then
|
|
1043
1209
|
-- An import line: `require "a.b"`, `dofile("x.lua")`, `#include <x.h>`, `from . import m`.
|
|
1044
|
-
local files = import_targets(V, f, line
|
|
1045
|
-
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
|
|
1046
1243
|
end
|
|
1047
1244
|
if c.decl and is_decl(V.nodes[targets[1]]) then
|
|
1048
1245
|
-- From a declaration, go to its definitions.
|
|
@@ -1054,7 +1251,7 @@ function handlers.lsp_definition(req)
|
|
|
1054
1251
|
end
|
|
1055
1252
|
local result = {}
|
|
1056
1253
|
for _, id in ipairs(targets) do result[#result + 1] = (location(V, id)) end
|
|
1057
|
-
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
|
|
1058
1255
|
end
|
|
1059
1256
|
|
|
1060
1257
|
-- Follow unmatched delimiters up to the cursor. Commas in nested calls,
|
|
@@ -1189,7 +1386,7 @@ local function positions_left(t0, incomplete)
|
|
|
1189
1386
|
end
|
|
1190
1387
|
|
|
1191
1388
|
function handlers.lsp_incoming(req)
|
|
1192
|
-
local V = view(req.session, req.root)
|
|
1389
|
+
local V = view(req.session, req.root, req.includePaths)
|
|
1193
1390
|
local id = relocate(V, req.data)
|
|
1194
1391
|
if not id then return {} end
|
|
1195
1392
|
local name = V.nodes[id].name
|
|
@@ -1213,7 +1410,7 @@ function handlers.lsp_incoming(req)
|
|
|
1213
1410
|
end
|
|
1214
1411
|
|
|
1215
1412
|
function handlers.lsp_outgoing(req)
|
|
1216
|
-
local V = view(req.session, req.root)
|
|
1413
|
+
local V = view(req.session, req.root, req.includePaths)
|
|
1217
1414
|
local f = type(req.data) == 'table' and type(req.data.path) == 'string' and V.file_index[req.data.path]
|
|
1218
1415
|
if not f then return {} end
|
|
1219
1416
|
if not V.drafts[f] then
|
|
@@ -1242,13 +1439,36 @@ function handlers.lsp_outgoing(req)
|
|
|
1242
1439
|
end
|
|
1243
1440
|
end
|
|
1244
1441
|
end
|
|
1245
|
-
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
|
|
1246
1443
|
end
|
|
1247
1444
|
|
|
1248
1445
|
function handlers.lsp_references(req)
|
|
1249
1446
|
local V, _, c, targets = at(req)
|
|
1250
|
-
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
|
|
1251
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
|
|
1252
1472
|
for _, id in ipairs(targets) do
|
|
1253
1473
|
if not REFERENCE[V.nodes[id].kind] then
|
|
1254
1474
|
return { error = 'References currently support functions, methods, constructors and macros only' }
|