summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/method/textDocument/publishDiagnostics.lua21
-rw-r--r--server/src/parser/ast.lua9
-rw-r--r--server/src/parser/grammar.lua15
3 files changed, 27 insertions, 18 deletions
diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua
index e5c8b2ff..6e2f437a 100644
--- a/server/src/method/textDocument/publishDiagnostics.lua
+++ b/server/src/method/textDocument/publishDiagnostics.lua
@@ -79,23 +79,30 @@ end
local function buildError(err, lines)
local diagnostic = {
source = 'Lua Language Server',
- message = lang.script.PARSER_IN_DEVELOPMENT,
+ message = lang.script('PARSER_'..err.type, err.info)
}
if err.level == 'error' then
diagnostic.severity = DiagnosticSeverity.Error
else
diagnostic.severity = DiagnosticSeverity.Warning
end
- local row, col = lines:rowcol(err.pos)
- local _, max = lines:range(row)
+ local startrow, startcol = lines:rowcol(err.start)
+ local endrow, endcol
+ if err.finish then
+ endrow, endcol = lines:rowcol(err.finish)
+ else
+ endrow = startrow
+ local _, max = lines:range(endrow)
+ endcol = max
+ end
local range = {
start = {
- line = row - 1,
- character = col - 1,
+ line = startrow - 1,
+ character = startcol - 1,
},
['end'] = {
- line = row - 1,
- character = max,
+ line = endrow - 1,
+ character = endcol,
},
}
diagnostic.range = range
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 8c4e1a1c..2096fd28 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -2,6 +2,11 @@ local tonumber = tonumber
local string_char = string.char
local utf8_char = utf8.char
+local Errs
+local function pushError(err)
+ Errs[#Errs+1] = err
+end
+
local defs = {
Nil = function (pos)
return {
@@ -415,12 +420,14 @@ local defs = {
}
return function (self, lua, mode)
+ Errs = {}
local suc, res, err = pcall(self.grammar, lua, mode, defs)
if not suc then
return nil, res
end
if not res then
- return nil, {err}
+ pushError(err)
+ return nil, Errs
end
return res
end
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index ce7e4794..5ec5b826 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -1,6 +1,5 @@
local re = require 'parser.relabel'
local m = require 'lpeglabel'
-local calcline = require 'parser.calcline'
local scriptBuf = ''
@@ -74,14 +73,10 @@ local function grammar(tag)
end
end
-local labels = {
-
-}
-
-local function errorpos(lua, pos, err)
+local function errorpos(pos, err)
return {
- lua = lua,
- pos = pos,
+ type = 'UNKNOWN',
+ start = pos,
err = err,
level = 'error',
}
@@ -431,9 +426,9 @@ Lua <- (Sp Action)* -> Lua Sp
return function (lua, mode, parser_)
parser = parser_ or {}
local gram = compiled[mode] or compiled['Lua']
- local r, e, pos = gram:match(lua)
+ local r, _, pos = gram:match(lua)
if not r then
- local err = errorpos(lua, pos, e)
+ local err = errorpos(pos)
return nil, err
end