diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-10-17 16:38:44 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-10-17 16:38:44 +0800 |
commit | bfb576d3eba9f12bb582a9f7e942c5eac387fe2b (patch) | |
tree | d5e3790aeca21994d4b9558453f40657383fcf63 /script/core/code-action.lua | |
parent | 3bdd74aa30a6175f1bbf973559241f99eb563dfe (diff) | |
download | lua-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/core/code-action.lua')
-rw-r--r-- | script/core/code-action.lua | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua index 1e19d466..4f15b335 100644 --- a/script/core/code-action.lua +++ b/script/core/code-action.lua @@ -135,7 +135,7 @@ local function solveUndefinedGlobal(uri, diag, results) if not state then return end - local start = converter.unpackRange(uri, diag.range) + local start = converter.unpackRange(state, diag.range) guide.eachSourceContain(state.ast, start, function (source) if source.type ~= 'getglobal' then return @@ -157,7 +157,7 @@ local function solveLowercaseGlobal(uri, diag, results) if not state then return end - local start = converter.unpackRange(uri, diag.range) + local start = converter.unpackRange(state, diag.range) guide.eachSourceContain(state.ast, start, function (source) if source.type ~= 'setglobal' then return @@ -175,7 +175,7 @@ local function findSyntax(uri, diag) end for _, err in ipairs(state.errs) do if err.type:lower():gsub('_', '-') == diag.code then - local range = converter.packRange(uri, err.start, err.finish) + local range = converter.packRange(state, err.start, err.finish) if util.equal(range, diag.range) then return err end @@ -276,7 +276,11 @@ local function solveSyntax(uri, diag, results) end local function solveNewlineCall(uri, diag, results) - local start = converter.unpackRange(uri, diag.range) + local state = files.getState(uri) + if not state then + return + end + local start = converter.unpackRange(state, diag.range) results[#results+1] = { title = lang.script.ACTION_ADD_SEMICOLON, kind = 'quickfix', @@ -333,7 +337,7 @@ local function solveAwaitInSync(uri, diag, results) if not state then return end - local start, finish = converter.unpackRange(uri, diag.range) + local start, finish = converter.unpackRange(state, diag.range) local parentFunction guide.eachSourceType(state.ast, 'function', function (source) if source.start > finish @@ -369,6 +373,10 @@ local function solveAwaitInSync(uri, diag, results) end local function solveSpell(uri, diag, results) + local state = files.getState(uri) + if not state then + return + end local spell = require 'provider.spell' local word = diag.data if word == nil then @@ -401,8 +409,8 @@ local function solveSpell(uri, diag, results) changes = { [uri] = { { - start = converter.unpackPosition(uri, diag.range.start), - finish = converter.unpackPosition(uri, diag.range["end"]), + start = converter.unpackPosition(state, diag.range.start), + finish = converter.unpackPosition(state, diag.range["end"]), newText = suggest } } |