[mod] logging
This commit is contained in:
parent
41d9e081b5
commit
55fef63678
6 changed files with 54 additions and 42 deletions
|
|
@ -67,7 +67,7 @@ function app:socket($wsid) {
|
||||||
"connectTime": ws:get($wsid,"connectTime"),
|
"connectTime": ws:get($wsid,"connectTime"),
|
||||||
"files": map:keys($files),
|
"files": map:keys($files),
|
||||||
"file1": json:serialize($file, { 'format': 'w3', 'indent': 'no' }),
|
"file1": json:serialize($file, { 'format': 'w3', 'indent': 'no' }),
|
||||||
"doc": json:serialize($doc, { 'format': 'w3', 'indent': 'no' })
|
"doc": $doc
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
1
webapp/lsp-manager/static/script.js
Normal file
1
webapp/lsp-manager/static/script.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
// todo
|
||||||
|
|
@ -17,7 +17,12 @@
|
||||||
</ul>
|
</ul>
|
||||||
<hr />
|
<hr />
|
||||||
<div th:text="${file1}">doc</div>
|
<div th:text="${file1}">doc</div>
|
||||||
<div th:text="${doc}">doc</div>
|
|
||||||
|
<div th:text="${doc.uri}">doc</div>
|
||||||
|
<div th:text="${doc.languageId}">doc</div>
|
||||||
|
<div th:text="${doc.version}">doc</div>
|
||||||
|
<hr />
|
||||||
|
<pre th:text="${doc.text}" style="height:16em;overflow:scroll;">doc</pre>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,24 @@
|
||||||
module namespace rpc = 'rpc';
|
module namespace rpc = 'rpc';
|
||||||
import module namespace lsp-text = 'lsp-text' at "lsp-text.xqm";
|
import module namespace lsp-text = 'lsp-text' at "lsp-text.xqm";
|
||||||
|
|
||||||
|
(:~ build a notification :)
|
||||||
|
declare function rpc:build-notification ($method as xs:string, $params as map(*))
|
||||||
|
as map(*){
|
||||||
|
{"jsonrpc": "2.0", "method": $method, "params": $params }
|
||||||
|
};
|
||||||
|
|
||||||
|
(:~ response to $json msg, if result empty just acknowledge :)
|
||||||
|
declare function rpc:build-response($json as map(*),$result:=())
|
||||||
|
as map(*){
|
||||||
|
{ "jsonrpc": "2.0", "id": $json?id, "result": $result}
|
||||||
|
};
|
||||||
|
|
||||||
|
(:~ response when error :)
|
||||||
|
declare function rpc:build-error($info as map(*),$json as map(*))
|
||||||
|
as map(*){
|
||||||
|
{ "jsonrpc": "2.0", "id": $json?id, "error": $info }
|
||||||
|
};
|
||||||
|
|
||||||
(: map methods to functions :)
|
(: map methods to functions :)
|
||||||
declare variable $rpc:Methods:=map:merge((
|
declare variable $rpc:Methods:=map:merge((
|
||||||
map{
|
map{
|
||||||
|
|
@ -22,7 +40,7 @@ as map(*)?
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
let $json:=parse-json($msg)
|
let $json:=parse-json($msg)
|
||||||
return if($json?jsonrpc="2.0" and exists($json?method))
|
return if($json?jsonrpc eq "2.0" and exists($json?method))
|
||||||
then $json
|
then $json
|
||||||
else ()
|
else ()
|
||||||
} catch *{
|
} catch *{
|
||||||
|
|
@ -39,8 +57,10 @@ as map(*)?
|
||||||
declare
|
declare
|
||||||
function rpc:reply($json as map(*))
|
function rpc:reply($json as map(*))
|
||||||
as empty-sequence() {
|
as empty-sequence() {
|
||||||
let $f :=(message($json,"➡️"),
|
let $f :=(
|
||||||
$rpc:Methods?($json?method))
|
rpc:admin-log($json,"➡️"),
|
||||||
|
$rpc:Methods?($json?method)
|
||||||
|
)
|
||||||
let $response := $f!.($json)
|
let $response := $f!.($json)
|
||||||
return $response!rpc:send(.)
|
return $response!rpc:send(.)
|
||||||
};
|
};
|
||||||
|
|
@ -50,7 +70,7 @@ declare
|
||||||
function rpc:send($msg as map(*))
|
function rpc:send($msg as map(*))
|
||||||
as empty-sequence()
|
as empty-sequence()
|
||||||
{
|
{
|
||||||
ws:send($msg =>trace("⬅️"),ws:id())
|
rpc:admin-log($msg,"⬅️"),ws:send($msg ,ws:id())
|
||||||
};
|
};
|
||||||
|
|
||||||
(:~ canned initialize response :)
|
(:~ canned initialize response :)
|
||||||
|
|
@ -59,7 +79,7 @@ function rpc:method-initialize($json as map(*))
|
||||||
as map(*)
|
as map(*)
|
||||||
{
|
{
|
||||||
ws:set(ws:id(),"client", $json?params),
|
ws:set(ws:id(),"client", $json?params),
|
||||||
rpc:result($json,
|
rpc:build-response($json,
|
||||||
json:doc("etc/capabilities.json",{"format":"w3"}))
|
json:doc("etc/capabilities.json",{"format":"w3"}))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -85,38 +105,20 @@ as map(*)?
|
||||||
declare function rpc:log($msg as xs:string)
|
declare function rpc:log($msg as xs:string)
|
||||||
as map(*)
|
as map(*)
|
||||||
{
|
{
|
||||||
{"jsonrpc": "2.0",
|
rpc:build-notification(
|
||||||
"method":"window/logMessage",
|
"window/logMessage",
|
||||||
"params":{"type":1, "message": $msg}
|
{"type":1, "message": $msg}
|
||||||
}
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
(:~ rpc response to $json msg, if result empty just acknowledge :)
|
(:~ write to admin:log :)
|
||||||
declare function rpc:result($json as map(*),$result:=())
|
declare function rpc:admin-log($data as item()*,$emoji as xs:string)
|
||||||
as map(*)
|
as empty-sequence()
|
||||||
{
|
{
|
||||||
map{
|
let $msg:= json:serialize($data,{ 'format': 'w3', 'indent': 'no' })
|
||||||
"jsonrpc": "2.0",
|
return admin:write-log($emoji || $msg,"LSP")
|
||||||
"id": $json?id,
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
(:~ window/showMessage :)
|
(:~ window/showMessage :)
|
||||||
declare function rpc:show-message($msg as xs:string)
|
declare function rpc:show-message($msg as xs:string)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ as map(*)
|
||||||
let $pos:=$json?params?position
|
let $pos:=$json?params?position
|
||||||
let $uri:= $json?params?textDocument?uri
|
let $uri:= $json?params?textDocument?uri
|
||||||
let $r:=hov:list($uri,$pos)
|
let $r:=hov:list($uri,$pos)
|
||||||
return rpc:result($json,{"contents":array:build($r)})
|
return rpc:build-response($json,{"contents":array:build($r)})
|
||||||
};
|
};
|
||||||
|
|
||||||
(:~ symbols :)
|
(:~ symbols :)
|
||||||
|
|
@ -43,7 +43,7 @@ as map(*)?
|
||||||
let $uri:=$json?params?textDocument?uri
|
let $uri:=$json?params?textDocument?uri
|
||||||
let $xml:=docs:get(ws:id(), $uri, "parse")
|
let $xml:=docs:get(ws:id(), $uri, "parse")
|
||||||
let $syms:=syms:list($xml,string($xml))
|
let $syms:=syms:list($xml,string($xml))
|
||||||
return rpc:result($json,array:build($syms))
|
return rpc:build-response($json,array:build($syms))
|
||||||
};
|
};
|
||||||
|
|
||||||
declare
|
declare
|
||||||
|
|
@ -53,7 +53,7 @@ as map(*)?
|
||||||
let $uri:=$json?params?textDocument?uri
|
let $uri:=$json?params?textDocument?uri
|
||||||
let $context:=$json?params?context (:{"triggerCharacter":":","triggerKind":2.0e0}:)
|
let $context:=$json?params?context (:{"triggerCharacter":":","triggerKind":2.0e0}:)
|
||||||
let $result:=comp:list($context)=>prof:time("⏱️ completions " || $uri)
|
let $result:=comp:list($context)=>prof:time("⏱️ completions " || $uri)
|
||||||
return rpc:result($json,array:build($result))
|
return rpc:build-response($json,array:build($result))
|
||||||
};
|
};
|
||||||
|
|
||||||
declare
|
declare
|
||||||
|
|
@ -64,14 +64,18 @@ as map(*)?
|
||||||
let $text:=docs:get(ws:id(), $uri, "textDocument")?text
|
let $text:=docs:get(ws:id(), $uri, "textDocument")?text
|
||||||
let $xml:=docs:get(ws:id(), $uri, "parse")
|
let $xml:=docs:get(ws:id(), $uri, "parse")
|
||||||
return if($xml/self::ERROR)
|
return if($xml/self::ERROR)
|
||||||
then rpc:error("Syntax errors found.",$json)
|
then rpc:build-error(
|
||||||
|
{ "code": -32803, "message": "Syntax errors found.",
|
||||||
|
"data": { "documentUri": $uri, "reason": "Syntax errors found." }
|
||||||
|
}
|
||||||
|
,$json)
|
||||||
else
|
else
|
||||||
let $xml:=$xml update {lsp-text:tidy(.)}
|
let $xml:=$xml update {lsp-text:tidy(.)}
|
||||||
let $result:=[{
|
let $result:=[{
|
||||||
"range":pos:full-range($text),
|
"range":pos:full-range($text),
|
||||||
"newText": string($xml)
|
"newText": string($xml)
|
||||||
}]
|
}]
|
||||||
return rpc:result($json,$result)
|
return rpc:build-response($json,$result)
|
||||||
};
|
};
|
||||||
|
|
||||||
(:~ didOpen method response :)
|
(:~ didOpen method response :)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ function lsp-ws:error($error) {
|
||||||
declare
|
declare
|
||||||
%ws:connect('/lsp')
|
%ws:connect('/lsp')
|
||||||
function lsp-ws:connect() as empty-sequence() {
|
function lsp-ws:connect() as empty-sequence() {
|
||||||
let $id:=ws:id()=>trace("CONNECT: ")
|
let $id:=(ws:id(),rpc:admin-log("CONNECT","🌹"))
|
||||||
return (
|
return (
|
||||||
ws:set($id, "id", $id),
|
ws:set($id, "id", $id),
|
||||||
ws:set($id, "connectTime", current-dateTime()),
|
ws:set($id, "connectTime", current-dateTime()),
|
||||||
|
|
@ -48,5 +48,5 @@ function lsp-ws:message(
|
||||||
declare
|
declare
|
||||||
%ws:close('/lsp')
|
%ws:close('/lsp')
|
||||||
function lsp-ws:close() as empty-sequence() {
|
function lsp-ws:close() as empty-sequence() {
|
||||||
message("SOCKET CLOSE: " || ws:id())
|
rpc:admin-log("CLOSE","🥀")
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue