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 | |
parent | b1afe6e48fc454fcc767c6a009fa2f59697b38c1 (diff) | |
download | lua-language-server-d91adfe4ebd18099fde3e4389655d4532fc9b00c.zip |
扩展优先级
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/diagnostics.lua | 19 | ||||
-rw-r--r-- | server/src/method/workspace/executeCommand.lua | 36 |
2 files changed, 37 insertions, 18 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 458a4686..239c8121 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -261,12 +261,15 @@ function mt:searchAmbiguity1(callback) 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 - callback(source.start, source.finish, exp.op, exp[2][1]) + -- (a or 0) + c --> a or (0 + c) + -- 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 exp.op and not other.op then + callback(source.start, source.finish, exp.start, exp.finish) + end end end) end @@ -755,9 +758,9 @@ return function (vm, lines, uri) } end) -- x or 0 + 1 - session:doDiagnostics(session.searchAmbiguity1, 'ambiguity-1', function (op, num) + session:doDiagnostics(session.searchAmbiguity1, 'ambiguity-1', function (start, finish) return { - message = lang.script('DIAG_AMBIGUITY_1', op, num), + message = lang.script('DIAG_AMBIGUITY_1', lines.buf:sub(start, finish)), } end) -- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删) 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 = ')', }, } |