[fix] positions
This commit is contained in:
parent
1483a807f4
commit
77bc1e524c
5 changed files with 40 additions and 23 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,10 +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}
|
||||
|
|
@ -44,25 +45,28 @@ as map(*){
|
|||
};
|
||||
|
||||
(:~
|
||||
<ERROR b="10819" e="10820" o="234" s="43">syntax error, found '}' while expecting [S,'else'] at line 290, column 3: ...} }; ? return bookmark info for children of $outlineItem as s...</ERROR>
|
||||
assert.equal(markers[0].code, 'XPST0003', 'parse error');
|
||||
assert.equal(markers[1].code, 'XQLT0001', 'previous parse error');
|
||||
<ERROR b="10819" e="10820" o="234" s="43">syntax error, found '}' while expecting [S,'else'] at line 290, column 'XPST0003', 'parse error'
|
||||
'XQLT0001', 'previous parse error'
|
||||
:)
|
||||
declare function lsp-diags:parse-error($text as xs:string, $xml as element(ERROR))
|
||||
as map(*)*{
|
||||
let $dmesg:=$xml/string()
|
||||
let $dmesg:=$xml/string()=>trace("parse-error")
|
||||
let $dmesg:=translate($dmesg," ",";")
|
||||
let $b:=number($xml/@b)-1
|
||||
let $e:= number($xml/@e)-1
|
||||
return (
|
||||
lsp-diags:nostic(pos:Range(pos:toPosition($text, $xml/@b),
|
||||
pos:toPosition($text, $xml/@e)),
|
||||
$lsp-diags:severities('error'),
|
||||
$dmesg,code:="XPST0003"),
|
||||
|
||||
lsp-diags:nostic(pos:Range(pos:toPosition($text, $xml/@e +1 ),
|
||||
lsp-diags:nostic(pos:Range(pos:toPosition($text, $b),
|
||||
pos:toPosition($text, min(($e,string-length($text)-1)))),
|
||||
1,
|
||||
$dmesg,'XPST0003'),
|
||||
if($e ge string-length($text))
|
||||
then ()
|
||||
else lsp-diags:nostic(pos:Range(pos:toPosition($text, $e +1 ),
|
||||
pos:toPosition($text, string-length($text)-1)),
|
||||
$lsp-diags:severities('warning'),
|
||||
2,
|
||||
"Unparsed due to previous parser error.",
|
||||
code:="XQLT0001")
|
||||
"XQLT0001")
|
||||
)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,9 @@ declare function pos:toPosition($text as xs:string,
|
|||
$index as pos:num
|
||||
)
|
||||
as pos:Position {
|
||||
let $nl:= index-of(string-to-codepoints($text),10)
|
||||
let $nl:= if($index=>trace("IN ") ge string-length($text)=>trace("L "))
|
||||
then error(xs:QName("pos:range"),"out of range")
|
||||
else index-of(string-to-codepoints($text),10)
|
||||
let $line:=pos:lineAt($nl,$index)
|
||||
let $off:=if($line eq 0)
|
||||
then 0
|
||||
|
|
@ -70,7 +72,7 @@ return pos:Position($line, $index - $off)
|
|||
declare function pos:lineAt($nl as xs:integer*,$pos as pos:num)
|
||||
as xs:integer
|
||||
{
|
||||
if($pos le head($nl))
|
||||
if(empty($nl) or $pos le head($nl))
|
||||
then 0
|
||||
else if($pos gt foot($nl))
|
||||
then count($nl)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue