summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/code_action.lua33
-rw-r--r--server/src/parser/ast.lua21
-rw-r--r--server/src/parser/grammar.lua2
3 files changed, 52 insertions, 4 deletions
diff --git a/server/src/core/code_action.lua b/server/src/core/code_action.lua
index 3c61ed56..b28bda34 100644
--- a/server/src/core/code_action.lua
+++ b/server/src/core/code_action.lua
@@ -216,6 +216,36 @@ local function solveSyntaxByAddDoEnd(uri, data, callback)
}
end
+local function solveSyntaxByFix(uri, err, lines, callback)
+ local changes = {}
+ for _, e in ipairs(err.fix) do
+ local start_row, start_col = lines:rowcol(e.start)
+ local finish_row, finish_col = lines:rowcol(e.finish)
+ changes[#changes+1] = {
+ range = {
+ start = {
+ line = start_row - 1,
+ character = start_col - 1,
+ },
+ ['end'] = {
+ line = finish_row - 1,
+ character = finish_col,
+ },
+ },
+ newText = e.text,
+ }
+ end
+ callback {
+ title = lang.script[err.fix.title],
+ kind = 'quickfix',
+ edit = {
+ changes = {
+ [uri] = changes,
+ }
+ }
+ }
+end
+
---@param lsp LSP
---@param uri uri
---@param data table
@@ -239,6 +269,9 @@ local function solveSyntax(lsp, uri, data, callback)
if err.type == 'ACTION_AFTER_BREAK' or err.type == 'ACTION_AFTER_RETURN' then
solveSyntaxByAddDoEnd(uri, data, callback)
end
+ if err.fix then
+ solveSyntaxByFix(uri, err, lines, callback)
+ end
end
local function solveDiagnostic(lsp, uri, data, callback)
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 1d44c848..80f82c82 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -264,6 +264,22 @@ local Defs = {
}
end
end,
+ CCommentPrefix = function (start, finish)
+ pushError {
+ type = 'ERR_COMMENT_PREFIX',
+ start = start,
+ finish = finish - 1,
+ fix = {
+ title = 'FIX_COMMENT_PREFIX',
+ {
+ start = start,
+ finish = finish,
+ text = '--',
+ },
+ }
+ }
+ return false
+ end,
String = function (start, quote, str, finish)
return {
type = 'string',
@@ -660,12 +676,9 @@ local Defs = {
}
elseif not wantField and isField and not isEmmy then
pushError {
- type = 'MISS_SYMBOL',
+ type = 'MISS_SEP_IN_TABLE',
start = start,
finish = arg.start-1,
- info = {
- symbol = ',',
- }
}
end
if isField then
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index bf725189..6e7a028e 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -388,6 +388,8 @@ CrtAction <- Semicolon
/ ExpInAction
UnkAction <- ({} {Word+})
-> UnknownAction
+ / ({} '//' {} (LongComment / ShortComment))
+ -> CCommentPrefix
/ ({} {. (!Sps !CrtAction .)*})
-> UnknownAction
ExpInAction <- Sp ({} Exp {})