summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-11-23 22:10:40 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-11-23 22:10:40 +0800
commit14c0ba0ebbf69426cab28c98409fb04aff89a34d (patch)
treed79bcd1f72e002744b5b6f855dcb7e8b74aa5dfb
parent7c176eb6882abbe00b0a1285bbbb4ff2af897b13 (diff)
downloadlua-language-server-14c0ba0ebbf69426cab28c98409fb04aff89a34d.zip
make VSCode happy
-rw-r--r--script/core/completion/postfix.lua32
-rw-r--r--script/core/substring.lua10
-rw-r--r--test/completion/common.lua13
3 files changed, 30 insertions, 25 deletions
diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua
index 8e21a86d..07c6be8c 100644
--- a/script/core/completion/postfix.lua
+++ b/script/core/completion/postfix.lua
@@ -1,6 +1,7 @@
local guide = require 'parser.guide'
local lookback = require 'core.look-backward'
local matchKey = require 'core.matchkey'
+local subString = require 'core.substring'
local define = require 'proto.define'
local actions = {}
@@ -15,16 +16,9 @@ local function register(key)
end
register 'pcall' {
- function (source, callback)
- callback({
- start = source.start,
- finish = source.start,
- newText = 'pcall(',
- }, {
- start = source.finish,
- finish = source.finish,
- newText = ')',
- })
+ function (state, source, callback)
+ local subber = subString(state)
+ callback(('pcall(%s)'):format(subber(source.start + 1, source.finish)))
end
}
@@ -44,16 +38,22 @@ local function checkPostFix(state, word, wordPosition, position, results)
end)
for _, action in ipairs(actions) do
if matchKey(word, action.key) then
- action.data[1](source, function (...)
+ action.data[1](state, source, function (newText)
results[#results+1] = {
- label = action.key,
- kind = define.CompletionItemKind.Event,
- textEdit = {
- start = wordPosition,
+ label = action.key,
+ kind = define.CompletionItemKind.Event,
+ textEdit = {
+ start = wordPosition + 1,
finish = position,
newText = '',
},
- additionalTextEdits = { ... }
+ additionalTextEdits = {
+ {
+ start = source.start,
+ finish = wordPosition + 1,
+ newText = newText,
+ },
+ },
}
end)
end
diff --git a/script/core/substring.lua b/script/core/substring.lua
new file mode 100644
index 00000000..0e4520c4
--- /dev/null
+++ b/script/core/substring.lua
@@ -0,0 +1,10 @@
+local guide = require 'parser.guide'
+
+return function (state)
+ return function (pos1, pos2)
+ return state.lua:sub(
+ guide.positionToOffset(state, pos1),
+ guide.positionToOffset(state, pos2)
+ )
+ end
+end
diff --git a/test/completion/common.lua b/test/completion/common.lua
index 918b6458..2080e12e 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -2764,21 +2764,16 @@ xx@pcall<??>
label = 'pcall',
kind = define.CompletionItemKind.Event,
textEdit = {
- start = 2,
+ start = 3,
finish = 8,
newText = '',
},
additionalTextEdits = {
{
start = 0,
- finish = 0,
- newText = 'pcall(',
- },
- {
- start = 2,
- finish = 2,
- newText = ')',
- },
+ finish = 3,
+ newText = 'pcall(xx)'
+ }
}
}
}