summaryrefslogtreecommitdiff
path: root/script/core/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r--script/core/diagnostics/count-down-loop.lua25
-rw-r--r--script/core/diagnostics/different-requires.lua2
-rw-r--r--script/core/diagnostics/init.lua2
-rw-r--r--script/core/diagnostics/newfield-call.lua5
-rw-r--r--script/core/diagnostics/newline-call.lua17
-rw-r--r--script/core/diagnostics/redundant-value.lua32
-rw-r--r--script/core/diagnostics/trailing-space.lua35
-rw-r--r--script/core/diagnostics/undefined-global.lua2
8 files changed, 67 insertions, 53 deletions
diff --git a/script/core/diagnostics/count-down-loop.lua b/script/core/diagnostics/count-down-loop.lua
index 1a7dcf7d..49c48880 100644
--- a/script/core/diagnostics/count-down-loop.lua
+++ b/script/core/diagnostics/count-down-loop.lua
@@ -10,30 +10,39 @@ return function (uri, callback)
end
guide.eachSourceType(state.ast, 'loop', function (source)
- if not source.loc or not source.loc.value then
- return
- end
local maxNumer = source.max and tonumber(source.max[1])
if maxNumer ~= 1 then
return
end
- local minNumber = source.loc and source.loc.value and tonumber(source.loc.value[1])
+ local minNumber = source.init and tonumber(source.init[1])
if minNumber and minNumber <= 1 then
return
end
if not source.step then
callback {
- start = source.loc.value.start,
+ start = source.init.start,
finish = source.max.finish,
- message = lang.script('DIAG_COUNT_DOWN_LOOP', ('%s, %s'):format(text:sub(source.loc.value.start, source.max.finish), '-1'))
+ message = lang.script('DIAG_COUNT_DOWN_LOOP'
+ , ('%s, %s'):format(text:sub(
+ guide.positionToOffset(state, source.init.start),
+ guide.positionToOffset(state, source.max.finish)
+ )
+ , '-1')
+ )
}
else
local stepNumber = tonumber(source.step[1])
if stepNumber and stepNumber > 0 then
callback {
- start = source.loc.value.start,
+ start = source.init.start,
finish = source.step.finish,
- message = lang.script('DIAG_COUNT_DOWN_LOOP', ('%s, -%s'):format(text:sub(source.loc.value.start, source.max.finish), source.step[1]))
+ message = lang.script('DIAG_COUNT_DOWN_LOOP'
+ , ('%s, -%s'):format(text:sub(
+ guide.positionToOffset(state, source.init.start),
+ guide.positionToOffset(state, source.max.finish)
+ )
+ , source.step[1])
+ )
}
end
end
diff --git a/script/core/diagnostics/different-requires.lua b/script/core/diagnostics/different-requires.lua
index 909342f4..fd7415b6 100644
--- a/script/core/diagnostics/different-requires.lua
+++ b/script/core/diagnostics/different-requires.lua
@@ -12,7 +12,7 @@ return function (uri, callback)
end
local cache = vm.getCache 'different-requires'
guide.eachSpecialOf(state.ast, 'require', function (source)
- local call = source.next
+ local call = source.parent
if not call or call.type ~= 'call' then
return
end
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index 09688f6e..63a1bcf0 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -44,7 +44,7 @@ local function check(uri, name, results)
if vm.isDiagDisabledAt(uri, result.start, name) then
return
end
- if result.start == 0 then
+ if result.start < 0 then
return
end
if mark[result.start] then
diff --git a/script/core/diagnostics/newfield-call.lua b/script/core/diagnostics/newfield-call.lua
index fe86ad66..669ed2bb 100644
--- a/script/core/diagnostics/newfield-call.lua
+++ b/script/core/diagnostics/newfield-call.lua
@@ -8,7 +8,6 @@ return function (uri, callback)
return
end
- local lines = files.getLines(uri)
local text = files.getText(uri)
guide.eachSourceType(ast.ast, 'table', function (source)
@@ -27,8 +26,8 @@ return function (uri, callback)
local func = call.node
local args = call.args
if args then
- local funcLine = guide.positionOf(lines, func.finish)
- local argsLine = guide.positionOf(lines, args.start)
+ local funcLine = guide.rowColOf(func.finish)
+ local argsLine = guide.rowColOf(args.start)
if argsLine > funcLine then
callback {
start = call.start,
diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua
index 71dc33e2..dbb8c690 100644
--- a/script/core/diagnostics/newline-call.lua
+++ b/script/core/diagnostics/newline-call.lua
@@ -3,14 +3,13 @@ local guide = require 'parser.guide'
local lang = require 'language'
return function (uri, callback)
- local ast = files.getState(uri)
- local lines = files.getLines(uri)
+ local state = files.getState(uri)
local text = files.getText(uri)
- if not ast or not lines 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
@@ -21,13 +20,15 @@ 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
- local nodeRow = guide.positionOf(lines, node.finish)
- local argRow = guide.positionOf(lines, args.start)
+ local nodeRow = guide.rowColOf(node.finish)
+ local argRow = guide.rowColOf(args.start)
if nodeRow == argRow 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/core/diagnostics/trailing-space.lua b/script/core/diagnostics/trailing-space.lua
index 824eb83f..cc51cf77 100644
--- a/script/core/diagnostics/trailing-space.lua
+++ b/script/core/diagnostics/trailing-space.lua
@@ -13,40 +13,43 @@ local function isInString(ast, offset)
end
return function (uri, callback)
- local ast = files.getState(uri)
- if not ast then
+ local state = files.getState(uri)
+ if not state then
return
end
local text = files.getText(uri)
- local lines = files.getLines(uri)
- for i = 1, #lines do
- local start = lines[i].start
- local range = lines[i].range
- local lastChar = text:sub(range, range)
+ local lines = state.lines
+ for i = 0, #lines do
+ local startOffset = lines[i]
+ local finishOffset = text:find('[\r\n]', startOffset) or (#text + 1)
+ local lastOffset = finishOffset - 1
+ local lastChar = text:sub(lastOffset, lastOffset)
if lastChar ~= ' ' and lastChar ~= '\t' then
goto NEXT_LINE
end
- if isInString(ast.ast, range) then
+ local lastPos = guide.offsetToPosition(state, lastOffset)
+ if isInString(state.ast, lastPos) then
goto NEXT_LINE
end
- local first = start
- for n = range - 1, start, -1 do
+ local firstOffset = startOffset
+ for n = lastOffset - 1, startOffset, -1 do
local char = text:sub(n, n)
if char ~= ' ' and char ~= '\t' then
- first = n + 1
+ firstOffset = n + 1
break
end
end
- if first == start then
+ local firstPos = guide.offsetToPosition(state, firstOffset) - 1
+ if firstOffset == startOffset then
callback {
- start = first,
- finish = range,
+ start = firstPos,
+ finish = lastPos,
message = lang.script.DIAG_LINE_ONLY_SPACE,
}
else
callback {
- start = first,
- finish = range,
+ start = firstPos,
+ finish = lastPos,
message = lang.script.DIAG_LINE_POST_SPACE,
}
end
diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua
index c7ddeac2..14754c16 100644
--- a/script/core/diagnostics/undefined-global.lua
+++ b/script/core/diagnostics/undefined-global.lua
@@ -5,6 +5,7 @@ local config = require 'config'
local guide = require 'parser.guide'
local noder = require 'core.noder'
local collector = require 'core.collector'
+local await = require 'await'
local requireLike = {
['include'] = true,
@@ -35,6 +36,7 @@ return function (uri, callback)
if node.tag ~= '_ENV' then
return
end
+ await.delay()
local id = 'def:' .. noder.getID(src)
if not collector.has(id) then
local message = lang.script('DIAG_UNDEF_GLOBAL', key)