summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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,
+ }
+}