summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/postfix.lua32
-rw-r--r--script/core/substring.lua10
2 files changed, 26 insertions, 16 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