diff options
Diffstat (limited to 'script/core/command')
-rw-r--r-- | script/core/command/autoRequire.lua | 7 | ||||
-rw-r--r-- | script/core/command/removeSpace.lua | 13 | ||||
-rw-r--r-- | script/core/command/solve.lua | 2 |
3 files changed, 9 insertions, 13 deletions
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua index c0deecfc..32911d92 100644 --- a/script/core/command/autoRequire.lua +++ b/script/core/command/autoRequire.lua @@ -21,6 +21,9 @@ end local function findInsertRow(uri) local text = files.getText(uri) local state = files.getState(uri) + if not state or not text then + return + end local lines = state.lines local fmt = { pair = false, @@ -68,7 +71,7 @@ local function askAutoRequire(uri, visiblePaths) local selects = {} local nameMap = {} for _, visible in ipairs(visiblePaths) do - local expect = visible.expect + local expect = visible.name local select = lang.script(expect) if not nameMap[select] then nameMap[select] = expect @@ -143,7 +146,7 @@ return function (data) return end table.sort(visiblePaths, function (a, b) - return #a.expect < #b.expect + return #a.name < #b.name end) local result = askAutoRequire(uri, visiblePaths) diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua index aa565f7f..992a0705 100644 --- a/script/core/command/removeSpace.lua +++ b/script/core/command/removeSpace.lua @@ -4,20 +4,12 @@ local proto = require 'proto' local lang = require 'language' local converter = require 'proto.converter' -local function isInString(ast, offset) - return guide.eachSourceContain(ast.ast, offset, function (source) - if source.type == 'string' then - return true - end - end) or false -end - ---@async return function (data) local uri = data.uri local text = files.getText(uri) local state = files.getState(uri) - if not state then + if not state or not text then return end @@ -32,7 +24,8 @@ return function (data) goto NEXT_LINE end local lastPos = guide.offsetToPosition(state, lastOffset) - if isInString(state.ast, lastPos) then + if guide.isInString(state.ast, lastPos) + or guide.isInComment(state.ast, lastPos) then goto NEXT_LINE end local firstOffset = startOffset diff --git a/script/core/command/solve.lua b/script/core/command/solve.lua index 8065aa9d..98ceaa58 100644 --- a/script/core/command/solve.lua +++ b/script/core/command/solve.lua @@ -32,7 +32,7 @@ return function (data) local uri = data.uri local text = files.getText(uri) local state = files.getState(uri) - if not state then + if not state or not text then return end |