diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-07-05 15:04:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-07-05 15:04:41 +0800 |
commit | d91adfe4ebd18099fde3e4389655d4532fc9b00c (patch) | |
tree | d15de422cd614f13c72a43a8f9ad375c43eba2da /server/src/method | |
parent | b1afe6e48fc454fcc767c6a009fa2f59697b38c1 (diff) | |
download | lua-language-server-d91adfe4ebd18099fde3e4389655d4532fc9b00c.zip |
扩展优先级
Diffstat (limited to 'server/src/method')
-rw-r--r-- | server/src/method/workspace/executeCommand.lua | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/server/src/method/workspace/executeCommand.lua b/server/src/method/workspace/executeCommand.lua index f22590d5..9b234fc1 100644 --- a/server/src/method/workspace/executeCommand.lua +++ b/server/src/method/workspace/executeCommand.lua @@ -133,22 +133,38 @@ function command.solve(lsp, data) 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 + local result = vm:eachSource(function (source) + if not isContainPos(source, start, finish) then return end - local exp = source[2] - if exp.op ~= '+' and exp.op ~= '-' then + if source.op ~= 'or' 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 + for x = 1, 2 do + local y = x % 2 + 1 + local exp = source[x] + local other = source[y] + if exp.op and not 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 end end end) - if not source then + log.debug(table.dump(result)) + + if not result then return end @@ -158,11 +174,11 @@ function command.solve(lsp, data) changes = { [uri] = { { - range = posToRange(lines, source.start, source.start - 1), + range = posToRange(lines, result.start, result.start - 1), newText = '(', }, { - range = posToRange(lines, source[2][1].finish + 1, source[2][1].finish), + range = posToRange(lines, result.finish + 1, result.finish), newText = ')', }, } |