diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/code-action.lua | 22 | ||||
-rw-r--r-- | script/core/command/jsonToLua.lua | 4 | ||||
-rw-r--r-- | script/core/command/removeSpace.lua | 2 | ||||
-rw-r--r-- | script/core/command/solve.lua | 4 | ||||
-rw-r--r-- | script/core/diagnostics/codestyle-check.lua | 9 | ||||
-rw-r--r-- | script/core/diagnostics/spell-check.lua | 9 | ||||
-rw-r--r-- | script/core/rangeformatting.lua | 10 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 10 | ||||
-rw-r--r-- | script/core/type-formatting.lua | 10 | ||||
-rw-r--r-- | script/core/view/psi-select.lua | 2 | ||||
-rw-r--r-- | script/core/view/psi-view.lua | 4 |
11 files changed, 51 insertions, 35 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 } } diff --git a/script/core/command/jsonToLua.lua b/script/core/command/jsonToLua.lua index 8d9e8ba1..da1aeb4b 100644 --- a/script/core/command/jsonToLua.lua +++ b/script/core/command/jsonToLua.lua @@ -11,7 +11,7 @@ local guide = require 'parser.guide' return function (data) local state = files.getState(data.uri) local text = files.getText(data.uri) - if not text then + if not text or not state then return end local start = guide.positionToOffset(state, data.start) @@ -43,7 +43,7 @@ return function (data) changes = { [data.uri] = { { - range = converter.packRange(data.uri, data.start, data.finish), + range = converter.packRange(state, data.start, data.finish), newText = luaStr, } } diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua index 992a0705..87d11fff 100644 --- a/script/core/command/removeSpace.lua +++ b/script/core/command/removeSpace.lua @@ -38,7 +38,7 @@ return function (data) end local firstPos = guide.offsetToPosition(state, firstOffset) - 1 textEdit[#textEdit+1] = { - range = converter.packRange(uri, firstPos, lastPos), + range = converter.packRange(state, firstPos, lastPos), newText = '', } diff --git a/script/core/command/solve.lua b/script/core/command/solve.lua index 98ceaa58..ca1458aa 100644 --- a/script/core/command/solve.lua +++ b/script/core/command/solve.lua @@ -36,7 +36,7 @@ return function (data) return end - local start, finish = converter.unpackRange(uri, data.range) + local start, finish = converter.unpackRange(state, data.range) local result = guide.eachSourceContain(state.ast, start, function (source) if source.start ~= start @@ -86,7 +86,7 @@ return function (data) changes = { [uri] = { { - range = converter.packRange(uri, result.start, result.finish), + range = converter.packRange(state, result.start, result.finish), newText = ('(%s)'):format(text:sub( guide.positionToOffset(state, result.start + 1), guide.positionToOffset(state, result.finish) diff --git a/script/core/diagnostics/codestyle-check.lua b/script/core/diagnostics/codestyle-check.lua index 6448979d..6d22597b 100644 --- a/script/core/diagnostics/codestyle-check.lua +++ b/script/core/diagnostics/codestyle-check.lua @@ -6,10 +6,11 @@ local pformatting = require 'provider.formatting' ---@async return function(uri, callback) - local text = files.getOriginText(uri) - if not text then + local state = files.getState(uri) + if not state then return end + local text = state.originText local suc, codeFormat = pcall(require, 'code_format') if not suc then @@ -31,8 +32,8 @@ return function(uri, callback) if diagnosticInfos then for _, diagnosticInfo in ipairs(diagnosticInfos) do callback { - start = converter.unpackPosition(uri, diagnosticInfo.range.start), - finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]), + start = converter.unpackPosition(state, diagnosticInfo.range.start), + finish = converter.unpackPosition(state, diagnosticInfo.range["end"]), message = diagnosticInfo.message } end diff --git a/script/core/diagnostics/spell-check.lua b/script/core/diagnostics/spell-check.lua index 7369a235..a4cb87be 100644 --- a/script/core/diagnostics/spell-check.lua +++ b/script/core/diagnostics/spell-check.lua @@ -6,10 +6,11 @@ local spell = require 'provider.spell' ---@async return function(uri, callback) - local text = files.getOriginText(uri) - if not text then + local state = files.getState(uri) + if not state then return end + local text = state.originText local status, diagnosticInfos = spell.spellCheck(uri, text) @@ -24,8 +25,8 @@ return function(uri, callback) if diagnosticInfos then for _, diagnosticInfo in ipairs(diagnosticInfos) do callback { - start = converter.unpackPosition(uri, diagnosticInfo.range.start), - finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]), + start = converter.unpackPosition(state, diagnosticInfo.range.start), + finish = converter.unpackPosition(state, diagnosticInfo.range["end"]), message = diagnosticInfo.message, data = diagnosticInfo.data } diff --git a/script/core/rangeformatting.lua b/script/core/rangeformatting.lua index 04a61bd9..7c3953e6 100644 --- a/script/core/rangeformatting.lua +++ b/script/core/rangeformatting.lua @@ -3,11 +3,15 @@ local log = require("log") local converter = require("proto.converter") return function(uri, range, options) + local state = files.getState(uri) + if not state then + return + end local suc, codeFormat = pcall(require, "code_format") if not suc then return end - local text = files.getOriginText(uri) + local text = state.originText local status, formattedText, startLine, endLine = codeFormat.range_format( uri, text, range.start.line, range["end"].line, options) @@ -21,8 +25,8 @@ return function(uri, range, options) return { { - start = converter.unpackPosition(uri, { line = startLine, character = 0 }), - finish = converter.unpackPosition(uri, { line = endLine + 1, character = 0 }), + start = converter.unpackPosition(state, { line = startLine, character = 0 }), + finish = converter.unpackPosition(state, { line = endLine + 1, character = 0 }), text = formattedText, } } diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index bc9bf8af..610b3061 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -699,13 +699,15 @@ local Care = util.switch() } end) -local function buildTokens(uri, results) +---@param state table +---@param results table +local function buildTokens(state, results) local tokens = {} local lastLine = 0 local lastStartChar = 0 for i, source in ipairs(results) do - local startPos = converter.packPosition(uri, source.start) - local finishPos = converter.packPosition(uri, source.finish) + local startPos = converter.packPosition(state, source.start) + local finishPos = converter.packPosition(state, source.finish) local line = startPos.line local startChar = startPos.character local deltaLine = line - lastLine @@ -881,7 +883,7 @@ return function (uri, start, finish) results = solveMultilineAndOverlapping(state, results) - local tokens = buildTokens(uri, results) + local tokens = buildTokens(state, results) return tokens end diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua index 94edc71b..419cb56b 100644 --- a/script/core/type-formatting.lua +++ b/script/core/type-formatting.lua @@ -199,22 +199,22 @@ local function typeFormat(results, uri, position, ch, options) return end local converter = require("proto.converter") - local pos = converter.packPosition(uri, position) + local pos = converter.packPosition(state, position) local typeFormatOptions = config.get(uri, 'Lua.typeFormat.config') local success, result = codeFormat.type_format(uri, text, pos.line, pos.character, options, typeFormatOptions) if success then local range = result.range results[#results+1] = { text = result.newText, - start = converter.unpackPosition(uri, { line = range.start.line, character = range.start.character }), - finish = converter.unpackPosition(uri, { line = range["end"].line, character = range["end"].character }), + start = converter.unpackPosition(state, { line = range.start.line, character = range.start.character }), + finish = converter.unpackPosition(state, { line = range["end"].line, character = range["end"].character }), } end end return function (uri, position, ch, options) - local ast = files.getState(uri) - if not ast then + local state = files.getState(uri) + if not state then return nil end diff --git a/script/core/view/psi-select.lua b/script/core/view/psi-select.lua index b6733aa5..40642039 100644 --- a/script/core/view/psi-select.lua +++ b/script/core/view/psi-select.lua @@ -8,6 +8,6 @@ return function(uri, position) return end - local pos = converter.unpackPosition(uri, position) + local pos = converter.unpackPosition(state, position) return { data = guide.positionToOffset(state, pos) } end diff --git a/script/core/view/psi-view.lua b/script/core/view/psi-view.lua index 86ed1403..640d1c4c 100644 --- a/script/core/view/psi-view.lua +++ b/script/core/view/psi-view.lua @@ -27,8 +27,8 @@ local function toPsiNode(astNode, state) local startOffset = guide.positionToOffset(state, astNode.start) local finishOffset = guide.positionToOffset(state, astNode.finish) - local startPosition = converter.packPosition(state.uri, astNode.start) - local finishPosition = converter.packPosition(state.uri, astNode.finish) + local startPosition = converter.packPosition(state, astNode.start) + local finishPosition = converter.packPosition(state, astNode.finish) return { name = string.format("%s@[%d:%d .. %d:%d]", astNode.type, |