[mod] format progress
This commit is contained in:
parent
df114e8005
commit
073bcc3d3d
4 changed files with 46 additions and 27 deletions
|
@ -1,6 +1,6 @@
|
||||||
import module namespace pos="lsp/position" at "../webapp/lsp/position.xqm";
|
import module namespace pos="lsp/position" at "../webapp/lsp/position.xqm";
|
||||||
import module namespace xq4="java:quodatum.parser.xq4";
|
import module namespace xq4="java:quodatum.parser.xq4";
|
||||||
let $text:="1+2 a"
|
let $text:="1+"
|
||||||
let $xml:=xq4:parseModule($text)=>trace("£ ")
|
let $xml:=xq4:parseModule($text)=>trace("£ ")
|
||||||
let $b:=number($xml/@b)-1
|
let $b:=number($xml/@b)-1
|
||||||
let $e:= number($xml/@e)-1
|
let $e:= number($xml/@e)-1
|
||||||
|
|
|
@ -13,17 +13,15 @@ declare variable $lsp-text:methods:=map{
|
||||||
"textDocument/didClose" : lsp-text:method-unknown#1,
|
"textDocument/didClose" : lsp-text:method-unknown#1,
|
||||||
|
|
||||||
"textDocument/hover": lsp-text:hover#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
|
declare
|
||||||
function lsp-text:hover($json as map(*))
|
function lsp-text:hover($json as map(*))
|
||||||
as map(*)
|
as map(*)
|
||||||
{
|
{
|
||||||
|
|
||||||
let $r:= [
|
let $r:= [
|
||||||
`markdown here, this is **bold**.
|
`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 :)
|
(:~ didOpen method response :)
|
||||||
declare
|
declare
|
||||||
function lsp-text:didOpen($json as map(*))
|
function lsp-text:didOpen($json as map(*))
|
||||||
as map(*)?
|
as map(*)?
|
||||||
{
|
{
|
||||||
let $uri:=docs:open(ws:id(),$json?params)=>prof:time("⏱️ doc:save ")
|
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 :)
|
(:~ didChange method response :)
|
||||||
|
|
|
@ -24,22 +24,6 @@ declare record pos:Range(
|
||||||
end as pos:Position
|
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 :)
|
(:~ find index from Position :)
|
||||||
declare function pos:resolvePosition($text as xs:string, $pos as pos:Position)
|
declare function pos:resolvePosition($text as xs:string, $pos as pos:Position)
|
||||||
|
@ -95,3 +79,26 @@ declare function pos:ln-col($pos as pos:Position,$offset as xs:integer:=1)
|
||||||
{
|
{
|
||||||
`Ln { $pos?line + $offset}, Col { $pos?character + $offset}`
|
`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))
|
||||||
|
};
|
||||||
|
|
|
@ -40,7 +40,7 @@ $("sync").onclick = e => { client.sync(); console.log("XXXsync");};
|
||||||
|
|
||||||
$("format").onclick = e => {
|
$("format").onclick = e => {
|
||||||
client.sync();
|
client.sync();
|
||||||
console.log("FMT",lsp.formatDocument());
|
console.log("FMT",lsp.formatDocument(view));
|
||||||
};
|
};
|
||||||
|
|
||||||
$("load").onchange = e => {
|
$("load").onchange = e => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue