summaryrefslogtreecommitdiff
path: root/server/src/method/workspace/executeCommand.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-28 15:31:04 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-28 15:31:04 +0800
commitf9d9266198cb54cadb7e75815a39bf2ce29ff045 (patch)
tree4214e85a2cc3e216585ca2bd86ace82a4a5beafb /server/src/method/workspace/executeCommand.lua
parentdeaf17c3d358085dcf9b8c4cf014b83daf5bf149 (diff)
downloadlua-language-server-f9d9266198cb54cadb7e75815a39bf2ce29ff045.zip
解决 x or 0 + 1
Diffstat (limited to 'server/src/method/workspace/executeCommand.lua')
-rw-r--r--server/src/method/workspace/executeCommand.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/server/src/method/workspace/executeCommand.lua b/server/src/method/workspace/executeCommand.lua
index 9643128e..173eaa22 100644
--- a/server/src/method/workspace/executeCommand.lua
+++ b/server/src/method/workspace/executeCommand.lua
@@ -118,6 +118,54 @@ function command.removeSpace(lsp, data)
})
end
+function command.solve(lsp, data)
+ local uri = data.uri
+ local vm, lines = lsp:getVM(uri)
+ if not vm then
+ return
+ end
+
+ local start = lines:position(data.range.start.line + 1, data.range.start.character + 1)
+ local finish = lines:position(data.range['end'].line + 1, data.range['end'].character)
+
+ local source = vm:eachSource(function (source)
+ if source.op ~= 'or' then
+ return
+ end
+ local exp = source[2]
+ if exp.op ~= '+' and exp.op ~= '-' then
+ return
+ end
+ if exp[1][1] == 0 and exp[2].type == 'number' then
+ if source.start == start and source.finish == finish then
+ return source
+ end
+ end
+ end)
+
+ if not source then
+ return
+ end
+
+ rpc:request('workspace/applyEdit', {
+ label = '添加括号',
+ edit = {
+ changes = {
+ [uri] = {
+ {
+ range = posToRange(lines, source.start, source.start - 1),
+ newText = '(',
+ },
+ {
+ range = posToRange(lines, source[2][1].finish + 1, source[2][1].finish),
+ newText = ')',
+ },
+ }
+ }
+ },
+ })
+end
+
return function (lsp, params)
local name = params.command
if not command[name] then