summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/completion.lua16
-rw-r--r--script/core/look-backward.lua1
-rw-r--r--test/completion/init.lua20
3 files changed, 36 insertions, 1 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 97984299..c5198e50 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1217,6 +1217,21 @@ local function tryWord(ast, text, offset, triggerCharacter, results)
end
end
+local function tryAfterIndex(ast, text, offset, triggerCharacter, results)
+ if isInString(ast, offset) then
+ return
+ end
+ local finish = lookBackward.skipSpace(text, offset)
+ do return end
+ local hasSpace = triggerCharacter ~= nil and finish ~= offset
+ local parent, oop = findParent(ast, text, start - 1)
+ if parent then
+ if not hasSpace then
+ checkField(ast, word, start, offset, parent, oop, results)
+ end
+ end
+end
+
local function trySymbol(ast, text, offset, results)
local symbol, start = lookBackward.findSymbol(text, offset)
if not symbol then
@@ -1943,6 +1958,7 @@ local function completion(uri, offset, triggerCharacter)
tryCallArg(ast, text, offset, results)
tryTable(ast, text, offset, results)
tryWord(ast, text, offset, triggerCharacter, results)
+ tryAfterIndex(ast, text, offset, triggerCharacter, results)
tryIndex(ast, text, offset, results)
trySymbol(ast, text, offset, results)
end
diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua
index 7119bdfa..ee89078f 100644
--- a/script/core/look-backward.lua
+++ b/script/core/look-backward.lua
@@ -73,7 +73,6 @@ function m.findTargetSymbol(text, offset, symbol)
else
return nil
end
- ::CONTINUE::
end
return nil
end
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 80a4aae5..4a04ecc5 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -2519,3 +2519,23 @@ zzzz$
insertText = 'zzzz(${1:a: any}, ${2:b: any})',
},
}
+Cared['insertText'] = false
+
+TEST [[
+--- @diagnostic disable: unused-local
+--- @class Test2
+--- @field world integer
+local Test2 = {}
+
+--- @type Test2
+local tdirect
+--- @type Test2[]
+local tarray
+
+-- Direct inference
+local b = tdirect -- type . here, shows "world"
+
+-- Inferred by index
+local c = tarray[1].$ -- type . here, no auto completion
+]]
+(EXISTS)