@codua/codeoutline-win32-x64 0.2.0 → 0.2.1
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 +6 -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/common.lua +10 -1
- package/scripts/codeoutline/completion.lua +30 -7
- package/scripts/codeoutline/documents.lua +1 -1
- package/scripts/codeoutline/explore.lua +3 -1
- package/scripts/codeoutline/graph.lua +61 -38
- package/scripts/codeoutline/index.lua +2 -2
- package/scripts/codeoutline/indirect.lua +201 -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 +2 -0
- package/scripts/codeoutline/lua_bindings.lua +222 -0
- package/scripts/codeoutline/navigation.lua +144 -32
- package/scripts/codeoutline/parse.lua +1 -0
- 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
|
|
@@ -142,7 +144,7 @@ end
|
|
|
142
144
|
local function deps(V, f)
|
|
143
145
|
local entry = V.dep_cache[f]
|
|
144
146
|
if not entry then
|
|
145
|
-
local direct, paired = graph.dependencies(V, f)
|
|
147
|
+
local direct, paired = graph.dependencies(V, f, V.js_context)
|
|
146
148
|
if C_FAMILY[V.files[f].language] then
|
|
147
149
|
local queue = {}
|
|
148
150
|
for g in pairs(direct) do queue[#queue + 1] = g end
|
|
@@ -180,13 +182,13 @@ local function recursive(node, recv)
|
|
|
180
182
|
end
|
|
181
183
|
|
|
182
184
|
-- 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)
|
|
185
|
+
local function resolve_site(V, f, from, name, kind, recv, evidence)
|
|
184
186
|
local src = from > 0 and V.id_of[f][from] or nil
|
|
185
187
|
local direct, paired = deps(V, f)
|
|
186
188
|
local rkind, accept = kind, nil
|
|
187
189
|
if kind == 'symbol' then rkind, accept = 'call', ANY
|
|
188
190
|
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 {}
|
|
191
|
+
local targets = graph.resolve(V, f, src, name, rkind, recv or nil, direct, paired, accept, evidence, V.js_context) or {}
|
|
190
192
|
if kind == 'symbol' then
|
|
191
193
|
local kept = {}
|
|
192
194
|
for _, id in ipairs(targets) do
|
|
@@ -204,7 +206,7 @@ local function resolve_site(V, f, from, name, kind, recv)
|
|
|
204
206
|
-- Definitions too far apart to choose between: a visible prototype still
|
|
205
207
|
-- names the function, and going to its definition lists them all.
|
|
206
208
|
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 {}
|
|
209
|
+
targets = graph.resolve(V, f, src, name, kind, recv or nil, direct, paired, PROTOTYPE, evidence, V.js_context) or {}
|
|
208
210
|
end
|
|
209
211
|
if C_FAMILY[V.files[f].language] then
|
|
210
212
|
-- C binds only what its includes make visible; a lone far definition
|
|
@@ -235,6 +237,7 @@ local function find_cursor(doc, offset, strict)
|
|
|
235
237
|
local a = refs.start[i]
|
|
236
238
|
if a and inside(a, refs.stop[i]) then
|
|
237
239
|
return { from = refs.from[i], name = refs.name[i], kind = refs.kind[i], recv = refs.recv[i],
|
|
240
|
+
evidence = refs.lua_binding and refs.lua_binding[i] or refs.js_receiver and refs.js_receiver[i],
|
|
238
241
|
first = a, last = refs.stop[i] }
|
|
239
242
|
end
|
|
240
243
|
end
|
|
@@ -412,11 +415,18 @@ local function scan(V, targets, name)
|
|
|
412
415
|
control.check()
|
|
413
416
|
local refs = V.files[f].refs
|
|
414
417
|
local names = refs.name
|
|
418
|
+
local aliases = {}
|
|
419
|
+
for _, binding in ipairs(V.files[f].js_imports or {}) do aliases[binding.local_name] = true end
|
|
420
|
+
if V.files[f].language == 'kotlin' then
|
|
421
|
+
for _, imp in ipairs(V.files[f].imports) do
|
|
422
|
+
if imp.alias and imp.path:match('([^.]+)$') == name then aliases[imp.alias] = true end
|
|
423
|
+
end
|
|
424
|
+
end
|
|
415
425
|
for i = 1, #names do
|
|
416
426
|
if i % 4096 == 0 then control.check() end
|
|
417
|
-
if names[i] == name then
|
|
427
|
+
if names[i] == name or aliases[names[i]] or aliases[refs.recv[i]] or (refs.lua_binding and refs.lua_binding[i] ~= '') then
|
|
418
428
|
if os.clock() > deadline then return hits, true end
|
|
419
|
-
for _, dst in ipairs(resolve_site(V, f, refs.from[i],
|
|
429
|
+
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
430
|
if targets[dst] then hits[#hits + 1] = { f, i }; break end
|
|
421
431
|
end
|
|
422
432
|
if #hits >= M.MAX_RESULTS then return hits, true end
|
|
@@ -541,14 +551,33 @@ local function definition_rules(root)
|
|
|
541
551
|
for _, rule in ipairs(rules) do
|
|
542
552
|
assert(type(rule) == 'table' and (rule.language == nil or rule.language == 'lua'),
|
|
543
553
|
'definitionRules currently support language lua')
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
554
|
+
assert(type(rule.call) == 'string' and rule.call:match('^[%a_][%w_%.:]*$'),
|
|
555
|
+
'definitionRules.call must be a qualified function name')
|
|
556
|
+
assert(type(rule.argument) == 'number' and rule.argument >= 1 and rule.argument <= 32
|
|
557
|
+
and rule.argument % 1 == 0,
|
|
558
|
+
'definitionRules.argument must be an integer from 1 to 32')
|
|
559
|
+
local kind = rule.targetKind or 'call'
|
|
560
|
+
assert(kind == 'call' or kind == 'declaration' or kind == 'key',
|
|
561
|
+
"definitionRules.targetKind must be 'call', 'declaration' or 'key'")
|
|
562
|
+
if kind ~= 'call' then
|
|
563
|
+
assert(rule.target == nil and rule.targetArgument == nil,
|
|
564
|
+
'declaration and key rules must not set target or targetArgument')
|
|
565
|
+
if rule.qualifiers ~= nil then
|
|
566
|
+
assert(type(rule.qualifiers) == 'table', 'definitionRules.qualifiers must be an array of names')
|
|
567
|
+
local qualifiers = {}
|
|
568
|
+
for _, q in ipairs(rule.qualifiers) do
|
|
569
|
+
assert(type(q) == 'string' and q:match('^[%a_][%w_]*$'),
|
|
570
|
+
'definitionRules.qualifiers must contain plain names')
|
|
571
|
+
qualifiers[q] = true
|
|
572
|
+
end
|
|
573
|
+
rule.qualifiers = qualifiers
|
|
574
|
+
end
|
|
575
|
+
else
|
|
576
|
+
assert(type(rule.target) == 'string' and rule.target:match('^[%a_][%w_%.:]*$'),
|
|
577
|
+
'definitionRules.target must be a qualified function name')
|
|
578
|
+
assert(type(rule.targetArgument) == 'number' and rule.targetArgument >= 1
|
|
579
|
+
and rule.targetArgument <= 32 and rule.targetArgument % 1 == 0,
|
|
580
|
+
'definitionRules.targetArgument must be an integer from 1 to 32')
|
|
552
581
|
end
|
|
553
582
|
end
|
|
554
583
|
return rules
|
|
@@ -633,6 +662,33 @@ local function literal_argument(T, call, argument)
|
|
|
633
662
|
end
|
|
634
663
|
end
|
|
635
664
|
|
|
665
|
+
local DECLARABLE = { ['function'] = true, method = true }
|
|
666
|
+
|
|
667
|
+
-- A string literal being written as a table key: t["name"] = ... or { ["name"] = ... }.
|
|
668
|
+
-- Returns the decoded value and the owner identifier for assignments (nil in constructors).
|
|
669
|
+
local function key_literal(T, i)
|
|
670
|
+
if i < 3 or i + 2 > T.n or T.k[i] ~= 'str' then return nil end
|
|
671
|
+
if T:text(i - 1) ~= '[' or T:text(i + 1) ~= ']' or T:text(i + 2) ~= '=' then return nil end
|
|
672
|
+
local value = string_value(T:text(i))
|
|
673
|
+
if not value then return nil end
|
|
674
|
+
local owner
|
|
675
|
+
if T.k[i - 2] == 'id' and T:text(i - 3) ~= '.' and T:text(i - 3) ~= ':' then
|
|
676
|
+
owner = T:text(i - 2)
|
|
677
|
+
end
|
|
678
|
+
return value, owner
|
|
679
|
+
end
|
|
680
|
+
|
|
681
|
+
local function qualifier_matches(rule, owner)
|
|
682
|
+
return not rule.qualifiers or (owner ~= nil and rule.qualifiers[owner])
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
-- A rule name also binds colon calls by their method segment: self:callCluster matches callCluster.
|
|
686
|
+
local function call_matches(name, rule_name)
|
|
687
|
+
if not name then return false end
|
|
688
|
+
if name == rule_name then return true end
|
|
689
|
+
return name:find(':') ~= nil and name:match('([%w_]+)$') == rule_name
|
|
690
|
+
end
|
|
691
|
+
|
|
636
692
|
local function configured_definition(V, doc, offset)
|
|
637
693
|
if doc:parse().language ~= 'lua' then return nil end
|
|
638
694
|
local rules = definition_rules(V.root)
|
|
@@ -643,7 +699,7 @@ local function configured_definition(V, doc, offset)
|
|
|
643
699
|
if i % 128 == 0 then control.check() end
|
|
644
700
|
local name = call_name(tokens, i)
|
|
645
701
|
for _, rule in ipairs(rules) do
|
|
646
|
-
if name
|
|
702
|
+
if call_matches(name, rule.call) then
|
|
647
703
|
local value, first, last = literal_argument(tokens, i, rule.argument)
|
|
648
704
|
if value and first <= offset and offset < last then matched[#matched + 1] = { rule, value } end
|
|
649
705
|
end
|
|
@@ -651,18 +707,48 @@ local function configured_definition(V, doc, offset)
|
|
|
651
707
|
end
|
|
652
708
|
if #matched == 0 then return nil end
|
|
653
709
|
local result, seen, files = {}, {}, {}
|
|
710
|
+
local function add(loc)
|
|
711
|
+
local start = loc.range.start
|
|
712
|
+
local key = loc.uri .. ':' .. start.line .. ':' .. start.character
|
|
713
|
+
if not seen[key] then
|
|
714
|
+
seen[key] = true
|
|
715
|
+
result[#result + 1] = loc
|
|
716
|
+
end
|
|
717
|
+
return #result >= M.MAX_RESULTS
|
|
718
|
+
end
|
|
719
|
+
local calls, keys = {}, {}
|
|
720
|
+
local deadline = os.clock() + M.SCAN_SECONDS
|
|
721
|
+
for _, match in ipairs(matched) do
|
|
722
|
+
if match[1].targetKind == 'declaration' then
|
|
723
|
+
for _, id in ipairs(V.by_name[match[2]]) do
|
|
724
|
+
control.check()
|
|
725
|
+
if os.clock() > deadline then return result, true end
|
|
726
|
+
local node = V.nodes[id]
|
|
727
|
+
if DECLARABLE[node.kind] and V.files[V.node_file[id]].language == 'lua' then
|
|
728
|
+
local owner = graph.owner(node.qualified or node.name)
|
|
729
|
+
if qualifier_matches(match[1], owner) and add(location(V, id)) then
|
|
730
|
+
return result, true
|
|
731
|
+
end
|
|
732
|
+
end
|
|
733
|
+
end
|
|
734
|
+
elseif match[1].targetKind == 'key' then
|
|
735
|
+
keys[#keys + 1] = match
|
|
736
|
+
else
|
|
737
|
+
calls[#calls + 1] = match
|
|
738
|
+
end
|
|
739
|
+
end
|
|
740
|
+
if #calls == 0 and #keys == 0 then return result, false end
|
|
654
741
|
for _, f in ipairs(V.file_order) do files[#files + 1] = f end
|
|
655
742
|
for _, f in ipairs(V.new_files) do files[#files + 1] = f end
|
|
656
743
|
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
744
|
for _, f in ipairs(files) do
|
|
659
745
|
control.check()
|
|
660
746
|
if os.clock() > deadline then return result, true end
|
|
661
747
|
if V.files[f].language == 'lua' then
|
|
662
748
|
local target = source_doc(V, f)
|
|
663
749
|
if target then
|
|
664
|
-
local candidate =
|
|
665
|
-
for _, match in ipairs(
|
|
750
|
+
local candidate = #keys > 0
|
|
751
|
+
for _, match in ipairs(calls) do
|
|
666
752
|
local tail = match[1].target:match('([%w_]+)$')
|
|
667
753
|
if target.source:find(tail, 1, true) then candidate = true; break end
|
|
668
754
|
end
|
|
@@ -674,15 +760,23 @@ local function configured_definition(V, doc, offset)
|
|
|
674
760
|
if os.clock() > deadline then return result, true end
|
|
675
761
|
end
|
|
676
762
|
local name = call_name(T, i)
|
|
677
|
-
for _, match in ipairs(
|
|
678
|
-
if name
|
|
763
|
+
for _, match in ipairs(calls) do
|
|
764
|
+
if call_matches(name, match[1].target) then
|
|
679
765
|
local value, first, last = literal_argument(T, i, match[1].targetArgument)
|
|
680
766
|
if value == match[2] then
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
767
|
+
if add({ uri = target.uri, range = target:range(first, last) }) then
|
|
768
|
+
return result, true
|
|
769
|
+
end
|
|
770
|
+
end
|
|
771
|
+
end
|
|
772
|
+
end
|
|
773
|
+
if #keys > 0 then
|
|
774
|
+
local value, owner = key_literal(T, i)
|
|
775
|
+
if value then
|
|
776
|
+
for _, match in ipairs(keys) do
|
|
777
|
+
if value == match[2] and qualifier_matches(match[1], owner)
|
|
778
|
+
and add({ uri = target.uri, range = target:range(T.s[i] - 1, T.e[i]) }) then
|
|
779
|
+
return result, true
|
|
686
780
|
end
|
|
687
781
|
end
|
|
688
782
|
end
|
|
@@ -705,7 +799,7 @@ local function at(req)
|
|
|
705
799
|
local c = cursor(doc, offset)
|
|
706
800
|
local targets = {}
|
|
707
801
|
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
|
|
802
|
+
elseif c then targets = resolve_site(V, f, c.from, c.name, c.kind, c.recv, c.evidence) end
|
|
709
803
|
return V, doc, c, targets, f, offset
|
|
710
804
|
end
|
|
711
805
|
|
|
@@ -766,12 +860,25 @@ function handlers.lsp_signature(req)
|
|
|
766
860
|
end
|
|
767
861
|
end
|
|
768
862
|
local call
|
|
863
|
+
local kotlin = doc:parse().language == 'kotlin'
|
|
769
864
|
for i = #stack, 1, -1 do
|
|
770
865
|
local entry = stack[i]
|
|
771
|
-
|
|
866
|
+
local name_token = entry.token - 1
|
|
867
|
+
if kotlin and entry.delimiter == '(' and T:text(name_token) == '>' then
|
|
868
|
+
local depth, k = 1, name_token - 1
|
|
869
|
+
while k > 1 and depth > 0 do
|
|
870
|
+
local s = T:text(k)
|
|
871
|
+
if s == '>' then depth = depth + 1 elseif s == '<' then depth = depth - 1 end
|
|
872
|
+
k = k - 1
|
|
873
|
+
end
|
|
874
|
+
if depth == 0 then name_token = k end
|
|
875
|
+
end
|
|
876
|
+
if entry.delimiter == '(' and T.k[name_token] == 'id' then
|
|
877
|
+
call = entry; call.name_token = name_token; break
|
|
878
|
+
end
|
|
772
879
|
end
|
|
773
880
|
if not call then return false end
|
|
774
|
-
local name_token = call.
|
|
881
|
+
local name_token = call.name_token
|
|
775
882
|
local query = {}
|
|
776
883
|
for key, value in pairs(req) do query[key] = value end
|
|
777
884
|
query.position = doc:position(T.s[name_token] - 1)
|
|
@@ -790,10 +897,14 @@ function handlers.lsp_signature(req)
|
|
|
790
897
|
end
|
|
791
898
|
local ending = opening and S.m[opening]
|
|
792
899
|
if ending then
|
|
793
|
-
local parameters, start, i = {}, S.e[opening] + 1, opening + 1
|
|
900
|
+
local parameters, start, i, angle_depth = {}, S.e[opening] + 1, opening + 1, 0
|
|
794
901
|
while i <= ending do
|
|
795
902
|
local s = S:text(i)
|
|
796
|
-
if
|
|
903
|
+
if kotlin and S.k[i] == 'op' then
|
|
904
|
+
if s == '<' then angle_depth = angle_depth + 1
|
|
905
|
+
elseif s == '>' then angle_depth = math.max(0, angle_depth - 1) end
|
|
906
|
+
end
|
|
907
|
+
if i == ending or (s == ',' and angle_depth == 0) then
|
|
797
908
|
local parameter = label:sub(start, S.s[i] - 1):match('^%s*(.-)%s*$')
|
|
798
909
|
if parameter ~= '' and parameter ~= 'void' then parameters[#parameters + 1] = { label = parameter } end
|
|
799
910
|
start = S.e[i] + 1
|
|
@@ -879,7 +990,7 @@ function handlers.lsp_outgoing(req)
|
|
|
879
990
|
for i = 1, #refs.name do
|
|
880
991
|
if i % 128 == 0 then control.check() end
|
|
881
992
|
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
|
|
993
|
+
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
994
|
local group = groups[dst]
|
|
884
995
|
if not group then
|
|
885
996
|
group = { to = item(V, dst), fromRanges = {} }
|
|
@@ -905,7 +1016,8 @@ function handlers.lsp_references(req)
|
|
|
905
1016
|
set[id] = true
|
|
906
1017
|
end
|
|
907
1018
|
set = expand(V, set)
|
|
908
|
-
local
|
|
1019
|
+
local name = V.files[V.node_file[targets[1]]].language == 'kotlin' and V.nodes[targets[1]].name or c.name
|
|
1020
|
+
local hits, incomplete = scan(V, set, name)
|
|
909
1021
|
local result, t0 = {}, os.clock()
|
|
910
1022
|
if req.includeDeclaration then
|
|
911
1023
|
for _, id in ipairs(sorted(set)) do result[#result + 1] = (location(V, id)) end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return
|
|
1
|
+
return 11
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.2.
|
|
1
|
+
return '0.2.1'
|