summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
Diffstat (limited to 'script/core')
-rw-r--r--script/core/code-action.lua28
-rw-r--r--script/core/command/autoRequire.lua3
-rw-r--r--script/core/completion/completion.lua3
-rw-r--r--script/core/formatting.lua9
-rw-r--r--script/core/type-formatting.lua3
5 files changed, 35 insertions, 11 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index d2cf440a..f9926b64 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -14,6 +14,9 @@ local function checkDisableByLuaDocExits(uri, row, mode, code)
return nil
end
local state = files.getState(uri)
+ if not state then
+ return nil
+ end
local lines = state.lines
if state.ast.docs and lines then
return guide.eachSourceBetween(
@@ -128,9 +131,12 @@ local function changeVersion(uri, version, results)
end
local function solveUndefinedGlobal(uri, diag, results)
- local ast = files.getState(uri)
- local start = converter.unpackRange(uri, diag.range)
- guide.eachSourceContain(ast.ast, start, function (source)
+ local state = files.getState(uri)
+ if not state then
+ return
+ end
+ local start = converter.unpackRange(uri, diag.range)
+ guide.eachSourceContain(state.ast, start, function (source)
if source.type ~= 'getglobal' then
return
end
@@ -147,9 +153,12 @@ local function solveUndefinedGlobal(uri, diag, results)
end
local function solveLowercaseGlobal(uri, diag, results)
- local ast = files.getState(uri)
- local start = converter.unpackRange(uri, diag.range)
- guide.eachSourceContain(ast.ast, start, function (source)
+ local state = files.getState(uri)
+ if not state then
+ return
+ end
+ local start = converter.unpackRange(uri, diag.range)
+ guide.eachSourceContain(state.ast, start, function (source)
if source.type ~= 'setglobal' then
return
end
@@ -160,8 +169,11 @@ local function solveLowercaseGlobal(uri, diag, results)
end
local function findSyntax(uri, diag)
- local ast = files.getState(uri)
- for _, err in ipairs(ast.errs) do
+ local state = files.getState(uri)
+ if not state then
+ return
+ 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)
if util.equal(range, diag.range) then
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua
index c0deecfc..923c6f11 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 then
+ return
+ end
local lines = state.lines
local fmt = {
pair = false,
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 52ec7a18..4fc63962 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -204,6 +204,9 @@ local function getSnip(source)
local uri = guide.getUri(def)
local text = files.getText(uri)
local state = files.getState(uri)
+ if not state then
+ goto CONTINUE
+ end
local lines = state.lines
if not text then
goto CONTINUE
diff --git a/script/core/formatting.lua b/script/core/formatting.lua
index b52854a4..fb5ca9c7 100644
--- a/script/core/formatting.lua
+++ b/script/core/formatting.lua
@@ -4,7 +4,10 @@ local log = require("log")
return function(uri, options)
local text = files.getOriginText(uri)
- local ast = files.getState(uri)
+ local state = files.getState(uri)
+ if not state then
+ return
+ end
local status, formattedText = codeFormat.format(uri, text, options)
if not status then
@@ -17,8 +20,8 @@ return function(uri, options)
return {
{
- start = ast.ast.start,
- finish = ast.ast.finish,
+ start = state.ast.start,
+ finish = state.ast.finish,
text = formattedText,
}
}
diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua
index 24b4dde4..7005af26 100644
--- a/script/core/type-formatting.lua
+++ b/script/core/type-formatting.lua
@@ -6,6 +6,9 @@ local function insertIndentation(uri, position, edits)
local text = files.getText(uri)
local state = files.getState(uri)
local row = guide.rowColOf(position)
+ if not state then
+ return
+ end
local offset = state.lines[row]
local indent = text:match('^%s*', offset)
for _, edit in ipairs(edits) do