Skip to content

Commit 6d18020

Browse files
committed
add: completion of lua symbol references
1 parent 36994ae commit 6d18020

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

script/core/completion/completion.lua

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ local function tryWord(state, position, triggerCharacter, results)
15461546
local env = guide.getENV(state.ast, startPos)
15471547
if env then
15481548
checkGlobal(state, word, startPos, position, env, false, results)
1549-
checkModule(state, word, startPos, results)
1549+
checkModule(state, word, startPos, results)
15501550
end
15511551
end
15521552
end
@@ -2256,16 +2256,43 @@ local function tryluaDocOfFunction(doc, results, pad)
22562256
}
22572257
end
22582258

2259+
---@async
2260+
local function appendSymbolResults(symbol, results)
2261+
for _, match in ipairs(wssymbol(symbol)) do
2262+
results[#results+1] = {
2263+
label = match.name,
2264+
kind = define.CompletionItemKind.Class,
2265+
insertText = match.name
2266+
}
2267+
end
2268+
end
2269+
22592270
---@async
22602271
local function tryLuaDoc(state, position, results)
22612272
local doc = getLuaDoc(state, position)
22622273
if not doc then
22632274
return
22642275
end
2276+
2277+
-- Used for matching referenced symbols e.g. [mySymbol](lua://mySymbol)
2278+
local SYMBOL_REF_PATTERN = "%]%(lua://([^)]*)()"
2279+
-- Every symbol reference starts with the start of a comment `--` and then `](lua://`
2280+
local SYMBOL_REF_COL_OFFSET = #"--](lua://"
2281+
22652282
if doc.type == 'doc.comment' then
2283+
---@type string
22662284
local line = doc.originalComment.text
2267-
-- 尝试 '---$' or '--- $'
2268-
if line == '-' or line == '- ' then
2285+
---@type integer
2286+
local offsetCol = select(2, guide.rowColOf(position)) - SYMBOL_REF_COL_OFFSET
2287+
---@type string, integer
2288+
local symbol, endCol = string.match(line, SYMBOL_REF_PATTERN, offsetCol)
2289+
2290+
if symbol and offsetCol <= endCol then
2291+
-- Contains ](lua://...
2292+
appendSymbolResults(symbol, results)
2293+
return
2294+
elseif line == '-' or line == '- ' then
2295+
-- 尝试 '---$' or '--- $'
22692296
tryluaDocOfFunction(doc, results, line == '- ')
22702297
return
22712298
end

0 commit comments

Comments
 (0)