[add] diags from server

This commit is contained in:
Andy Bunce 2025-08-14 18:20:41 +01:00
parent 5c759eb3f4
commit 2078055d05
8 changed files with 150 additions and 15 deletions

View file

@ -25,7 +25,7 @@ declare function lsp-diags:publish(
$xml as lsp-diags:ParseResult)
as map(*){
let $diagnostics:=if($xml/self::ERROR)
then [lsp-diags:parse-error($text, $xml)]
then array{lsp-diags:parse-error($text, $xml)}
else []
return {"jsonrpc": "2.0",
@ -38,9 +38,13 @@ 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>
:)
declare function lsp-diags:parse-error($text as xs:string, $xml as element(ERROR))
as map(*)?{
as map(*)*{
lsp-diags:nostic(pos:Range(pos:toPosition($text=>trace("EXML "), $xml/@b),
pos:toPosition($text, $xml/@e)),
1,$xml/string())=>trace("EEEE ")
1,$xml/string())=>trace("EEEE "),
lsp-diags:nostic(pos:Range(pos:toPosition($text=>trace("EXML "), $xml/@e +1 ),
pos:toPosition($text, string-length($text)-1)),
1,"Previous parse error")
};

View file

@ -3,13 +3,15 @@ text editing API
:)
module namespace pos="lsp/position";
declare type pos:num as (xs:integer|xs:double);
(:~
@param line Line position in a document (zero-based).
@param character Character offset on a line in a document (zero-based).
:)
declare record pos:Position(
line as xs:integer,
character as xs:integer
line as pos:num,
character as pos:num
);
(:~
@ -38,7 +40,7 @@ as xs:string{
(:~ find index from Position :)
declare function pos:resolvePosition($text as xs:string, $pos as pos:Position)
as xs:integer
as pos:num
{
let $nl:= index-of(string-to-codepoints($text),10)
let $off:=if($pos?line eq 0)
@ -49,7 +51,7 @@ as xs:integer
(:~ convert index into Position :)
declare function pos:toPosition($text as xs:string,
$index as xs:integer
$index as pos:num
)
as pos:Position {
let $nl:= index-of(string-to-codepoints($text),10)
@ -63,7 +65,7 @@ return pos:Position($line, $index - $off)
(:~ line number for $pos :)
declare function pos:lineAt($nl as xs:integer*,$pos as xs:integer)
declare function pos:lineAt($nl as xs:integer*,$pos as pos:num)
as xs:integer
{
if($pos le head($nl))