@codua/codeoutline-win32-x64 0.2.0 → 0.2.4
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 +7 -1
- package/README.zh-CN.md +4 -1
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/callers.lua +116 -0
- package/scripts/codeoutline/command.lua +7 -3
- package/scripts/codeoutline/common.lua +21 -1
- package/scripts/codeoutline/completion.lua +93 -22
- package/scripts/codeoutline/documents.lua +1 -1
- package/scripts/codeoutline/explore.lua +39 -10
- package/scripts/codeoutline/foreign.lua +60 -0
- package/scripts/codeoutline/foreign_lua.lua +146 -0
- package/scripts/codeoutline/graph.lua +107 -54
- package/scripts/codeoutline/index.lua +7 -3
- package/scripts/codeoutline/index_worker.lua +15 -7
- package/scripts/codeoutline/indirect.lua +225 -0
- package/scripts/codeoutline/js_evidence.lua +175 -0
- package/scripts/codeoutline/js_resolution.lua +201 -0
- package/scripts/codeoutline/lang/kotlin.lua +384 -0
- package/scripts/codeoutline/lang/lua.lua +17 -0
- package/scripts/codeoutline/lsp.lua +58 -34
- package/scripts/codeoutline/lua_bindings.lua +360 -0
- package/scripts/codeoutline/main.lua +24 -3
- package/scripts/codeoutline/mcp.lua +13 -4
- package/scripts/codeoutline/navigation.lua +161 -34
- package/scripts/codeoutline/parse.lua +3 -0
- package/scripts/codeoutline/query_report.lua +36 -0
- package/scripts/codeoutline/service.lua +11 -3
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -73,6 +73,8 @@ local function view(session, root)
|
|
|
73
73
|
local G = idx:symbols()
|
|
74
74
|
local V = setmetatable({ root = root, idx = idx, drafts = {}, disk = {}, dep_cache = {}, new_files = {},
|
|
75
75
|
next_file = G.next_file, next_node = G.next_node, next_dir = G.next_dir }, { __index = G })
|
|
76
|
+
V.js_context = require('codeoutline.js_resolution').context(V)
|
|
77
|
+
V.js_context.lua = require('codeoutline.lua_bindings').context(V)
|
|
76
78
|
for _, name in ipairs({ 'files', 'nodes', 'node_file', 'id_of', 'file_index', 'file_dir' }) do
|
|
77
79
|
V[name] = setmetatable({}, { __index = G[name] })
|
|
78
80
|
end
|
|
@@ -107,6 +109,10 @@ local function view(session, root)
|
|
|
107
109
|
local list = added[node.name]
|
|
108
110
|
if not list then list = {}; added[node.name] = list end
|
|
109
111
|
list[#list + 1] = id
|
|
112
|
+
for _, alias in ipairs(require('codeoutline.lua_bindings').aliases(node, V.lua_global_export_tables)) do
|
|
113
|
+
added[alias] = added[alias] or {}
|
|
114
|
+
added[alias][#added[alias] + 1] = id
|
|
115
|
+
end
|
|
110
116
|
end
|
|
111
117
|
return f
|
|
112
118
|
end
|
|
@@ -142,7 +148,7 @@ end
|
|
|
142
148
|
local function deps(V, f)
|
|
143
149
|
local entry = V.dep_cache[f]
|
|
144
150
|
if not entry then
|
|
145
|
-
local direct, paired = graph.dependencies(V, f)
|
|
151
|
+
local direct, paired = graph.dependencies(V, f, V.js_context)
|
|
146
152
|
if C_FAMILY[V.files[f].language] then
|
|
147
153
|
local queue = {}
|
|
148
154
|
for g in pairs(direct) do queue[#queue + 1] = g end
|
|
@@ -180,13 +186,13 @@ local function recursive(node, recv)
|
|
|
180
186
|
end
|
|
181
187
|
|
|
182
188
|
-- Targets of one occurrence of name in file f, enclosed by node index from.
|
|
183
|
-
local function resolve_site(V, f, from, name, kind, recv)
|
|
189
|
+
local function resolve_site(V, f, from, name, kind, recv, evidence)
|
|
184
190
|
local src = from > 0 and V.id_of[f][from] or nil
|
|
185
191
|
local direct, paired = deps(V, f)
|
|
186
192
|
local rkind, accept = kind, nil
|
|
187
193
|
if kind == 'symbol' then rkind, accept = 'call', ANY
|
|
188
194
|
elseif kind == 'member_symbol' then rkind, accept = 'member_call', ANY end
|
|
189
|
-
local targets = graph.resolve(V, f, src, name, rkind, recv or nil, direct, paired, accept) or {}
|
|
195
|
+
local targets = graph.resolve(V, f, src, name, rkind, recv or nil, direct, paired, accept, evidence, V.js_context) or {}
|
|
190
196
|
if kind == 'symbol' then
|
|
191
197
|
local kept = {}
|
|
192
198
|
for _, id in ipairs(targets) do
|
|
@@ -204,7 +210,7 @@ local function resolve_site(V, f, from, name, kind, recv)
|
|
|
204
210
|
-- Definitions too far apart to choose between: a visible prototype still
|
|
205
211
|
-- names the function, and going to its definition lists them all.
|
|
206
212
|
if #targets == 0 and (kind == 'call' or kind == 'ref') then
|
|
207
|
-
targets = graph.resolve(V, f, src, name, kind, recv or nil, direct, paired, PROTOTYPE) or {}
|
|
213
|
+
targets = graph.resolve(V, f, src, name, kind, recv or nil, direct, paired, PROTOTYPE, evidence, V.js_context) or {}
|
|
208
214
|
end
|
|
209
215
|
if C_FAMILY[V.files[f].language] then
|
|
210
216
|
-- C binds only what its includes make visible; a lone far definition
|
|
@@ -235,6 +241,7 @@ local function find_cursor(doc, offset, strict)
|
|
|
235
241
|
local a = refs.start[i]
|
|
236
242
|
if a and inside(a, refs.stop[i]) then
|
|
237
243
|
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],
|
|
238
245
|
first = a, last = refs.stop[i] }
|
|
239
246
|
end
|
|
240
247
|
end
|
|
@@ -405,6 +412,10 @@ end
|
|
|
405
412
|
-- Hot names can match thousands of files; past the budget the scan stops.
|
|
406
413
|
local function scan(V, targets, name)
|
|
407
414
|
local hits, deadline = {}, os.clock() + M.SCAN_SECONDS
|
|
415
|
+
local wanted = { [name] = true }
|
|
416
|
+
for id in pairs(targets) do
|
|
417
|
+
for _, alias in ipairs(require('codeoutline.lua_bindings').aliases(V.nodes[id], V.lua_global_export_tables)) do wanted[alias] = true end
|
|
418
|
+
end
|
|
408
419
|
local files = {}
|
|
409
420
|
for i, f in ipairs(V.file_order) do files[i] = f end
|
|
410
421
|
for _, f in ipairs(V.new_files) do files[#files + 1] = f end
|
|
@@ -412,11 +423,18 @@ local function scan(V, targets, name)
|
|
|
412
423
|
control.check()
|
|
413
424
|
local refs = V.files[f].refs
|
|
414
425
|
local names = refs.name
|
|
426
|
+
local aliases = {}
|
|
427
|
+
for _, binding in ipairs(V.files[f].js_imports or {}) do aliases[binding.local_name] = true end
|
|
428
|
+
if V.files[f].language == 'kotlin' then
|
|
429
|
+
for _, imp in ipairs(V.files[f].imports) do
|
|
430
|
+
if imp.alias and imp.path:match('([^.]+)$') == name then aliases[imp.alias] = true end
|
|
431
|
+
end
|
|
432
|
+
end
|
|
415
433
|
for i = 1, #names do
|
|
416
434
|
if i % 4096 == 0 then control.check() end
|
|
417
|
-
if names[i]
|
|
435
|
+
if wanted[names[i]] or aliases[names[i]] or aliases[refs.recv[i]] or (refs.lua_binding and refs.lua_binding[i] ~= '') then
|
|
418
436
|
if os.clock() > deadline then return hits, true end
|
|
419
|
-
for _, dst in ipairs(resolve_site(V, f, refs.from[i],
|
|
437
|
+
for _, dst in ipairs(resolve_site(V, f, refs.from[i], names[i], refs.kind[i], refs.recv[i], refs.lua_binding and refs.lua_binding[i] or refs.js_receiver and refs.js_receiver[i])) do
|
|
420
438
|
if targets[dst] then hits[#hits + 1] = { f, i }; break end
|
|
421
439
|
end
|
|
422
440
|
if #hits >= M.MAX_RESULTS then return hits, true end
|
|
@@ -541,14 +559,33 @@ local function definition_rules(root)
|
|
|
541
559
|
for _, rule in ipairs(rules) do
|
|
542
560
|
assert(type(rule) == 'table' and (rule.language == nil or rule.language == 'lua'),
|
|
543
561
|
'definitionRules currently support language lua')
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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')
|
|
552
589
|
end
|
|
553
590
|
end
|
|
554
591
|
return rules
|
|
@@ -633,6 +670,33 @@ local function literal_argument(T, call, argument)
|
|
|
633
670
|
end
|
|
634
671
|
end
|
|
635
672
|
|
|
673
|
+
local DECLARABLE = { ['function'] = true, method = true }
|
|
674
|
+
|
|
675
|
+
-- A string literal being written as a table key: t["name"] = ... or { ["name"] = ... }.
|
|
676
|
+
-- Returns the decoded value and the owner identifier for assignments (nil in constructors).
|
|
677
|
+
local function key_literal(T, i)
|
|
678
|
+
if i < 3 or i + 2 > T.n or T.k[i] ~= 'str' then return nil end
|
|
679
|
+
if T:text(i - 1) ~= '[' or T:text(i + 1) ~= ']' or T:text(i + 2) ~= '=' then return nil end
|
|
680
|
+
local value = string_value(T:text(i))
|
|
681
|
+
if not value then return nil end
|
|
682
|
+
local owner
|
|
683
|
+
if T.k[i - 2] == 'id' and T:text(i - 3) ~= '.' and T:text(i - 3) ~= ':' then
|
|
684
|
+
owner = T:text(i - 2)
|
|
685
|
+
end
|
|
686
|
+
return value, owner
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
local function qualifier_matches(rule, owner)
|
|
690
|
+
return not rule.qualifiers or (owner ~= nil and rule.qualifiers[owner])
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
-- A rule name also binds colon calls by their method segment: self:callCluster matches callCluster.
|
|
694
|
+
local function call_matches(name, rule_name)
|
|
695
|
+
if not name then return false end
|
|
696
|
+
if name == rule_name then return true end
|
|
697
|
+
return name:find(':') ~= nil and name:match('([%w_]+)$') == rule_name
|
|
698
|
+
end
|
|
699
|
+
|
|
636
700
|
local function configured_definition(V, doc, offset)
|
|
637
701
|
if doc:parse().language ~= 'lua' then return nil end
|
|
638
702
|
local rules = definition_rules(V.root)
|
|
@@ -643,7 +707,7 @@ local function configured_definition(V, doc, offset)
|
|
|
643
707
|
if i % 128 == 0 then control.check() end
|
|
644
708
|
local name = call_name(tokens, i)
|
|
645
709
|
for _, rule in ipairs(rules) do
|
|
646
|
-
if name
|
|
710
|
+
if call_matches(name, rule.call) then
|
|
647
711
|
local value, first, last = literal_argument(tokens, i, rule.argument)
|
|
648
712
|
if value and first <= offset and offset < last then matched[#matched + 1] = { rule, value } end
|
|
649
713
|
end
|
|
@@ -651,18 +715,48 @@ local function configured_definition(V, doc, offset)
|
|
|
651
715
|
end
|
|
652
716
|
if #matched == 0 then return nil end
|
|
653
717
|
local result, seen, files = {}, {}, {}
|
|
718
|
+
local function add(loc)
|
|
719
|
+
local start = loc.range.start
|
|
720
|
+
local key = loc.uri .. ':' .. start.line .. ':' .. start.character
|
|
721
|
+
if not seen[key] then
|
|
722
|
+
seen[key] = true
|
|
723
|
+
result[#result + 1] = loc
|
|
724
|
+
end
|
|
725
|
+
return #result >= M.MAX_RESULTS
|
|
726
|
+
end
|
|
727
|
+
local calls, keys = {}, {}
|
|
728
|
+
local deadline = os.clock() + M.SCAN_SECONDS
|
|
729
|
+
for _, match in ipairs(matched) do
|
|
730
|
+
if match[1].targetKind == 'declaration' then
|
|
731
|
+
for _, id in ipairs(V.by_name[match[2]]) do
|
|
732
|
+
control.check()
|
|
733
|
+
if os.clock() > deadline then return result, true end
|
|
734
|
+
local node = V.nodes[id]
|
|
735
|
+
if DECLARABLE[node.kind] and V.files[V.node_file[id]].language == 'lua' then
|
|
736
|
+
local owner = graph.owner(node.qualified or node.name)
|
|
737
|
+
if qualifier_matches(match[1], owner) and add(location(V, id)) then
|
|
738
|
+
return result, true
|
|
739
|
+
end
|
|
740
|
+
end
|
|
741
|
+
end
|
|
742
|
+
elseif match[1].targetKind == 'key' then
|
|
743
|
+
keys[#keys + 1] = match
|
|
744
|
+
else
|
|
745
|
+
calls[#calls + 1] = match
|
|
746
|
+
end
|
|
747
|
+
end
|
|
748
|
+
if #calls == 0 and #keys == 0 then return result, false end
|
|
654
749
|
for _, f in ipairs(V.file_order) do files[#files + 1] = f end
|
|
655
750
|
for _, f in ipairs(V.new_files) do files[#files + 1] = f end
|
|
656
751
|
table.sort(files, function(a, b) return V.files[a].path < V.files[b].path end)
|
|
657
|
-
local deadline = os.clock() + M.SCAN_SECONDS
|
|
658
752
|
for _, f in ipairs(files) do
|
|
659
753
|
control.check()
|
|
660
754
|
if os.clock() > deadline then return result, true end
|
|
661
755
|
if V.files[f].language == 'lua' then
|
|
662
756
|
local target = source_doc(V, f)
|
|
663
757
|
if target then
|
|
664
|
-
local candidate =
|
|
665
|
-
for _, match in ipairs(
|
|
758
|
+
local candidate = #keys > 0
|
|
759
|
+
for _, match in ipairs(calls) do
|
|
666
760
|
local tail = match[1].target:match('([%w_]+)$')
|
|
667
761
|
if target.source:find(tail, 1, true) then candidate = true; break end
|
|
668
762
|
end
|
|
@@ -674,15 +768,23 @@ local function configured_definition(V, doc, offset)
|
|
|
674
768
|
if os.clock() > deadline then return result, true end
|
|
675
769
|
end
|
|
676
770
|
local name = call_name(T, i)
|
|
677
|
-
for _, match in ipairs(
|
|
678
|
-
if name
|
|
771
|
+
for _, match in ipairs(calls) do
|
|
772
|
+
if call_matches(name, match[1].target) then
|
|
679
773
|
local value, first, last = literal_argument(T, i, match[1].targetArgument)
|
|
680
774
|
if value == match[2] then
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
775
|
+
if add({ uri = target.uri, range = target:range(first, last) }) then
|
|
776
|
+
return result, true
|
|
777
|
+
end
|
|
778
|
+
end
|
|
779
|
+
end
|
|
780
|
+
end
|
|
781
|
+
if #keys > 0 then
|
|
782
|
+
local value, owner = key_literal(T, i)
|
|
783
|
+
if value then
|
|
784
|
+
for _, match in ipairs(keys) do
|
|
785
|
+
if value == match[2] and qualifier_matches(match[1], owner)
|
|
786
|
+
and add({ uri = target.uri, range = target:range(T.s[i] - 1, T.e[i]) }) then
|
|
787
|
+
return result, true
|
|
686
788
|
end
|
|
687
789
|
end
|
|
688
790
|
end
|
|
@@ -705,7 +807,7 @@ local function at(req)
|
|
|
705
807
|
local c = cursor(doc, offset)
|
|
706
808
|
local targets = {}
|
|
707
809
|
if c and c.decl then targets = { V.id_of[f][c.decl] }
|
|
708
|
-
elseif c then targets = resolve_site(V, f, c.from, c.name, c.kind, c.recv) end
|
|
810
|
+
elseif c then targets = resolve_site(V, f, c.from, c.name, c.kind, c.recv, c.evidence) end
|
|
709
811
|
return V, doc, c, targets, f, offset
|
|
710
812
|
end
|
|
711
813
|
|
|
@@ -766,12 +868,25 @@ function handlers.lsp_signature(req)
|
|
|
766
868
|
end
|
|
767
869
|
end
|
|
768
870
|
local call
|
|
871
|
+
local kotlin = doc:parse().language == 'kotlin'
|
|
769
872
|
for i = #stack, 1, -1 do
|
|
770
873
|
local entry = stack[i]
|
|
771
|
-
|
|
874
|
+
local name_token = entry.token - 1
|
|
875
|
+
if kotlin and entry.delimiter == '(' and T:text(name_token) == '>' then
|
|
876
|
+
local depth, k = 1, name_token - 1
|
|
877
|
+
while k > 1 and depth > 0 do
|
|
878
|
+
local s = T:text(k)
|
|
879
|
+
if s == '>' then depth = depth + 1 elseif s == '<' then depth = depth - 1 end
|
|
880
|
+
k = k - 1
|
|
881
|
+
end
|
|
882
|
+
if depth == 0 then name_token = k end
|
|
883
|
+
end
|
|
884
|
+
if entry.delimiter == '(' and T.k[name_token] == 'id' then
|
|
885
|
+
call = entry; call.name_token = name_token; break
|
|
886
|
+
end
|
|
772
887
|
end
|
|
773
888
|
if not call then return false end
|
|
774
|
-
local name_token = call.
|
|
889
|
+
local name_token = call.name_token
|
|
775
890
|
local query = {}
|
|
776
891
|
for key, value in pairs(req) do query[key] = value end
|
|
777
892
|
query.position = doc:position(T.s[name_token] - 1)
|
|
@@ -780,8 +895,13 @@ function handlers.lsp_signature(req)
|
|
|
780
895
|
local signatures, seen = {}, {}
|
|
781
896
|
for _, id in ipairs(targets) do
|
|
782
897
|
local node = V.nodes[id]
|
|
898
|
+
local foreign = require('codeoutline.foreign').signature(node, doc:parse().language, T:text(name_token))
|
|
783
899
|
local label = node.sig
|
|
784
|
-
if
|
|
900
|
+
if foreign and not seen[foreign.label] then
|
|
901
|
+
foreign.activeParameter = #foreign.parameters > 0 and math.min(call.argument, #foreign.parameters - 1) or nil
|
|
902
|
+
signatures[#signatures + 1] = foreign
|
|
903
|
+
seen[foreign.label] = true
|
|
904
|
+
elseif not foreign and REFERENCE[node.kind] and label and not seen[label] then
|
|
785
905
|
local sig_doc = documents.new(uri_of(V, V.node_file[id]), label, 0)
|
|
786
906
|
local S = sig_doc:tokens()
|
|
787
907
|
local opening
|
|
@@ -790,10 +910,14 @@ function handlers.lsp_signature(req)
|
|
|
790
910
|
end
|
|
791
911
|
local ending = opening and S.m[opening]
|
|
792
912
|
if ending then
|
|
793
|
-
local parameters, start, i = {}, S.e[opening] + 1, opening + 1
|
|
913
|
+
local parameters, start, i, angle_depth = {}, S.e[opening] + 1, opening + 1, 0
|
|
794
914
|
while i <= ending do
|
|
795
915
|
local s = S:text(i)
|
|
796
|
-
if
|
|
916
|
+
if kotlin and S.k[i] == 'op' then
|
|
917
|
+
if s == '<' then angle_depth = angle_depth + 1
|
|
918
|
+
elseif s == '>' then angle_depth = math.max(0, angle_depth - 1) end
|
|
919
|
+
end
|
|
920
|
+
if i == ending or (s == ',' and angle_depth == 0) then
|
|
797
921
|
local parameter = label:sub(start, S.s[i] - 1):match('^%s*(.-)%s*$')
|
|
798
922
|
if parameter ~= '' and parameter ~= 'void' then parameters[#parameters + 1] = { label = parameter } end
|
|
799
923
|
start = S.e[i] + 1
|
|
@@ -817,7 +941,9 @@ function handlers.lsp_hover(req)
|
|
|
817
941
|
for k, id in ipairs(targets) do
|
|
818
942
|
if k > M.MAX_HOVER then break end
|
|
819
943
|
local node, rec = V.nodes[id], V.files[V.node_file[id]]
|
|
820
|
-
|
|
944
|
+
local foreign = require('codeoutline.foreign').signature(node, doc:parse().language, doc.source:sub(c.first + 1, c.last))
|
|
945
|
+
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```'
|
|
821
947
|
parts[#parts + 1] = node.kind .. ' `' .. node.qualified .. '` — ' .. rec.path .. ':' .. node.line
|
|
822
948
|
end
|
|
823
949
|
return { contents = { kind = 'markdown', value = table.concat(parts, '\n\n') }, range = doc:range(c.first, c.last) }
|
|
@@ -879,7 +1005,7 @@ function handlers.lsp_outgoing(req)
|
|
|
879
1005
|
for i = 1, #refs.name do
|
|
880
1006
|
if i % 128 == 0 then control.check() end
|
|
881
1007
|
if refs.from[i] == from then
|
|
882
|
-
for _, dst in ipairs(resolve_site(V, f, from, refs.name[i], refs.kind[i], refs.recv[i])) do
|
|
1008
|
+
for _, dst in ipairs(resolve_site(V, f, from, refs.name[i], refs.kind[i], refs.recv[i], refs.lua_binding and refs.lua_binding[i] or refs.js_receiver and refs.js_receiver[i])) do
|
|
883
1009
|
local group = groups[dst]
|
|
884
1010
|
if not group then
|
|
885
1011
|
group = { to = item(V, dst), fromRanges = {} }
|
|
@@ -905,7 +1031,8 @@ function handlers.lsp_references(req)
|
|
|
905
1031
|
set[id] = true
|
|
906
1032
|
end
|
|
907
1033
|
set = expand(V, set)
|
|
908
|
-
local
|
|
1034
|
+
local name = V.files[V.node_file[targets[1]]].language == 'kotlin' and V.nodes[targets[1]].name or c.name
|
|
1035
|
+
local hits, incomplete = scan(V, set, name)
|
|
909
1036
|
local result, t0 = {}, os.clock()
|
|
910
1037
|
if req.includeDeclaration then
|
|
911
1038
|
for _, id in ipairs(sorted(set)) do result[#result + 1] = (location(V, id)) end
|
|
@@ -19,6 +19,7 @@ M.EXTENSIONS = {
|
|
|
19
19
|
c = 'c', h = 'c',
|
|
20
20
|
py = 'python', pyi = 'python',
|
|
21
21
|
java = 'java',
|
|
22
|
+
kt = 'kotlin', kts = 'kotlin',
|
|
22
23
|
lua = 'lua',
|
|
23
24
|
cpp = 'cpp', cc = 'cpp', cxx = 'cpp', hpp = 'cpp', hh = 'cpp', hxx = 'cpp', ipp = 'cpp',
|
|
24
25
|
go = 'go',
|
|
@@ -48,6 +49,8 @@ function M.parse_tokens(path, src, opts)
|
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
-- opts.ranges=false emits compact index nodes; default parsing retains positions.
|
|
52
|
+
-- opts.dispatch_only=true is transient query data, not an index record: it
|
|
53
|
+
-- retains parser nodes/refs and skips binding evidence and record packing.
|
|
51
54
|
function M.parse(path, src, opts)
|
|
52
55
|
return (M.parse_tokens(path, src, opts))
|
|
53
56
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- Bounded, query-owned explanations; never stored on index records.
|
|
2
|
+
local M = {}
|
|
3
|
+
|
|
4
|
+
function M.new(limit)
|
|
5
|
+
local report = { entries = {}, truncated = false, scope = 'indexed references and configured dispatch rules' }
|
|
6
|
+
local seen = {}
|
|
7
|
+
function report:add(entry)
|
|
8
|
+
local key = table.concat({ entry.source or '', entry.target or '', entry.line or '',
|
|
9
|
+
entry.kind or '', entry.reason or '', entry.rule or '', entry.call or '' }, ':')
|
|
10
|
+
if seen[key] then return end
|
|
11
|
+
if #self.entries >= (limit or 64) then self.truncated = true; return end
|
|
12
|
+
seen[key] = true
|
|
13
|
+
self.entries[#self.entries + 1] = entry
|
|
14
|
+
end
|
|
15
|
+
return report
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
function M.render(report, G)
|
|
19
|
+
local lines = { '\n## Relationship evidence / unresolved references',
|
|
20
|
+
'Scope: indexed references and configured dispatch rules; unresolved does not mean no runtime call.' }
|
|
21
|
+
for _, e in ipairs(report.entries) do
|
|
22
|
+
local source = G.nodes[e.source]
|
|
23
|
+
local path = source and G.files[G.node_file[e.source]].path or '?'
|
|
24
|
+
local target = e.target and G.nodes[e.target].qualified
|
|
25
|
+
local detail = e.reason or e.kind
|
|
26
|
+
if e.call then detail = detail .. ' via ' .. e.call end
|
|
27
|
+
if e.rule then detail = detail .. ' (rule #' .. e.rule .. ', argument ' .. e.argument .. ')' end
|
|
28
|
+
if e.registered_at then detail = detail .. '; registered at ' .. e.registered_at end
|
|
29
|
+
lines[#lines + 1] = string.format('- %s:%d %s%s: %s', path, e.line or 0,
|
|
30
|
+
source and source.qualified or '?', target and ' -> ' .. target or '', detail)
|
|
31
|
+
end
|
|
32
|
+
if report.truncated then lines[#lines + 1] = 'Evidence limit reached; additional explanations omitted.' end
|
|
33
|
+
return table.concat(lines, '\n')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
return M
|
|
@@ -144,14 +144,14 @@ function M.resident(root)
|
|
|
144
144
|
return p.idx, p.idx.symbol_tables
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
function
|
|
148
|
-
|
|
147
|
+
local function run_query(engine, root, query, opts)
|
|
148
|
+
engine.validate(query, opts)
|
|
149
149
|
local idx, _, stats = refresh(root, opts, true)
|
|
150
150
|
idx.query_sources = {}
|
|
151
151
|
local ok, result = pcall(function()
|
|
152
152
|
while true do
|
|
153
153
|
-- A GBK repair commits the decoded file, which renumbers its nodes.
|
|
154
|
-
local output, details =
|
|
154
|
+
local output, details = engine.run(idx:symbols(), idx, query, opts)
|
|
155
155
|
control.check()
|
|
156
156
|
if not details.encoding_retry then return { text = output, info = details } end
|
|
157
157
|
end
|
|
@@ -166,6 +166,14 @@ function M.explore(root, query, opts)
|
|
|
166
166
|
return result.text, result.info
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
+
function M.explore(root, query, opts)
|
|
170
|
+
return run_query(explore, root, query, opts)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
function M.callers(root, query, opts)
|
|
174
|
+
return run_query(require('codeoutline.callers'), root, query, opts)
|
|
175
|
+
end
|
|
176
|
+
|
|
169
177
|
function M.status(root, opts)
|
|
170
178
|
local idx, G, stats = M.get(root, opts)
|
|
171
179
|
local languages = {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return
|
|
1
|
+
return 13
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.2.
|
|
1
|
+
return '0.2.4'
|