@codua/codeoutline-win32-x64 0.3.6 → 0.3.8
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/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/editors/codeoutline.vsix +0 -0
- package/editors/zed/extension.wasm +0 -0
- package/package.json +1 -1
- package/scripts/codeoutline/analysis/csharp/csharp_bindings.lua +77 -40
- package/scripts/codeoutline/analysis/graph.lua +2 -0
- package/scripts/codeoutline/analysis/implementations.lua +2 -0
- package/scripts/codeoutline/analysis/lua/lua_bindings.lua +206 -25
- package/scripts/codeoutline/analysis/receivers.lua +181 -16
- package/scripts/codeoutline/lang/lua.lua +3 -2
- package/scripts/codeoutline/query/completion.lua +11 -1
- package/scripts/codeoutline/query/definition_candidates.lua +81 -59
- package/scripts/codeoutline/query/navigation.lua +162 -23
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -128,6 +128,10 @@ local function view(session, root, include_paths, only)
|
|
|
128
128
|
added[alias] = added[alias] or {}
|
|
129
129
|
added[alias][#added[alias] + 1] = id
|
|
130
130
|
end
|
|
131
|
+
for _, alias in ipairs(require('codeoutline.analysis.lua.lua_bindings').member_aliases(node)) do
|
|
132
|
+
added[alias] = added[alias] or {}
|
|
133
|
+
added[alias][#added[alias] + 1] = id
|
|
134
|
+
end
|
|
131
135
|
end
|
|
132
136
|
return f
|
|
133
137
|
end
|
|
@@ -1187,6 +1191,33 @@ end
|
|
|
1187
1191
|
|
|
1188
1192
|
local handlers = {}
|
|
1189
1193
|
|
|
1194
|
+
local function lua_self_member(V, f, c)
|
|
1195
|
+
return c and c.recv == 'self' and V.files[f].language == 'lua'
|
|
1196
|
+
and (c.kind == 'member_call' or c.kind == 'member_symbol')
|
|
1197
|
+
end
|
|
1198
|
+
|
|
1199
|
+
local function definition_tags(V, f, c)
|
|
1200
|
+
local self_fallback = lua_self_member(V, f, c) and c.evidence and c.evidence:match('^lua%-self:%d+$')
|
|
1201
|
+
local ids, info = require('codeoutline.query.definition_candidates').find(V, f, c, V.js_context, self_fallback, true)
|
|
1202
|
+
local result, seen, bytes, started, count = {}, {}, 0, os.clock(), 0
|
|
1203
|
+
for _, id in ipairs(ids) do
|
|
1204
|
+
local g = V.node_file[id]
|
|
1205
|
+
local size = V.files[g].size or 0
|
|
1206
|
+
if not seen[g] then
|
|
1207
|
+
if count >= 4 or size > M.MAX_FILE_BYTES or bytes + size > 2 * M.MAX_FILE_BYTES
|
|
1208
|
+
or os.clock() - started >= 0.5 then info.truncated = true; break end
|
|
1209
|
+
seen[g], bytes, count = true, bytes + size, count + 1
|
|
1210
|
+
end
|
|
1211
|
+
local _, hit = locate(V, id)
|
|
1212
|
+
if hit and hit.parent and V.files[g].language == 'lua' then
|
|
1213
|
+
local _, tokens = M.full(V, g)
|
|
1214
|
+
if not tokens or require('codeoutline.analysis.lua.lua_bindings').has_local_receiver(tokens, c.recv, hit.start_byte) then hit = nil end
|
|
1215
|
+
end
|
|
1216
|
+
if hit then result[#result + 1] = id end
|
|
1217
|
+
end
|
|
1218
|
+
return result, info.truncated
|
|
1219
|
+
end
|
|
1220
|
+
|
|
1190
1221
|
-- Best-effort idle work: share the exact caches used by navigation, rather
|
|
1191
1222
|
-- than retaining answers that could outlive a document/configuration change.
|
|
1192
1223
|
function handlers.lsp_warm(req)
|
|
@@ -1269,14 +1300,15 @@ function handlers.lsp_definition(req)
|
|
|
1269
1300
|
end
|
|
1270
1301
|
-- Selecting a loader's member asks for that value, not the imported file.
|
|
1271
1302
|
if #targets == 0 and c and type(c.evidence) == 'string' and c.evidence:match('^lua%-value:') then return {} end
|
|
1303
|
+
local lua_self = lua_self_member(V, f, c)
|
|
1272
1304
|
local importer = false
|
|
1273
|
-
if c and not c.decl then
|
|
1305
|
+
if c and not c.decl and not lua_self then
|
|
1274
1306
|
-- `require`/`dofile` themselves name the file they load, not a same-named project function.
|
|
1275
1307
|
for _, imp in ipairs(V.files[f].imports or {}) do
|
|
1276
1308
|
if imp.line == line and imp.kind == c.name then importer = true end
|
|
1277
1309
|
end
|
|
1278
1310
|
end
|
|
1279
|
-
if #targets == 0 or importer then
|
|
1311
|
+
if (#targets == 0 and not lua_self) or importer then
|
|
1280
1312
|
-- An import line: `require "a.b"`, `dofile("x.lua")`, `#include <x.h>`, `from . import m`.
|
|
1281
1313
|
local files = import_targets(V, f, line)
|
|
1282
1314
|
if #files > 0 or importer then
|
|
@@ -1295,21 +1327,10 @@ function handlers.lsp_definition(req)
|
|
|
1295
1327
|
return result, info.truncated
|
|
1296
1328
|
end
|
|
1297
1329
|
end
|
|
1298
|
-
local ids,
|
|
1299
|
-
local result
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
local g = V.node_file[id]
|
|
1303
|
-
local size = V.files[g].size or 0
|
|
1304
|
-
if not seen[g] then
|
|
1305
|
-
if count >= 4 or size > M.MAX_FILE_BYTES or bytes + size > 2 * M.MAX_FILE_BYTES
|
|
1306
|
-
or os.clock() - started >= 0.5 then info.truncated = true; break end
|
|
1307
|
-
seen[g], bytes, count = true, bytes + size, count + 1
|
|
1308
|
-
end
|
|
1309
|
-
local target_doc, hit = locate(V, id)
|
|
1310
|
-
if hit then result[#result + 1] = { uri = target_doc.uri, range = target_doc:range(hit.name_start, hit.name_end) } end
|
|
1311
|
-
end
|
|
1312
|
-
return result, info.truncated or V.js_context.include_incomplete or V.js_context.workspace_incomplete
|
|
1330
|
+
local ids, truncated = definition_tags(V, f, c)
|
|
1331
|
+
local result = {}
|
|
1332
|
+
for _, id in ipairs(ids) do result[#result + 1] = (location(V, id)) end
|
|
1333
|
+
return result, truncated or V.js_context.include_incomplete or V.js_context.workspace_incomplete
|
|
1313
1334
|
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 or V.js_context.receiver_incomplete
|
|
1314
1335
|
end
|
|
1315
1336
|
if c.decl and is_decl(V.nodes[targets[1]]) then
|
|
@@ -1340,6 +1361,115 @@ local function external_signature(entry)
|
|
|
1340
1361
|
return label
|
|
1341
1362
|
end
|
|
1342
1363
|
|
|
1364
|
+
-- Read adjacent comments from the validated definition source or its draft.
|
|
1365
|
+
local function leading_comments(doc, hit, language)
|
|
1366
|
+
local line = doc:position(hit.start_byte).line + 1
|
|
1367
|
+
local prefix = doc.source:sub(doc.lines[line] + 1, hit.start_byte)
|
|
1368
|
+
local c_style = language ~= 'lua' and language ~= 'python'
|
|
1369
|
+
local marker = c_style and '//[/!]?' or language == 'lua' and '%-%-%-?' or '#'
|
|
1370
|
+
local comments = {}
|
|
1371
|
+
local in_block = false
|
|
1372
|
+
if prefix:find('%S') then
|
|
1373
|
+
local inline = c_style and prefix:match('^%s*/%*%*?(.-)%*/%s*$')
|
|
1374
|
+
if not inline or inline:find('*/', 1, true) or (language == 'rust' and prefix:match('^%s*/%*!')) then return comments end
|
|
1375
|
+
comments[1] = inline:match('^%s*(.-)%s*$')
|
|
1376
|
+
end
|
|
1377
|
+
for i = line - 1, math.max(1, line - 40), -1 do
|
|
1378
|
+
if doc.lines[line] - doc.lines[i] > 8192 then break end
|
|
1379
|
+
local text = doc.source:sub(doc.lines[i] + 1, doc.lines[i + 1]):match('^%s*(.-)%s*$')
|
|
1380
|
+
if (language == 'rust' and (text:match('^//!') or text:match('^/%*!')))
|
|
1381
|
+
or (language == 'python' and text:match('^#!')) then break end
|
|
1382
|
+
local comment = not in_block and text:match('^' .. marker .. '[ \t]*(.*)$')
|
|
1383
|
+
if comment then
|
|
1384
|
+
if language == 'lua' and (comment:match('^%[=*%[') or comment:match('^%]=*%]')) then break end
|
|
1385
|
+
comments[#comments + 1] = comment
|
|
1386
|
+
elseif c_style and (in_block or text:sub(-2) == '*/') then
|
|
1387
|
+
if not in_block then
|
|
1388
|
+
text = text:sub(1, -3)
|
|
1389
|
+
in_block = #comments + 1
|
|
1390
|
+
end
|
|
1391
|
+
if text:find('*/', 1, true) then break end
|
|
1392
|
+
local opening = text:match('^/%*[%*!]?(.*)$')
|
|
1393
|
+
comment = (opening or text:gsub('^%*', '')):match('^%s*(.-)%s*$')
|
|
1394
|
+
if comment ~= '' or not opening then comments[#comments + 1] = comment end
|
|
1395
|
+
if opening then in_block = false end
|
|
1396
|
+
else
|
|
1397
|
+
break
|
|
1398
|
+
end
|
|
1399
|
+
end
|
|
1400
|
+
if in_block then for i = #comments, in_block, -1 do comments[i] = nil end end
|
|
1401
|
+
return comments
|
|
1402
|
+
end
|
|
1403
|
+
|
|
1404
|
+
local function python_docstring(V, f, hit)
|
|
1405
|
+
local _, T = M.full(V, f)
|
|
1406
|
+
if not T then return nil end
|
|
1407
|
+
local lo, hi = 1, T.n
|
|
1408
|
+
while lo < hi do
|
|
1409
|
+
local mid = math.floor((lo + hi) / 2)
|
|
1410
|
+
if T.s[mid] <= hit.name_start then lo = mid + 1 else hi = mid end
|
|
1411
|
+
end
|
|
1412
|
+
if T.s[lo] ~= hit.name_start + 1 then return nil end
|
|
1413
|
+
local i = lo + 1
|
|
1414
|
+
while T.s[i] and T.s[i] - 1 < math.min(hit.end_byte, hit.name_start + 8192) and T.k[i] ~= 'nl' do
|
|
1415
|
+
if T:text(i) == ':' then break end
|
|
1416
|
+
i = (T.m[i] and T.m[i] > i) and T.m[i] + 1 or i + 1
|
|
1417
|
+
end
|
|
1418
|
+
if T:text(i) ~= ':' then return nil end
|
|
1419
|
+
i = i + 1
|
|
1420
|
+
while T.k[i] == 'nl' or T.k[i] == 'indent' do i = i + 1 end
|
|
1421
|
+
if T.k[i] ~= 'str' or T.e[i] > hit.end_byte or T.e[i] - T.s[i] > 8192
|
|
1422
|
+
or (T.k[i + 1] and T.k[i + 1] ~= 'nl' and T.k[i + 1] ~= 'dedent' and T:text(i + 1) ~= ';') then return nil end
|
|
1423
|
+
local literal = T:text(i):gsub('^[rRuU]', '')
|
|
1424
|
+
local quote = literal:match('^"""') or literal:match("^'''") or literal:match('^["\']')
|
|
1425
|
+
if not quote or #literal < 2 * #quote or literal:sub(-#quote) ~= quote then return nil end
|
|
1426
|
+
local value = literal:sub(#quote + 1, -#quote - 1):gsub('\r\n?', '\n')
|
|
1427
|
+
local margin
|
|
1428
|
+
for indent in value:gmatch('\n([ \t]*)%S') do margin = math.min(margin or #indent, #indent) end
|
|
1429
|
+
if margin and margin > 0 then value = value:gsub('\n[ \t]+', function(indent) return '\n' .. indent:sub(margin + 2) end) end
|
|
1430
|
+
return value:match('^%s*(.-)%s*$')
|
|
1431
|
+
end
|
|
1432
|
+
|
|
1433
|
+
local function definition_documentation(V, id)
|
|
1434
|
+
local node, f = V.nodes[id], V.node_file[id]
|
|
1435
|
+
local record = V.files[f]
|
|
1436
|
+
if not REFERENCE[node.kind] or (not V.drafts[f] and (record.size or 0) > M.MAX_FILE_BYTES) then return nil end
|
|
1437
|
+
local doc, hit = locate(V, id)
|
|
1438
|
+
if not hit then return nil end
|
|
1439
|
+
local language = record.language
|
|
1440
|
+
if language == 'python' then
|
|
1441
|
+
local value = python_docstring(V, f, hit)
|
|
1442
|
+
if value and value ~= '' then return { kind = 'markdown', value = value } end
|
|
1443
|
+
end
|
|
1444
|
+
local comments = leading_comments(doc, hit, language)
|
|
1445
|
+
local prose, annotations = {}, {}
|
|
1446
|
+
for i = #comments, 1, -1 do
|
|
1447
|
+
local comment = comments[i]
|
|
1448
|
+
if comment:match('^[@\\]%a+[%s:]') then
|
|
1449
|
+
annotations[#annotations + 1] = language == 'lua' and '---' .. comment or comment
|
|
1450
|
+
else
|
|
1451
|
+
prose[#prose + 1] = comment
|
|
1452
|
+
end
|
|
1453
|
+
end
|
|
1454
|
+
local value = table.concat(prose, ' \n'):match('^%s*(.-)%s*$')
|
|
1455
|
+
if language == 'csharp' then
|
|
1456
|
+
value = value:gsub('<param%s+name="([%w_]+)">', '**Parameter `%1`** ')
|
|
1457
|
+
:gsub('<typeparam%s+name="([%w_]+)">', '**Type parameter `%1`** ')
|
|
1458
|
+
:gsub('<paramref%s+name="([%w_]+)"%s*/>', '`%1`')
|
|
1459
|
+
:gsub('<see%s+cref="([^"\r\n]+)"%s*/>', '`%1`')
|
|
1460
|
+
:gsub('<returns>', '**Returns** '):gsub('<value>', '**Value** ')
|
|
1461
|
+
for _, tag in ipairs({ 'summary', 'remarks', 'param', 'typeparam', 'returns', 'value' }) do
|
|
1462
|
+
value = value:gsub('</?' .. tag .. '>', '')
|
|
1463
|
+
end
|
|
1464
|
+
value = value:match('^%s*(.-)%s*$')
|
|
1465
|
+
end
|
|
1466
|
+
if #annotations > 0 then
|
|
1467
|
+
local fence = language == 'lua' and '```lua\n' or '```text\n'
|
|
1468
|
+
value = value .. (value ~= '' and '\n\n' or '') .. fence .. table.concat(annotations, '\n') .. '\n```'
|
|
1469
|
+
end
|
|
1470
|
+
if value ~= '' then return { kind = 'markdown', value = value } end
|
|
1471
|
+
end
|
|
1472
|
+
|
|
1343
1473
|
-- Follow unmatched delimiters up to the cursor. Commas in nested calls,
|
|
1344
1474
|
-- literals and indexing expressions do not advance the enclosing argument.
|
|
1345
1475
|
function handlers.lsp_signature(req)
|
|
@@ -1356,7 +1486,7 @@ function handlers.lsp_signature(req)
|
|
|
1356
1486
|
if i % 128 == 0 then control.check() end
|
|
1357
1487
|
if language == 'lua' and T.k[i] == 'kw' then
|
|
1358
1488
|
local s = T:text(i)
|
|
1359
|
-
if lua_blocks[s] then
|
|
1489
|
+
if lua_blocks[s] and (s ~= 'function' or T:text(i - 1) ~= ':') then
|
|
1360
1490
|
stack[#stack + 1] = { token = i, delimiter = s, block = true, argument = 0 }
|
|
1361
1491
|
elseif s == 'end' or s == 'until' then
|
|
1362
1492
|
while #stack > 0 do if table.remove(stack).block then break end end
|
|
@@ -1400,10 +1530,12 @@ function handlers.lsp_signature(req)
|
|
|
1400
1530
|
query.position = doc:position(T.s[name_token] - 1)
|
|
1401
1531
|
local V, _, c, targets, f = at(query)
|
|
1402
1532
|
if not V or not c or c.decl then return false end
|
|
1533
|
+
if #targets == 0 and language == 'lua' then targets = definition_tags(V, f, c) end
|
|
1403
1534
|
local signatures, seen = {}, {}
|
|
1404
|
-
local function add_signature(node, label, uri, foreign)
|
|
1535
|
+
local function add_signature(node, label, uri, foreign, id)
|
|
1405
1536
|
if foreign and not seen[foreign.label] then
|
|
1406
1537
|
foreign.activeParameter = #foreign.parameters > 0 and math.min(call.argument, #foreign.parameters - 1) or nil
|
|
1538
|
+
foreign.documentation = id and definition_documentation(V, id) or foreign.documentation
|
|
1407
1539
|
signatures[#signatures + 1] = foreign
|
|
1408
1540
|
seen[foreign.label] = true
|
|
1409
1541
|
elseif not foreign and REFERENCE[node.kind] and label and not seen[label] then
|
|
@@ -1430,6 +1562,7 @@ function handlers.lsp_signature(req)
|
|
|
1430
1562
|
i = i + 1
|
|
1431
1563
|
end
|
|
1432
1564
|
signatures[#signatures + 1] = { label = label, parameters = parameters,
|
|
1565
|
+
documentation = id and definition_documentation(V, id),
|
|
1433
1566
|
activeParameter = #parameters > 0 and math.min(call.argument, #parameters - 1) or nil }
|
|
1434
1567
|
seen[label] = true
|
|
1435
1568
|
end
|
|
@@ -1438,7 +1571,7 @@ function handlers.lsp_signature(req)
|
|
|
1438
1571
|
for _, id in ipairs(targets) do
|
|
1439
1572
|
local node = V.nodes[id]
|
|
1440
1573
|
add_signature(node, M.detail(V, V.node_file[id], node).sig, uri_of(V, V.node_file[id]),
|
|
1441
|
-
require('codeoutline.analysis.foreign').signature(node,
|
|
1574
|
+
require('codeoutline.analysis.foreign').signature(node, language, T:text(name_token)), id)
|
|
1442
1575
|
end
|
|
1443
1576
|
if #targets == 0 and C_FAMILY[doc:parse().language] then
|
|
1444
1577
|
-- Share definition lookup's bounded, source-validated external-header
|
|
@@ -1454,8 +1587,11 @@ function handlers.lsp_signature(req)
|
|
|
1454
1587
|
end
|
|
1455
1588
|
|
|
1456
1589
|
function handlers.lsp_hover(req)
|
|
1457
|
-
local V, doc, c, targets = at(req)
|
|
1458
|
-
if not V
|
|
1590
|
+
local V, doc, c, targets, f = at(req)
|
|
1591
|
+
if not V then return false end
|
|
1592
|
+
local fallback = #targets == 0 and V.files[f].language == 'lua'
|
|
1593
|
+
if fallback then targets = definition_tags(V, f, c) end
|
|
1594
|
+
if #targets == 0 then return false end
|
|
1459
1595
|
local parts = {}
|
|
1460
1596
|
for k, id in ipairs(targets) do
|
|
1461
1597
|
if k > M.MAX_HOVER then break end
|
|
@@ -1463,7 +1599,10 @@ function handlers.lsp_hover(req)
|
|
|
1463
1599
|
local foreign = require('codeoutline.analysis.foreign').signature(node, doc:parse().language, doc.source:sub(c.first + 1, c.last))
|
|
1464
1600
|
parts[#parts + 1] = '```' .. (foreign and doc:parse().language or rec.language or '') .. '\n'
|
|
1465
1601
|
.. (foreign and foreign.label or M.detail(V, V.node_file[id], node).sig or node.qualified) .. '\n```'
|
|
1466
|
-
|
|
1602
|
+
local documentation = definition_documentation(V, id)
|
|
1603
|
+
if documentation then parts[#parts + 1] = documentation.value end
|
|
1604
|
+
parts[#parts + 1] = (fallback and 'Definition candidate · ' or '')
|
|
1605
|
+
.. node.kind .. ' `' .. node.qualified .. '` — ' .. rec.path .. ':' .. node.line
|
|
1467
1606
|
end
|
|
1468
1607
|
return { contents = { kind = 'markdown', value = table.concat(parts, '\n\n') }, range = doc:range(c.first, c.last) }
|
|
1469
1608
|
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return
|
|
1
|
+
return 27
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.3.
|
|
1
|
+
return '0.3.8'
|