summaryrefslogtreecommitdiff
path: root/server
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
parentdeaf17c3d358085dcf9b8c4cf014b83daf5bf149 (diff)
downloadlua-language-server-f9d9266198cb54cadb7e75815a39bf2ce29ff045.zip
解决 x or 0 + 1
Diffstat (limited to 'server')
-rw-r--r--server/src/core/diagnostics.lua2
-rw-r--r--server/src/method/initialize.lua1
-rw-r--r--server/src/method/textDocument/codeAction.lua44
-rw-r--r--server/src/method/workspace/executeCommand.lua48
-rw-r--r--server/src/vm/vm.lua5
5 files changed, 98 insertions, 2 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index a43cbf2f..e6ba6f83 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -329,7 +329,7 @@ return function (vm, lines, uri)
-- x or 0 + 1
session:doDiagnostics(session.searchAmbiguity1, 'ambiguity-1', function (op, num)
return {
- level = DiagnosticSeverity.Information,
+ level = DiagnosticSeverity.Warning,
message = lang.script('DIAG_AMBIGUITY_1', op, num),
}
end)
diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua
index ecd354c4..abce7b94 100644
--- a/server/src/method/initialize.lua
+++ b/server/src/method/initialize.lua
@@ -43,6 +43,7 @@ return function (lsp)
commands = {
'config',
'removeSpace',
+ 'solve',
},
},
}
diff --git a/server/src/method/textDocument/codeAction.lua b/server/src/method/textDocument/codeAction.lua
index 845b2591..6dc664dc 100644
--- a/server/src/method/textDocument/codeAction.lua
+++ b/server/src/method/textDocument/codeAction.lua
@@ -60,6 +60,44 @@ local function solveTrailingSpace(lsp, uri, data, callback)
}
end
+local function solveNewlineCall(lsp, uri, data, callback)
+ callback {
+ title = '添加 `;`',
+ kind = 'quickfix',
+ edit = {
+ changes = {
+ [uri] = {
+ {
+ range = {
+ start = data.range.start,
+ ['end'] = data.range.start,
+ },
+ newText = ';',
+ }
+ }
+ }
+ }
+ }
+end
+
+local function solveAmbiguity1(lsp, uri, data, callback)
+ callback {
+ title = '添加括号',
+ kind = 'quickfix',
+ command = {
+ title = '添加括号',
+ command = 'solve',
+ arguments = {
+ {
+ name = 'ambiguity-1',
+ uri = uri,
+ range = data.range,
+ }
+ }
+ },
+ }
+end
+
local function solveDiagnostic(lsp, uri, data, callback)
if data.code then
disableDiagnostic(lsp, uri, data, callback)
@@ -70,6 +108,12 @@ local function solveDiagnostic(lsp, uri, data, callback)
if data.code == 'trailing-space' then
solveTrailingSpace(lsp, uri, data, callback)
end
+ if data.code == 'newline-call' then
+ solveNewlineCall(lsp, uri, data, callback)
+ end
+ if data.code == 'ambiguity-1' then
+ solveAmbiguity1(lsp, uri, data, callback)
+ end
end
return function (lsp, params)
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
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 332f4a69..afe455d5 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -1128,7 +1128,10 @@ function mt:eachSource(callback)
end
local sources = self.sources
for i = 1, #sources do
- callback(sources[i])
+ local res = callback(sources[i])
+ if res ~= nil then
+ return res
+ end
end
end