[fix] diag msg
This commit is contained in:
parent
ba9a3594b0
commit
6829f17673
4 changed files with 36 additions and 28 deletions
|
|
@ -17,7 +17,7 @@ declare record lsp-diags:nostic(
|
|||
range as pos:Range,
|
||||
severity as xs:integer, (: enum('error', 'hint', 'info', 'warning') :)
|
||||
message as xs:string,
|
||||
code as xs:string,
|
||||
code? as xs:string,
|
||||
source as xs:string:="xquery"
|
||||
);
|
||||
|
||||
|
|
@ -33,11 +33,11 @@ declare function lsp-diags:publish(
|
|||
$text as xs:string,
|
||||
$xml as lsp-diags:ParseResult)
|
||||
as map(*){
|
||||
let $_:=trace($xml,"PABLISH ")
|
||||
|
||||
let $diagnostics:=if($xml/self::ERROR)
|
||||
then array{lsp-diags:parse-error($text, $xml)}
|
||||
else array{ lsp-diags:parse-xquery($text,$xml)}
|
||||
let $_:=trace($diagnostics,"PIBLISH ")
|
||||
|
||||
return {"jsonrpc": "2.0",
|
||||
"method":"textDocument/publishDiagnostics",
|
||||
"params":{"uri": $uri, "diagnostics": $diagnostics}
|
||||
|
|
@ -50,25 +50,30 @@ let $_:=trace($diagnostics,"PIBLISH ")
|
|||
:)
|
||||
declare function lsp-diags:parse-error($text as xs:string, $xml as element(ERROR))
|
||||
as map(*)*{
|
||||
let $dmesg:=$xml/string()=>trace("parse-error")
|
||||
let $dmesg:=translate($dmesg," ",";")
|
||||
let $b:=number($xml/@b)-1
|
||||
let $e:= number($xml/@e)-1
|
||||
let $last:= string-length($text)-1
|
||||
return (
|
||||
|
||||
if(string-length($text) gt 0)
|
||||
then let $last:= max((0,string-length($text)-1))
|
||||
let $dmesg:=$xml/string()=>trace("parse-error")
|
||||
let $dmesg:=translate($dmesg," ",";")
|
||||
let $b:=number($xml/@b)-1
|
||||
let $e:= number($xml/@e)-1
|
||||
return (
|
||||
(: mark error :)
|
||||
lsp-diags:nostic(pos:Range(pos:toPosition($text, $b),
|
||||
pos:toPosition($text, min(($e,$last)))),
|
||||
1,
|
||||
$dmesg,'XPST0003'),
|
||||
|
||||
lsp-diags:nostic(pos:Range(pos:toPosition($text, $b),
|
||||
pos:toPosition($text, min(($e,$last)))),
|
||||
1,
|
||||
$dmesg,'XPST0003'),
|
||||
if($e ge string-length($text))
|
||||
then ()
|
||||
else lsp-diags:nostic(pos:Range(pos:toPosition($text, $e +1 ),
|
||||
pos:toPosition($text, $last)),
|
||||
2,
|
||||
"Unparsed due to previous parser error.",
|
||||
"XQLT0001")
|
||||
)
|
||||
(:mark after error:)
|
||||
if($e ge string-length($text))
|
||||
then ()
|
||||
else lsp-diags:nostic(pos:Range(pos:toPosition($text, $e +1 ),
|
||||
pos:toPosition($text, $last)),
|
||||
2,
|
||||
"Unparsed due to previous parser error.",
|
||||
"XQLT0001")
|
||||
)
|
||||
else ()
|
||||
};
|
||||
|
||||
(: test data :)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
(:~
|
||||
text editing API
|
||||
positions in text
|
||||
:)
|
||||
module namespace pos="lsp/position";
|
||||
|
||||
|
|
@ -89,6 +89,8 @@ as xs:integer
|
|||
return $s?max
|
||||
};
|
||||
|
||||
declare function pos:ln-col($pos as pos:Position){
|
||||
`Ln { $pos?line}, Col { $pos?character}`
|
||||
(:~ position text for display :)
|
||||
declare function pos:ln-col($pos as pos:Position,$offset as xs:integer:=1)
|
||||
{
|
||||
`Ln { $pos?line + $offset}, Col { $pos?character + $offset}`
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue