diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 17:41:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 17:41:25 +0800 |
commit | c951f3472628bdccdbf13a6bd95bc36cc93523fd (patch) | |
tree | 1b54015d40483b573e981678f06859e3e709c929 /script | |
parent | 32aa2dac835a0c74b82b19d83d9fd06be7a947ce (diff) | |
download | lua-language-server-c951f3472628bdccdbf13a6bd95bc36cc93523fd.zip |
update
Diffstat (limited to 'script')
-rw-r--r-- | script/core/diagnostics/newline-call.lua | 12 | ||||
-rw-r--r-- | script/core/diagnostics/redundant-value.lua | 32 | ||||
-rw-r--r-- | script/files.lua | 6 | ||||
-rw-r--r-- | script/parser/newparser.lua | 16 |
4 files changed, 35 insertions, 31 deletions
diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua index b28310e3..dbb8c690 100644 --- a/script/core/diagnostics/newline-call.lua +++ b/script/core/diagnostics/newline-call.lua @@ -3,13 +3,13 @@ local guide = require 'parser.guide' local lang = require 'language' return function (uri, callback) - local ast = files.getState(uri) + local state = files.getState(uri) local text = files.getText(uri) - if not ast then + if not state then return end - guide.eachSourceType(ast.ast, 'call', function (source) + guide.eachSourceType(state.ast, 'call', function (source) local node = source.node local args = source.args if not args then @@ -20,8 +20,10 @@ return function (uri, callback) if not source.next then return end - if text:sub(args.start, args.start) ~= '(' - or text:sub(args.finish, args.finish) ~= ')' then + local startOffset = guide.positionToOffset(state, args.start) + 1 + local finishOffset = guide.positionToOffset(state, args.finish) + if text:sub(startOffset, startOffset) ~= '(' + or text:sub(finishOffset, finishOffset) ~= ')' then return end diff --git a/script/core/diagnostics/redundant-value.lua b/script/core/diagnostics/redundant-value.lua index d6cd97a7..4c913330 100644 --- a/script/core/diagnostics/redundant-value.lua +++ b/script/core/diagnostics/redundant-value.lua @@ -1,24 +1,24 @@ local files = require 'files' local define = require 'proto.define' local lang = require 'language' +local guide = require 'parser.guide' +local await = require 'await' -return function (uri, callback, code) - local ast = files.getState(uri) - if not ast then +return function (uri, callback) + local state = files.getState(uri) + if not state then return end - local diags = ast.diags[code] - if not diags then - return - end - - for _, info in ipairs(diags) do - callback { - start = info.start, - finish = info.finish, - tags = { define.DiagnosticTag.Unnecessary }, - message = lang.script('DIAG_OVER_MAX_VALUES', info.max, info.passed) - } - end + guide.eachSource(state.ast, function (src) + await.delay() + if src.redundant then + callback { + start = src.start, + finish = src.finish, + tags = { define.DiagnosticTag.Unnecessary }, + message = lang.script('DIAG_OVER_MAX_VALUES', src.redundant.max, src.redundant.passed) + } + end + end) end diff --git a/script/files.lua b/script/files.lua index a3595a4f..25f07ca2 100644 --- a/script/files.lua +++ b/script/files.lua @@ -35,8 +35,6 @@ m.assocMatcher = nil m.globalVersion = 0 m.fileCount = 0 m.astCount = 0 -m.linesMap = setmetatable({}, { __mode = 'v' }) -m.originLinesMap = setmetatable({}, { __mode = 'v' }) m.astMap = {} -- setmetatable({}, { __mode = 'v' }) --- 打开文件 @@ -160,8 +158,6 @@ function m.setText(uri, text, isTrust, instance) file.trusted = isTrust file.originText = text file.words = nil - m.linesMap[uri] = nil - m.originLinesMap[uri] = nil m.astMap[uri] = nil file.cache = {} file.cacheActiveTime = math.huge @@ -346,7 +342,6 @@ function m.removeAll() m.fileCount = m.fileCount - 1 m.fileMap[uri] = nil m.astMap[uri] = nil - m.linesMap[uri] = nil m.onWatch('remove', uri) end end @@ -366,7 +361,6 @@ function m.removeAllClosed() m.fileCount = m.fileCount - 1 m.fileMap[uri] = nil m.astMap[uri] = nil - m.linesMap[uri] = nil m.onWatch('remove', uri) end end diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index 9547a830..ba91cd10 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -2573,6 +2573,7 @@ local function parseMultiVars(n1, parser, isLocal) skipSpace() local v1, v2, vrest local isSet + local max = 1 if expectAssign() then v1, v2, vrest = parseSetValues() isSet = true @@ -2583,6 +2584,7 @@ local function parseMultiVars(n1, parser, isLocal) bindValue(n1, v1, 1, nil, isLocal, isSet) local lastValue = v1 if n2 then + max = 2 bindValue(n2, v2, 2, lastValue, isLocal, isSet) lastValue = v2 or lastValue pushActionIntoCurrentChunk(n2) @@ -2591,21 +2593,28 @@ local function parseMultiVars(n1, parser, isLocal) for i = 1, #nrest do local n = nrest[i] local v = vrest and vrest[i] - bindValue(n, v, i + 2, lastValue, isLocal, isSet) + max = i + 2 + bindValue(n, v, max, lastValue, isLocal, isSet) lastValue = v or lastValue pushActionIntoCurrentChunk(n) end end if v2 and not n2 then - v2.redundant = true + v2.redundant = { + max = max, + passed = 2, + } pushActionIntoCurrentChunk(v2) end if vrest then for i = 1, #vrest do local v = vrest[i] if not nrest or not nrest[i] then - v.redundant = true + v.redundant = { + max = max, + passed = v + 2, + } pushActionIntoCurrentChunk(v) end end @@ -3530,7 +3539,6 @@ local function initState(lua, version, options) lua = lua, ast = {}, errs = {}, - diags = {}, comms = {}, lines = { [0] = 1, |