basex-lsp/webapp/lsp/lsp-text.xqm
2025-08-07 23:06:42 +01:00

93 lines
No EOL
1.8 KiB
Text

(:~ handle textDocument messages
: @author andy bunce
:)
module namespace lsp-text = 'lsp-text';
import module namespace docs="lsp/docs" at "docs.xqm";
import module namespace rpc = 'rpc' at 'jsonrpc.xqm';
declare variable $lsp-text:methods:=map{
"textDocument/didOpen": lsp-text:didOpen#1,
"textDocument/didChange": lsp-text:didChange#1,
"textDocument/didClose" : lsp-text:method-unknown#1,
"textDocument/hover": lsp-text:hover#1,
"textDocument/completion": lsp-text:completion#1
};
(:~ hover
:)
declare
function lsp-text:hover($json as map(*))
as map(*)
{
map{
"jsonrpc": "2.0",
"id": $json?id,
"result":{
"contents": [
`markdown here, this is **bold**.
A [link](http://google.com)
The last line.`
,
`A hover at \\n\\n{ json:serialize($json?params?position) }
uri: {$json?params?textDocument?uri} `
]
}
}
};
declare
function lsp-text:completion($json as map(*))
as map(*)?
{
let $doc:=$json?params?textDocument?uri
return map{
"jsonrpc": "2.0",
"id": $json?id,
"result":()
}
};
(:~ 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 ")
(:
let $xml:=prof:time(p:parse-Module($text),"⏱️ p:parse-Module ")
let $x:=job:eval(xs:anyURI("parse.xq"),
{"params" : $json?params,
"webSocket":ws:id()},
{ 'cache': true() }
)
:)
return rpc:log("saved " || $uri)
};
(:~ didChange method response :)
declare
function lsp-text:didChange($json as map(*))
as map(*)?
{
let $uri:=docs:change(ws:id(),$json?params)=>prof:time("⏱️ doc:change ")
return docs:parse(ws:id(),$uri)
};
(:~ unknown method response :)
declare
function lsp-text:method-unknown($json as map(*))
as map(*)?
{
let $_:=trace($json?method,"unknown")
return ()
};