diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-24 22:16:17 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-24 22:16:17 +0800 |
commit | b6a58d0912d6cb015c621d2ce32d701ef6e7500e (patch) | |
tree | 6492047bb9cf877987b10c629aa062fa92365b8f | |
parent | 95688433e4b7aa46257b4db557db38d81f0d6b04 (diff) | |
download | lua-language-server-b6a58d0912d6cb015c621d2ce32d701ef6e7500e.zip |
stash
-rw-r--r-- | script/core/completion.lua | 16 | ||||
-rw-r--r-- | script/core/look-backward.lua | 1 | ||||
-rw-r--r-- | test/completion/init.lua | 20 |
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) |