summaryrefslogtreecommitdiff
path: root/server/src/method
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/method
parentdd792e6924572117905f7f58574ac38bb361c236 (diff)
downloadlua-language-server-dc67d2357ef43e9f3c1f4d78ef5e141c475b9dcb.zip
修正优先级识别的bug
Diffstat (limited to 'server/src/method')
-rw-r--r--server/src/method/workspace/executeCommand.lua49
1 files changed, 31 insertions, 18 deletions
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)