summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-07-08 20:31:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-07-08 20:31:53 +0800
commitdc67d2357ef43e9f3c1f4d78ef5e141c475b9dcb (patch)
tree76d0d5e06bb44c0401522a206adefad167ee049e /server/src
parentdd792e6924572117905f7f58574ac38bb361c236 (diff)
downloadlua-language-server-dc67d2357ef43e9f3c1f4d78ef5e141c475b9dcb.zip
修正优先级识别的bug
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/diagnostics.lua31
-rw-r--r--server/src/method/workspace/executeCommand.lua49
2 files changed, 55 insertions, 25 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 77898b17..1a72d504 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -271,19 +271,36 @@ local opMap = {
['..'] = true,
}
+local literalMap = {
+ ['number'] = true,
+ ['boolean'] = true,
+ ['string'] = true,
+ ['table'] = true,
+}
+
function mt:searchAmbiguity1(callback)
self.vm:eachSource(function (source)
if source.op ~= 'or' then
return
end
- -- (a or 0) + c --> a or (0 + c)
+ local first = source[1]
+ local second = source[2]
-- a + (b or 0) --> (a + b) or 0
- for x = 1, 2 do
- local y = x % 2 + 1
- local exp = source[x]
- local other = source[y]
- if opMap[exp.op] and not opMap[other.op] then
- callback(source.start, source.finish, exp.start, exp.finish)
+ do
+ if opMap[first.op]
+ and not second.op
+ and literalMap[second.type]
+ then
+ callback(source.start, source.finish, first.start, first.finish)
+ end
+ end
+ -- (a or 0) + c --> a or (0 + c)
+ do
+ if opMap[second.op]
+ and not first.op
+ and literalMap[second[1].type]
+ then
+ callback(source.start, source.finish, second.start, second.finish)
end
end
end)
diff --git a/server/src/method/workspace/executeCommand.lua b/server/src/method/workspace/executeCommand.lua
index bec55e03..95d90fec 100644
--- a/server/src/method/workspace/executeCommand.lua
+++ b/server/src/method/workspace/executeCommand.lua
@@ -138,6 +138,13 @@ local opMap = {
['..'] = true,
}
+local literalMap = {
+ ['number'] = true,
+ ['boolean'] = true,
+ ['string'] = true,
+ ['table'] = true,
+}
+
function command.solve(lsp, data)
local uri = data.uri
local vm, lines = lsp:getVM(uri)
@@ -155,24 +162,30 @@ function command.solve(lsp, data)
if source.op ~= 'or' then
return
end
- for x = 1, 2 do
- local y = x % 2 + 1
- local exp = source[x]
- local other = source[y]
- if opMap[exp.op] and not opMap[other.op] then
- if x == 1 then
- -- (a + b) or c --> a + (b or c)
- return {
- start = source[1][2].start,
- finish = source[2].finish,
- }
- else
- -- a or (b + c) --> (a or b) + c
- return {
- start = source[1].start,
- finish = source[2][1].finish,
- }
- end
+ local first = source[1]
+ local second = source[2]
+ -- (a + b) or 0 --> a + (b or 0)
+ do
+ if opMap[first.op]
+ and not second.op
+ and literalMap[second.type]
+ then
+ return {
+ start = source[1][2].start,
+ finish = source[2].finish,
+ }
+ end
+ end
+ -- a or (b + c) --> (a or b) + c
+ do
+ if opMap[second.op]
+ and not first.op
+ and literalMap[second[1].type]
+ then
+ return {
+ start = source[1].start,
+ finish = source[2][1].finish,
+ }
end
end
end)