summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/await.lua3
-rw-r--r--script-beta/core/code-action.lua48
-rw-r--r--script-beta/parser/ast.lua4
-rw-r--r--script-beta/parser/guide.lua9
-rw-r--r--script-beta/provider/diagnostic.lua1
-rw-r--r--script-beta/vm/eachField.lua3
6 files changed, 65 insertions, 3 deletions
diff --git a/script-beta/await.lua b/script-beta/await.lua
index 00c2bcd0..95a63f4a 100644
--- a/script-beta/await.lua
+++ b/script-beta/await.lua
@@ -117,6 +117,9 @@ function m.wait(callback, ...)
return
end
waked = true
+ if coroutine.status(co) == 'dead' then
+ return
+ end
return m.checkResult(co, coroutine.resume(co, ...))
end, ...)
return coroutine.yield()
diff --git a/script-beta/core/code-action.lua b/script-beta/core/code-action.lua
index 86bd520e..8bba07d4 100644
--- a/script-beta/core/code-action.lua
+++ b/script-beta/core/code-action.lua
@@ -120,14 +120,60 @@ local function solveSyntaxByChangeVersion(err, results)
end
end
+local function solveSyntaxByAddDoEnd(uri, err, results)
+ local text = files.getText(uri)
+ local lines = files.getLines(uri)
+ results[#results+1] = {
+ title = lang.script.ACTION_ADD_DO_END,
+ kind = 'quickfix',
+ edit = {
+ changes = {
+ [uri] = {
+ {
+ range = define.range(lines, text, err.start, err.finish),
+ newText = ('do %s end'):format(text:sub(err.start, err.finish)),
+ },
+ }
+ }
+ }
+ }
+end
+
+local function solveSyntaxByFix(uri, err, results)
+ local text = files.getText(uri)
+ local lines = files.getLines(uri)
+ local changes = {}
+ for _, fix in ipairs(err.fix) do
+ changes[#changes+1] = {
+ range = define.range(lines, text, fix.start, fix.finish),
+ newText = fix.text,
+ }
+ end
+ results[#results+1] = {
+ title = lang.script['ACTION_' .. err.fix.title],
+ kind = 'quickfix',
+ edit = {
+ changes = {
+ [uri] = changes,
+ }
+ }
+ }
+end
+
local function solveSyntax(uri, diag, results)
- local err = findSyntax(uri, diag)
+ local err = findSyntax(uri, diag)
if not err then
return
end
if err.version then
solveSyntaxByChangeVersion(err, results)
end
+ if err.type == 'ACTION_AFTER_BREAK' or err.type == 'ACTION_AFTER_RETURN' then
+ solveSyntaxByAddDoEnd(uri, err, results)
+ end
+ if err.fix then
+ solveSyntaxByFix(uri, err, results)
+ end
end
local function solveDiagnostic(uri, diag, results)
diff --git a/script-beta/parser/ast.lua b/script-beta/parser/ast.lua
index 2e566047..bdf15508 100644
--- a/script-beta/parser/ast.lua
+++ b/script-beta/parser/ast.lua
@@ -1737,8 +1737,8 @@ end
local function close()
State = nil
- PushError = function () end
- PushDiag = function () end
+ PushError = function (_) end
+ PushDiag = function (_) end
end
return {
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index b69c4f75..f066d925 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -922,6 +922,9 @@ local function buildSimpleList(obj, max)
end
while cur.type == 'paren' do
cur = cur.exp
+ if not cur then
+ return nil
+ end
end
if cur.type == 'setfield'
or cur.type == 'getfield'
@@ -1137,6 +1140,9 @@ end
function m.getObjectValue(obj)
while obj.type == 'paren' do
obj = obj.exp
+ if not obj then
+ return nil
+ end
end
if obj.library then
return nil
@@ -2890,6 +2896,9 @@ end
function m.searchInfer(status, obj)
while obj.type == 'paren' do
obj = obj.exp
+ if not obj then
+ return
+ end
end
while true do
local value = m.getObjectValue(obj)
diff --git a/script-beta/provider/diagnostic.lua b/script-beta/provider/diagnostic.lua
index 48d0409d..89b70061 100644
--- a/script-beta/provider/diagnostic.lua
+++ b/script-beta/provider/diagnostic.lua
@@ -50,6 +50,7 @@ local function buildSyntaxError(uri, err)
end
return {
+ code = err.type:lower():gsub('_', '-'),
range = define.range(lines, text, err.start, err.finish),
severity = define.DiagnosticSeverity.Error,
source = lang.script.DIAG_SYNTAX_CHECK,
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index f4c2963a..d724f56d 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -26,6 +26,9 @@ local function eachField(source)
while source.type == 'paren' do
source = source.exp
+ if not source then
+ return
+ end
end
await.delay()