[add] base64 handling
This commit is contained in:
parent
04134c720b
commit
6d5323918b
3 changed files with 32 additions and 18 deletions
|
|
@ -5,7 +5,7 @@ It written for BaseX 12.0 and uses the [BaseX websocket](https://docs.basex.org/
|
||||||
RFC 6455](https://www.rfc-editor.org/rfc/rfc6455.html)
|
RFC 6455](https://www.rfc-editor.org/rfc/rfc6455.html)
|
||||||
|
|
||||||
# Demo
|
# Demo
|
||||||
The demos expect `Docker` or `Podman` on the local machine. This is only a requirement for the demos.
|
The demo makes use of `Docker` or `Podman` for ease of setup. This is not a requirement to use the software.
|
||||||
|
|
||||||
1 Clone this repo
|
1 Clone this repo
|
||||||
2. Run `docker compose up -d` The LSP server shall now running on port 3000 (edit `compose.yaml` to change port)
|
2. Run `docker compose up -d` The LSP server shall now running on port 3000 (edit `compose.yaml` to change port)
|
||||||
|
|
|
||||||
|
|
@ -33,21 +33,6 @@ declare variable $rpc:Methods:=map:merge((
|
||||||
$lsp-text:methods
|
$lsp-text:methods
|
||||||
));
|
));
|
||||||
|
|
||||||
(:~ return map if $msg is jsonrpc else empty :)
|
|
||||||
declare
|
|
||||||
function rpc:parse($msg as xs:string)
|
|
||||||
as map(*)?
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
let $json:=parse-json($msg)
|
|
||||||
return if($json?jsonrpc eq "2.0" and exists($json?method))
|
|
||||||
then $json
|
|
||||||
else ()
|
|
||||||
} catch *{
|
|
||||||
()
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
(:~ send reply to $json message
|
(:~ send reply to $json message
|
||||||
get functions for methods
|
get functions for methods
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,15 @@ declare
|
||||||
function lsp-ws:message(
|
function lsp-ws:message(
|
||||||
$message as xs:string
|
$message as xs:string
|
||||||
) as empty-sequence() {
|
) as empty-sequence() {
|
||||||
|
|
||||||
let $json := rpc:parse($message)
|
let $json := lsp-ws:parse($message)
|
||||||
return if(exists($json))
|
return if(exists($json))
|
||||||
then rpc:reply($json)
|
then rpc:reply($json)
|
||||||
else message($message,"bad RPC: ")
|
else message($message,"bad RPC: ")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(:~
|
(:~
|
||||||
: Closes a WebSocket connection.
|
: Closes a WebSocket connection.
|
||||||
:)
|
:)
|
||||||
|
|
@ -55,3 +56,31 @@ declare
|
||||||
function lsp-ws:close() as empty-sequence() {
|
function lsp-ws:close() as empty-sequence() {
|
||||||
rpc:admin-log("CLOSE","🥀")
|
rpc:admin-log("CLOSE","🥀")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(:~ return map if $msg is jsonrpc else empty :)
|
||||||
|
declare
|
||||||
|
function lsp-ws:parse($msg as xs:string)
|
||||||
|
as map(*)?
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
let $jtext:=if(starts-with($msg,"{"))
|
||||||
|
then $msg
|
||||||
|
else lsp-ws:decode($msg)
|
||||||
|
|
||||||
|
let $json:=parse-json($jtext)
|
||||||
|
return if($json?jsonrpc eq "2.0" and exists($json?method))
|
||||||
|
then $json
|
||||||
|
else ()
|
||||||
|
} catch *{
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
(:~ decode
|
||||||
|
"Q29udGVudC1MZW5ndGg6IDU4NDUNCg0K" -> "Content-Length: 5845"
|
||||||
|
:)
|
||||||
|
declare function lsp-ws:decode($basex64 as xs:string)
|
||||||
|
as xs:string{
|
||||||
|
xs:base64Binary($basex64) => bin:to-octets() => codepoints-to-string()
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue