@codua/codeoutline-win32-x64 0.3.7 → 0.3.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.
@@ -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
@@ -220,7 +224,9 @@ local function resolve_site(V, f, from, name, kind, recv, evidence, offset, inde
220
224
  end
221
225
  -- The resolver never binds a ref to its enclosing node, which hides recursion.
222
226
  local receiver_bound = recv and evidence and evidence ~= '' or reason and reason:match('^receiver:')
223
- if #targets == 0 and not receiver_bound 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
227
+ if #targets == 0 and not receiver_bound and reason ~= 'unknown or unsupported macro visibility'
228
+ and reason ~= 'receiver binding unresolved' and src and V.nodes[src].name == name
229
+ and (kind == 'call' or recursive(V.nodes[src], recv)) then
224
230
  targets = { src }
225
231
  end
226
232
  -- Definitions too far apart to choose between: a visible prototype still
@@ -1095,16 +1101,31 @@ local function legacy_definition(V, doc, offset, rules)
1095
1101
  end
1096
1102
  end
1097
1103
  if #calls == 0 and #keys == 0 then return result, false end
1098
- for _, f in ipairs(V.file_order) do files[#files + 1] = f end
1099
- for _, f in ipairs(V.new_files) do files[#files + 1] = f end
1104
+ local scoped = #calls == 0
1105
+ local seen_files = {}
1106
+ for _, match in ipairs(keys) do
1107
+ local path = match[1].targetPath
1108
+ if not path then scoped = false; break end
1109
+ local f = V.file_index[path]
1110
+ if f and not seen_files[f] then files[#files + 1] = f; seen_files[f] = true end
1111
+ end
1112
+ if not scoped then
1113
+ files = {}
1114
+ for _, f in ipairs(V.file_order) do files[#files + 1] = f end
1115
+ for _, f in ipairs(V.new_files) do files[#files + 1] = f end
1116
+ end
1100
1117
  table.sort(files, function(a, b) return V.files[a].path < V.files[b].path end)
1101
1118
  for _, f in ipairs(files) do
1102
1119
  control.check()
1103
1120
  if os.clock() > deadline then return result, true end
1104
1121
  if V.files[f].language == 'lua' then
1122
+ local file_keys = {}
1123
+ for _, match in ipairs(keys) do
1124
+ if not match[1].targetPath or match[1].targetPath == V.files[f].path then file_keys[#file_keys + 1] = match end
1125
+ end
1105
1126
  local target = source_doc(V, f)
1106
1127
  if target then
1107
- local candidate = #keys > 0
1128
+ local candidate = #file_keys > 0
1108
1129
  for _, match in ipairs(calls) do
1109
1130
  local tail = match[1].target:match('([%w_]+)$')
1110
1131
  if target.source:find(tail, 1, true) then candidate = true; break end
@@ -1116,7 +1137,7 @@ local function legacy_definition(V, doc, offset, rules)
1116
1137
  control.check()
1117
1138
  if os.clock() > deadline then return result, true end
1118
1139
  end
1119
- local name = call_name(T, i)
1140
+ local name = #calls > 0 and call_name(T, i)
1120
1141
  for _, match in ipairs(calls) do
1121
1142
  if call_matches(name, match[1].target) then
1122
1143
  local value, first, last = literal_argument(T, i, match[1].targetArgument)
@@ -1127,10 +1148,10 @@ local function legacy_definition(V, doc, offset, rules)
1127
1148
  end
1128
1149
  end
1129
1150
  end
1130
- if #keys > 0 then
1151
+ if #file_keys > 0 then
1131
1152
  local value, owner = key_literal(T, i)
1132
1153
  if value then
1133
- for _, match in ipairs(keys) do
1154
+ for _, match in ipairs(file_keys) do
1134
1155
  if value == match[2] and qualifier_matches(match[1], owner)
1135
1156
  and add({ uri = target.uri, range = target:range(T.s[i] - 1, T.e[i]) }) then
1136
1157
  return result, true
@@ -1187,6 +1208,33 @@ end
1187
1208
 
1188
1209
  local handlers = {}
1189
1210
 
1211
+ local function lua_self_member(V, f, c)
1212
+ return c and c.recv == 'self' and V.files[f].language == 'lua'
1213
+ and (c.kind == 'member_call' or c.kind == 'member_symbol')
1214
+ end
1215
+
1216
+ local function definition_tags(V, f, c)
1217
+ local self_fallback = lua_self_member(V, f, c) and c.evidence and c.evidence:match('^lua%-self:%d+$')
1218
+ local ids, info = require('codeoutline.query.definition_candidates').find(V, f, c, V.js_context, self_fallback, true)
1219
+ local result, seen, bytes, started, count = {}, {}, 0, os.clock(), 0
1220
+ for _, id in ipairs(ids) do
1221
+ local g = V.node_file[id]
1222
+ local size = V.files[g].size or 0
1223
+ if not seen[g] then
1224
+ if count >= 4 or size > M.MAX_FILE_BYTES or bytes + size > 2 * M.MAX_FILE_BYTES
1225
+ or os.clock() - started >= 0.5 then info.truncated = true; break end
1226
+ seen[g], bytes, count = true, bytes + size, count + 1
1227
+ end
1228
+ local _, hit = locate(V, id)
1229
+ if hit and hit.parent and V.files[g].language == 'lua' then
1230
+ local _, tokens = M.full(V, g)
1231
+ if not tokens or require('codeoutline.analysis.lua.lua_bindings').has_local_receiver(tokens, c.recv, hit.start_byte) then hit = nil end
1232
+ end
1233
+ if hit then result[#result + 1] = id end
1234
+ end
1235
+ return result, info.truncated
1236
+ end
1237
+
1190
1238
  -- Best-effort idle work: share the exact caches used by navigation, rather
1191
1239
  -- than retaining answers that could outlive a document/configuration change.
1192
1240
  function handlers.lsp_warm(req)
@@ -1269,8 +1317,7 @@ function handlers.lsp_definition(req)
1269
1317
  end
1270
1318
  -- Selecting a loader's member asks for that value, not the imported file.
1271
1319
  if #targets == 0 and c and type(c.evidence) == 'string' and c.evidence:match('^lua%-value:') then return {} end
1272
- local lua_self = c and c.recv == 'self' and V.files[f].language == 'lua'
1273
- and (c.kind == 'member_call' or c.kind == 'member_symbol')
1320
+ local lua_self = lua_self_member(V, f, c)
1274
1321
  local importer = false
1275
1322
  if c and not c.decl and not lua_self then
1276
1323
  -- `require`/`dofile` themselves name the file they load, not a same-named project function.
@@ -1297,22 +1344,10 @@ function handlers.lsp_definition(req)
1297
1344
  return result, info.truncated
1298
1345
  end
1299
1346
  end
1300
- local self_fallback = lua_self and c.evidence and c.evidence:match('^lua%-self:%d+$')
1301
- local ids, info = require('codeoutline.query.definition_candidates').find(V, f, c, V.js_context, self_fallback)
1302
- local result, seen, bytes, started = {}, {}, 0, os.clock()
1303
- local count = 0
1304
- for _, id in ipairs(ids) do
1305
- local g = V.node_file[id]
1306
- local size = V.files[g].size or 0
1307
- if not seen[g] then
1308
- if count >= 4 or size > M.MAX_FILE_BYTES or bytes + size > 2 * M.MAX_FILE_BYTES
1309
- or os.clock() - started >= 0.5 then info.truncated = true; break end
1310
- seen[g], bytes, count = true, bytes + size, count + 1
1311
- end
1312
- local target_doc, hit = locate(V, id)
1313
- if hit then result[#result + 1] = { uri = target_doc.uri, range = target_doc:range(hit.name_start, hit.name_end) } end
1314
- end
1315
- return result, info.truncated or V.js_context.include_incomplete or V.js_context.workspace_incomplete
1347
+ local ids, truncated = definition_tags(V, f, c)
1348
+ local result = {}
1349
+ for _, id in ipairs(ids) do result[#result + 1] = (location(V, id)) end
1350
+ return result, truncated or V.js_context.include_incomplete or V.js_context.workspace_incomplete
1316
1351
  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
1317
1352
  end
1318
1353
  if c.decl and is_decl(V.nodes[targets[1]]) then
@@ -1468,7 +1503,7 @@ function handlers.lsp_signature(req)
1468
1503
  if i % 128 == 0 then control.check() end
1469
1504
  if language == 'lua' and T.k[i] == 'kw' then
1470
1505
  local s = T:text(i)
1471
- if lua_blocks[s] then
1506
+ if lua_blocks[s] and (s ~= 'function' or T:text(i - 1) ~= ':') then
1472
1507
  stack[#stack + 1] = { token = i, delimiter = s, block = true, argument = 0 }
1473
1508
  elseif s == 'end' or s == 'until' then
1474
1509
  while #stack > 0 do if table.remove(stack).block then break end end
@@ -1512,6 +1547,7 @@ function handlers.lsp_signature(req)
1512
1547
  query.position = doc:position(T.s[name_token] - 1)
1513
1548
  local V, _, c, targets, f = at(query)
1514
1549
  if not V or not c or c.decl then return false end
1550
+ if #targets == 0 and language == 'lua' then targets = definition_tags(V, f, c) end
1515
1551
  local signatures, seen = {}, {}
1516
1552
  local function add_signature(node, label, uri, foreign, id)
1517
1553
  if foreign and not seen[foreign.label] then
@@ -1568,8 +1604,11 @@ function handlers.lsp_signature(req)
1568
1604
  end
1569
1605
 
1570
1606
  function handlers.lsp_hover(req)
1571
- local V, doc, c, targets = at(req)
1572
- if not V or #targets == 0 then return false end
1607
+ local V, doc, c, targets, f = at(req)
1608
+ if not V then return false end
1609
+ local fallback = #targets == 0 and V.files[f].language == 'lua'
1610
+ if fallback then targets = definition_tags(V, f, c) end
1611
+ if #targets == 0 then return false end
1573
1612
  local parts = {}
1574
1613
  for k, id in ipairs(targets) do
1575
1614
  if k > M.MAX_HOVER then break end
@@ -1579,7 +1618,8 @@ function handlers.lsp_hover(req)
1579
1618
  .. (foreign and foreign.label or M.detail(V, V.node_file[id], node).sig or node.qualified) .. '\n```'
1580
1619
  local documentation = definition_documentation(V, id)
1581
1620
  if documentation then parts[#parts + 1] = documentation.value end
1582
- parts[#parts + 1] = node.kind .. ' `' .. node.qualified .. '` — ' .. rec.path .. ':' .. node.line
1621
+ parts[#parts + 1] = (fallback and 'Definition candidate · ' or '')
1622
+ .. node.kind .. ' `' .. node.qualified .. '` — ' .. rec.path .. ':' .. node.line
1583
1623
  end
1584
1624
  return { contents = { kind = 'markdown', value = table.concat(parts, '\n\n') }, range = doc:range(c.first, c.last) }
1585
1625
  end
@@ -61,6 +61,14 @@ local function definition(r, label)
61
61
  result.targetKind = r.targetKind or 'call'
62
62
  assert(result.targetKind == 'call' or result.targetKind == 'declaration' or result.targetKind == 'key',
63
63
  "invalid " .. label .. '.targetKind')
64
+ if r.targetPath ~= nil then
65
+ assert(result.targetKind == 'key' and type(r.targetPath) == 'string' and r.targetPath ~= ''
66
+ and not r.targetPath:find('[\\:%z\r\n]') and not r.targetPath:match('^/'),
67
+ label .. '.targetPath must be a project-relative key target path')
68
+ for part in r.targetPath:gmatch('[^/]+') do
69
+ assert(part ~= '.' and part ~= '..', label .. '.targetPath must stay inside the project')
70
+ end
71
+ end
64
72
  if result.targetKind == 'call' then
65
73
  call(r, 'target', label); position(r, 'targetArgument', label)
66
74
  else
@@ -83,7 +91,7 @@ function M.normalize(config)
83
91
  local seen = { definitions = {}, dispatch = {} }
84
92
  local function add(consumer, r)
85
93
  local fields = consumer == 'dispatch' and { 'kind', 'language', 'call', 'argument', 'register', 'keyArgument', 'handlerArgument', 'serviceArgument' }
86
- or { 'language', 'call', 'argument', 'targetKind', 'target', 'targetArgument', 'serviceArgument' }
94
+ or { 'language', 'call', 'argument', 'targetKind', 'target', 'targetArgument', 'serviceArgument', 'targetPath' }
87
95
  local key = {}
88
96
  for _, f in ipairs(fields) do key[#key + 1] = tostring(r[f]) end
89
97
  if r.qualifiers then
@@ -1 +1 @@
1
- return 26
1
+ return 28
@@ -1 +1 @@
1
- return '0.3.7'
1
+ return '0.3.9'