summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/completion/postfix.lua15
-rw-r--r--test/completion/common.lua24
3 files changed, 33 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md
index 2e9c3d12..5ca3b842 100644
--- a/changelog.md
+++ b/changelog.md
@@ -8,6 +8,7 @@
* `FIX` [#831](https://github.com/sumneko/lua-language-server/issues/831)
* `FIX` [#837](https://github.com/sumneko/lua-language-server/issues/837)
* `FIX` [#838](https://github.com/sumneko/lua-language-server/issues/838)
+* `FIX` postfix
* `FIX` runtime errors
## 2.5.1
diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua
index 9ad20965..0395e2a5 100644
--- a/script/core/completion/postfix.lua
+++ b/script/core/completion/postfix.lua
@@ -230,9 +230,10 @@ local accepts = {
['table'] = true,
}
-local function checkPostFix(state, word, wordPosition, position, results)
+local function checkPostFix(state, word, wordPosition, position, symbol, results)
local source = guide.eachSourceContain(state.ast, wordPosition, function (source)
- if accepts[source.type] then
+ if accepts[source.type]
+ and source.finish == wordPosition then
return source
end
end)
@@ -249,14 +250,14 @@ local function checkPostFix(state, word, wordPosition, position, results)
: add('lua', newText)
: string(),
textEdit = {
- start = wordPosition + 1,
+ start = wordPosition + #symbol,
finish = position,
newText = newText,
},
additionalTextEdits = {
{
start = source.start,
- finish = wordPosition + 1,
+ finish = wordPosition + #symbol,
newText = '',
},
},
@@ -279,7 +280,7 @@ return function (state, position, results)
local symbol = text:sub(offset, offset)
if symbol == config.get 'Lua.completion.postfix' then
local wordPosition = guide.offsetToPosition(state, offset - 1)
- checkPostFix(state, word or '', wordPosition, position, results)
+ checkPostFix(state, word or '', wordPosition, position, symbol, results)
return symbol ~= '.' and symbol ~= ':'
end
if not word then
@@ -292,8 +293,8 @@ return function (state, position, results)
offset = offset - 3
end
if word then
- local wordPosition = guide.offsetToPosition(state, offset - 1)
- checkPostFix(state, word or '', wordPosition, position, results)
+ local wordPosition = guide.offsetToPosition(state, offset)
+ checkPostFix(state, word or '', wordPosition, position, '', results)
return true
end
end
diff --git a/test/completion/common.lua b/test/completion/common.lua
index 60a5f2ac..3a3d1d46 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -3013,3 +3013,27 @@ xx++<??>
}
},
}
+
+TEST [[
+fff(function ()
+ xx@xpcall<??>
+end)
+]]
+{
+ [1] = {
+ label = 'xpcall',
+ kind = define.CompletionItemKind.Event,
+ textEdit = {
+ start = 10007,
+ finish = 10013,
+ newText = 'xpcall(xx, ${1:debug.traceback}$2)$0',
+ },
+ additionalTextEdits = {
+ {
+ start = 10004,
+ finish = 10007,
+ newText = '',
+ }
+ }
+ },
+}