summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-16 17:13:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-16 17:13:05 +0800
commit792afd666c6c43bdbd7e82ec8596755f579dc9ba (patch)
tree207b03ee49dc58344c8f79653947a6b3ade20eca
parent025c4c5fb2ced70e448716391be70fc47e82b1fb (diff)
downloadlua-language-server-792afd666c6c43bdbd7e82ec8596755f579dc9ba.zip
completion: supports `t:$` as `doc.function`
-rw-r--r--script/core/completion.lua2
-rw-r--r--script/core/infer.lua8
-rw-r--r--test/completion/init.lua14
3 files changed, 23 insertions, 1 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 7e95d663..dc34419c 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -477,7 +477,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul
})
return
end
- if oop then
+ if oop and not infer.hasType(src, 'function') then
return
end
local literal = guide.getLiteral(value)
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 84a2b2e5..9264ba06 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -635,6 +635,14 @@ function m.hasType(source, tp, mark)
if mark.hasType[source] == nil then
local infers = m.searchInfers(source, nil, mark)
mark.hasType[source] = infers[tp] or false
+ if tp == 'function' and not infers[tp] then
+ for infer in pairs(infers) do
+ if infer:sub(1, 4) == 'fun(' then
+ mark.hasType[source] = true
+ break
+ end
+ end
+ end
end
return mark.hasType[source]
end
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 1ed82b2a..3dd9b639 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -2723,3 +2723,17 @@ f('$')
},
},
}
+
+TEST [[
+---@class Class
+---@field on fun()
+local c
+
+c:$
+]]
+{
+ {
+ label = 'on',
+ kind = define.CompletionItemKind.Field,
+ }
+}