summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/completion.lua17
-rw-r--r--script/provider/provider.lua11
-rw-r--r--test/completion/init.lua3
-rw-r--r--test/crossfile/completion.lua2
5 files changed, 21 insertions, 13 deletions
diff --git a/changelog.md b/changelog.md
index f51596e3..a95923e8 100644
--- a/changelog.md
+++ b/changelog.md
@@ -4,6 +4,7 @@
* `FIX` loaded new file with ignored filename
* `FIX` [#536](https://github.com/sumneko/lua-language-server/issues/536)
* `FIX` [#537](https://github.com/sumneko/lua-language-server/issues/537)
+* `FIX` [#539](https://github.com/sumneko/lua-language-server/issues/539)
## 1.21.1
`2021-5-8`
diff --git a/script/core/completion.lua b/script/core/completion.lua
index ee61029d..e3980eca 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1163,13 +1163,18 @@ local function tryIndex(ast, text, offset, results)
checkField(ast, word, offset, offset, parent, oop, results)
end
-local function tryWord(ast, text, offset, results)
+local function tryWord(ast, text, offset, triggerCharacter, results)
local finish = lookBackward.skipSpace(text, offset)
- local word, start = lookBackward.findWord(text, finish)
+ local word, start = lookBackward.findWord(text, offset)
if not word then
- return nil
+ if triggerCharacter == nil then
+ word = ''
+ start = offset
+ else
+ return nil
+ end
end
- local hasSpace = finish ~= offset
+ local hasSpace = triggerCharacter ~= nil and finish ~= offset
if isInString(ast, offset) then
if not hasSpace then
if #results == 0 then
@@ -1918,7 +1923,7 @@ local function clearCache()
cache.results = nil
end
-local function completion(uri, offset)
+local function completion(uri, offset, triggerCharacter)
tracy.ZoneBeginN 'completion cache'
local results = getCache(uri, offset)
tracy.ZoneEnd()
@@ -1940,7 +1945,7 @@ local function completion(uri, offset)
trySpecial(ast, text, offset, results)
tryCallArg(ast, text, offset, results)
tryTable(ast, text, offset, results)
- tryWord(ast, text, offset, results)
+ tryWord(ast, text, offset, triggerCharacter, results)
tryIndex(ast, text, offset, results)
trySymbol(ast, text, offset, results)
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index a6f4d9cc..3ac71d8b 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -458,17 +458,18 @@ proto.on('textDocument/completion', function (params)
if not files.exists(uri) then
return nil
end
- if params.context and config.other.acceptSuggestionOnEnter ~= 'off' then
- if params.context.triggerCharacter == '\n'
- or params.context.triggerCharacter == '{'
- or params.context.triggerCharacter == ',' then
+ local triggerCharacter = params.context and params.context.triggerCharacter
+ if config.other.acceptSuggestionOnEnter ~= 'off' then
+ if triggerCharacter == '\n'
+ or triggerCharacter == '{'
+ or triggerCharacter == ',' then
return
end
end
await.setPriority(1000)
local clock = os.clock()
local offset = files.offset(uri, params.position)
- local result = core.completion(uri, offset - 1)
+ local result = core.completion(uri, offset - 1, triggerCharacter)
local passed = os.clock() - clock
if passed > 0.1 then
log.warn(('Completion takes %.3f sec.'):format(passed))
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 89772853..dde4b559 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -70,7 +70,8 @@ function TEST(script)
files.setText('', new_script)
core.clearCache()
- local result = core.completion('', pos)
+ local triggerCharacter = script:sub(pos - 1, pos - 1)
+ local result = core.completion('', pos, triggerCharacter)
if not expect then
assert(result == nil)
return
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index d07a2eac..15ce3440 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -97,7 +97,7 @@ function TEST(data)
local expect = data.completion
core.clearCache()
- local result = core.completion(mainUri, pos)
+ local result = core.completion(mainUri, pos, '')
if not expect then
assert(result == nil)
return