summaryrefslogtreecommitdiff
path: root/script/provider/diagnostic.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-10-17 16:38:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-10-17 16:38:44 +0800
commitbfb576d3eba9f12bb582a9f7e942c5eac387fe2b (patch)
treed5e3790aeca21994d4b9558453f40657383fcf63 /script/provider/diagnostic.lua
parent3bdd74aa30a6175f1bbf973559241f99eb563dfe (diff)
downloadlua-language-server-bfb576d3eba9f12bb582a9f7e942c5eac387fe2b.zip
use `state` instead of `uri` for converter
The state may have changed when responding, so we need to use the state when requesting. Try not to get the state on the spot.
Diffstat (limited to 'script/provider/diagnostic.lua')
-rw-r--r--script/provider/diagnostic.lua29
1 files changed, 19 insertions, 10 deletions
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 58179514..149e409f 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -32,8 +32,9 @@ local function concat(t, sep)
end
local function buildSyntaxError(uri, err)
- local text = files.getText(uri)
- if not text then
+ local state = files.getState(uri)
+ local text = files.getText(uri)
+ if not text or not state then
return
end
local message = lang.script('PARSER_' .. err.type, err.info)
@@ -58,16 +59,19 @@ local function buildSyntaxError(uri, err)
rmessage = text:sub(rel.start, rel.finish)
end
local relUri = rel.uri or uri
- relatedInformation[#relatedInformation+1] = {
- message = rmessage,
- location = converter.location(relUri, converter.packRange(relUri, rel.start, rel.finish)),
- }
+ local relState = files.getState(relUri)
+ if relState then
+ relatedInformation[#relatedInformation+1] = {
+ message = rmessage,
+ location = converter.location(relUri, converter.packRange(relState, rel.start, rel.finish)),
+ }
+ end
end
end
return {
code = err.type:lower():gsub('_', '-'),
- range = converter.packRange(uri, err.start, err.finish),
+ range = converter.packRange(state, err.start, err.finish),
severity = define.DiagnosticSeverity[err.level],
source = lang.script.DIAG_SYNTAX_CHECK,
message = message,
@@ -78,7 +82,8 @@ local function buildSyntaxError(uri, err)
end
local function buildDiagnostic(uri, diag)
- if not files.exists(uri) then
+ local state = files.getState(uri)
+ if not state then
return
end
@@ -90,16 +95,20 @@ local function buildDiagnostic(uri, diag)
if not rtext then
goto CONTINUE
end
+ local relState = files.getState(rel.uri)
+ if not relState then
+ goto CONTINUE
+ end
relatedInformation[#relatedInformation+1] = {
message = rel.message or rtext:sub(rel.start, rel.finish),
- location = converter.location(rel.uri, converter.packRange(rel.uri, rel.start, rel.finish))
+ location = converter.location(rel.uri, converter.packRange(relState, rel.start, rel.finish))
}
::CONTINUE::
end
end
return {
- range = converter.packRange(uri, diag.start, diag.finish),
+ range = converter.packRange(state, diag.start, diag.finish),
source = lang.script.DIAG_DIAGNOSTICS,
severity = diag.level,
message = diag.message,