summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorcarsakiller <carsakiller@gmail.com>2024-05-23 05:49:56 +0000
committercarsakiller <carsakiller@gmail.com>2024-05-23 05:49:56 +0000
commit1f3a500b81ad1d55cf8564de9eca590e9f29e80b (patch)
tree84b8e4b0aef77246613835ccefc9f11377341741 /script
parent36994ae9a8943755fe7b37b0d8377182a7c381e4 (diff)
downloadlua-language-server-1f3a500b81ad1d55cf8564de9eca590e9f29e80b.zip
add: completion of lua symbol references
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/completion.lua38
1 files changed, 37 insertions, 1 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index d047dd56..cf2ec745 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -2256,6 +2256,37 @@ local function tryluaDocOfFunction(doc, results, pad)
}
end
+---Checks for a lua symbol reference in comment and returns an async callback if found
+local function trySymbolReference(state, position, results)
+ local doc = getLuaDoc(state, position)
+ if not doc then
+ return
+ end
+
+ local line = doc.originalComment.text ---@type string
+ local col = select(2, guide.rowColOf(position)) - 2 ---@type integer
+
+ -- User will ask for completion at end of symbol name so we need to perform a reverse match to see if they are in a symbol reference
+ -- Matching in reverse allows the symbol to be of any length and we can still match all the way back to `](lua://` from right to left
+ local symbol = string.match(string.reverse(line), "%)?(.*)//:aul%(%]", #line - col)
+
+ if symbol then
+ -- flip it back the right way around
+ symbol = string.reverse(symbol)
+
+ ---@async
+ return function ()
+ for _, match in ipairs(wssymbol(symbol)) do
+ results[#results+1] = {
+ label = match.name,
+ kind = define.CompletionItemKind.Class,
+ insertText = match.name
+ }
+ end
+ end
+ end
+end
+
---@async
local function tryLuaDoc(state, position, results)
local doc = getLuaDoc(state, position)
@@ -2327,8 +2358,13 @@ end
---@async
local function tryCompletions(state, position, triggerCharacter, results)
if getComment(state, position) then
+ local callback = trySymbolReference(state, position, results)
+ if callback then
+ callback()
+ else
+ tryComment(state, position, results)
+ end
tryLuaDoc(state, position, results)
- tryComment(state, position, results)
return
end
if postfix(state, position, results) then