[mod] improve formatting
This commit is contained in:
parent
0508901f72
commit
877e7b8d13
5 changed files with 47 additions and 17 deletions
|
@ -1,3 +1,4 @@
|
|||
(: parse xq and save result:)
|
||||
import module namespace p="xq4" at "C:\Users\mrwhe\git\quodatum\basex-lsp\webapp\lsp\xq4.xqm";
|
||||
declare variable $generator.xpath :="https://raw.githubusercontent.com/dnovatchev/Articles/refs/heads/main/Generators/Code/generator.xq";
|
||||
|
||||
|
@ -5,8 +6,8 @@ declare variable $pdfbox-good.xqm :="../../test/sample.docs/pdfbox.xqm";
|
|||
declare variable $dest:="C:\Users\mrwhe\git\quodatum\basex-lsp\test\sample.docs\parse-pdfbox.xml";
|
||||
|
||||
let $parse:= $pdfbox-good.xqm
|
||||
=>fetch:text()
|
||||
=>lazy:cache()
|
||||
=>p:parse-Module()
|
||||
=>fetch:text()
|
||||
=>lazy:cache()
|
||||
=>p:parse-Module()
|
||||
|
||||
return file:write($dest,$parse)
|
|
@ -49,11 +49,8 @@ declare
|
|||
function rpc:method-initialize($json as map(*))
|
||||
as map(*)
|
||||
{
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": $json?id,
|
||||
"result": json:doc("etc/capabilities.json",{"format":"w3"})
|
||||
}
|
||||
json:doc("etc/capabilities.json",{"format":"w3"})
|
||||
=>rpc:result($json)
|
||||
};
|
||||
|
||||
(:~ initialized response :)
|
||||
|
@ -84,7 +81,7 @@ as map(*)
|
|||
};
|
||||
|
||||
(:~ rpc response to $json msg :)
|
||||
declare function rpc:response($result,$json as map(*))
|
||||
declare function rpc:result($result,$json as map(*))
|
||||
as map(*)
|
||||
{
|
||||
map{
|
||||
|
@ -93,3 +90,19 @@ map{
|
|||
"result": $result
|
||||
}
|
||||
};
|
||||
|
||||
(:~ response when error :)
|
||||
declare function rpc:error($message as xs:string,$json as map(*))
|
||||
{
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": $json?id,
|
||||
"error": {
|
||||
"code": -32803,
|
||||
"message": $message,
|
||||
"data": { "documentUri": "file:///example.txt",
|
||||
"reason": "Syntax block"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
|
@ -31,7 +31,7 @@ The last line.`
|
|||
,
|
||||
`A hover at { pos:ln-col($json?params?position) } uri: {$json?params?textDocument?uri} `
|
||||
]
|
||||
return rpc:response({"contents":$r},$json)
|
||||
return rpc:result({"contents":$r},$json)
|
||||
};
|
||||
|
||||
|
||||
|
@ -53,16 +53,17 @@ as map(*)?
|
|||
{
|
||||
let $uri:=$json?params?textDocument?uri
|
||||
let $text:=docs:get(ws:id(), $uri, "textDocument")?text
|
||||
let $xml:=docs:get(ws:id(), $uri, "parse")
|
||||
return if($xml/self::ERROR)
|
||||
then rpc:error("Syntax errors found.",$json)
|
||||
else
|
||||
let $xml:=$xml update {lsp-text:tidy(.)}
|
||||
let $fmt:=`(: formatting to do :)
|
||||
`
|
||||
return map{
|
||||
"jsonrpc": "2.0",
|
||||
"id": $json?id,
|
||||
"result":[{
|
||||
return rpc:result([{
|
||||
"range":pos:full-range($text),
|
||||
"newText": $fmt || $text
|
||||
}]
|
||||
}
|
||||
"newText": $fmt || string($xml)
|
||||
}],$json)
|
||||
};
|
||||
|
||||
(:~ didOpen method response :)
|
||||
|
@ -93,3 +94,18 @@ as map(*)?
|
|||
let $_:=trace($json?method,"unknown")
|
||||
return ()
|
||||
};
|
||||
|
||||
(:~ ensure spaces around := :)
|
||||
declare %updating function lsp-text:tidy($doc){
|
||||
for $a in $doc//TOKEN[.=":="]
|
||||
let $before:= $a/preceding-sibling::node()[1]
|
||||
let $after:= $a/following-sibling::node()[1]
|
||||
|
||||
return (
|
||||
if($before instance of element(*))
|
||||
then insert node " " before $a else (),
|
||||
|
||||
if($after instance of element(*))
|
||||
then insert node " " after $a else ()
|
||||
)
|
||||
};
|
Loading…
Add table
Reference in a new issue