[mod] format progress

This commit is contained in:
Andy Bunce 2025-08-28 21:58:40 +01:00
parent df114e8005
commit 073bcc3d3d
4 changed files with 46 additions and 27 deletions

View file

@ -1,6 +1,6 @@
import module namespace pos="lsp/position" at "../webapp/lsp/position.xqm";
import module namespace xq4="java:quodatum.parser.xq4";
let $text:="1+2 a"
let $text:="1+"
let $xml:=xq4:parseModule($text)=>trace("£ ")
let $b:=number($xml/@b)-1
let $e:= number($xml/@e)-1

View file

@ -13,17 +13,15 @@ declare variable $lsp-text:methods:=map{
"textDocument/didClose" : lsp-text:method-unknown#1,
"textDocument/hover": lsp-text:hover#1,
"textDocument/completion": lsp-text:completion#1
"textDocument/completion": lsp-text:completion#1,
"textDocument/formatting" : lsp-text:format#1
};
(:~ hover
:)
(:~ hover :)
declare
function lsp-text:hover($json as map(*))
as map(*)
{
let $r:= [
`markdown here, this is **bold**.
@ -49,15 +47,29 @@ as map(*)?
}
};
declare
function lsp-text:format($json as map(*))
as map(*)?
{
let $uri:=$json?params?textDocument?uri
let $text:=docs:get(ws:id(), $uri, "textDocument")?text
return map{
"jsonrpc": "2.0",
"id": $json?id,
"result":{
"range":pos:full-range($text),
"newText":"formated"
}
}
};
(:~ didOpen method response :)
declare
function lsp-text:didOpen($json as map(*))
as map(*)?
{
let $uri:=docs:open(ws:id(),$json?params)=>prof:time("⏱️ doc:save ")
return docs:parse(ws:id(),$uri)
return docs:parse(ws:id(),$uri)
};
(:~ didChange method response :)

View file

@ -24,22 +24,6 @@ declare record pos:Range(
end as pos:Position
);
(:~ update $text with changes $chs from didChange
:)
declare function pos:apply-changes($text as xs:string, $chs as array(*))
as xs:string{
array:fold-left($chs,$text,pos:apply-change#2)
};
(:~ text updated single change :)
declare function pos:apply-change($text as xs:string, $ch as map(*))
as xs:string{
if(exists($ch?range))
then substring($text,1, pos:resolvePosition($text, $ch?range?start))
|| $ch?text ||
substring($text,pos:resolvePosition($text, $ch?range?end))
else $ch?text
};
(:~ find index from Position :)
declare function pos:resolvePosition($text as xs:string, $pos as pos:Position)
@ -94,4 +78,27 @@ as xs:integer
declare function pos:ln-col($pos as pos:Position,$offset as xs:integer:=1)
{
`Ln { $pos?line + $offset}, Col { $pos?character + $offset}`
};
};
(:~ update $text with changes $chs from didChange
:)
declare function pos:apply-changes($text as xs:string, $chs as array(*))
as xs:string{
array:fold-left($chs,$text,pos:apply-change#2)
};
(:~ text updated single change :)
declare function pos:apply-change($text as xs:string, $ch as map(*))
as xs:string{
if(exists($ch?range))
then substring($text,1, pos:resolvePosition($text, $ch?range?start))
|| $ch?text ||
substring($text,pos:resolvePosition($text, $ch?range?end))
else $ch?text
};
(:~ full range for $text :)
declare function pos:full-range($text as xs:string)
as pos:Range{
pos:Range(pos:toPosition($text,0), pos:toPosition($text, string-length($text)-1))
};

View file

@ -40,7 +40,7 @@ $("sync").onclick = e => { client.sync(); console.log("XXXsync");};
$("format").onclick = e => {
client.sync();
console.log("FMT",lsp.formatDocument());
console.log("FMT",lsp.formatDocument(view));
};
$("load").onchange = e => {