[mod] samples

This commit is contained in:
Andy Bunce 2025-08-01 23:14:52 +01:00
parent 2f54b3370e
commit 6e88dd1509
22 changed files with 1048 additions and 142 deletions

View file

@ -0,0 +1,21 @@
{
"capabilities": {
"textDocumentSync": 2,
"completionProvider": {
"resolveProvider": false,
"triggerCharacters": [ "\"", ":" ],
"documentSelector": [{ "language": "xquery" }]
},
"hoverProvider": true,
"documentSymbolProvider": true,
"documentRangeFormattingProvider": false,
"colorProvider": {},
"foldingRangeProvider": true,
"selectionRangeProvider": true,
"documentLinkProvider": {},
"serverInfo": {
"name": "My Custom Language Server",
"version": "1.0.0"
}
}
}

View file

@ -9,7 +9,7 @@ import module namespace lsp-text = 'lsp-text' at "lsp-text.xqm";
declare variable $lsprpc:methods:=map:merge((
map{
"initialize" : lsprpc:method-initialize#1,
"initialized" : lsprpc:method-unknown#1,
"initialized" : lsprpc:method-initialized#1,
"workspace/didChangeConfiguration" :lsprpc:method-unknown#1
},
$lsp-text:methods
@ -49,25 +49,18 @@ as map(*)
{
"jsonrpc": "2.0",
"id": $json?id,
"result": {
"capabilities": {
"textDocumentSync": 2,
"completionProvider": {
"resolveProvider": false(),
"triggerCharacters": [ """", ":" ]
},
"hoverProvider": true(),
"documentSymbolProvider": true(),
"documentRangeFormattingProvider": false(),
"colorProvider": {},
"foldingRangeProvider": true(),
"selectionRangeProvider": true(),
"documentLinkProvider": {}
}
}
"result": json:doc("capabilities.json",{"format":"w3"})
}
};
(:~ initialized response :)
declare
function lsprpc:method-initialized($json as map(*))
as empty-sequence()
{
ws:set(ws:id(),"initialized", true())
};
(:~ unknown method response :)
declare
function lsprpc:method-unknown($json as map(*))

View file

@ -12,20 +12,7 @@ declare variable $lsp-text:methods:=map{
"textDocument/completion": lsp-text:completion#1
};
(:~ hover
{
"jsonrpc": "2.0",
"id": 2,
"method": "textDocument/hover",
"params": {
"textDocument": {
"uri": "file:///session1.json"
},
"position": {
"line": 2,
"character": 22
}
}
}
:)
declare
function lsp-text:hover($json as map(*))
@ -35,7 +22,16 @@ as map(*)?
return map{
"jsonrpc": "2.0",
"id": $json?id,
"value":"uri: " || $doc
"result":{
"contents": [{
"language": "PlainText",
"value": "VPCONFLICTQ : [NONE,AVX512_CD] Detect Conflicts Within a Vector of Packed Dword/Qword Values into Dense Memory/ Register\n"
},
{
"language": "Markdown",
"value": "```text\n µOps µOps µOps \nArchitecture Instruction Fused Unfused Port Latency Throughput \nSkylakeX VPCONFLICTQ x,x 3 3 p01 p5 4 2 \nSkylakeX VPCONFLICTQ y,y 15 15 p01 p5 13 7 \nSkylakeX VPCONFLICTQ z,z 22 22 p0 p5 17 12 \n```"
}]
}
}
};

View file

@ -1,56 +0,0 @@
(:~
: Simple WebSocket chat. Utility functions.
: @author BaseX Team, BSD License
:)
module namespace lsp-util = 'chat/util';
import module namespace ws = 'http://basex.org/modules/ws';
(:~ User id (bound to sessions and WebSockets). :)
declare variable $lsp-util:id := 'id';
(:~
: Sends a users list (all, active) to all registered clients.
:)
declare function lsp-util:users() as empty-sequence() {
ws:emit(map{
'type': 'users',
'users': array { sort(user:list()) },
'active': array { distinct-values(
for $id in ws:ids()
return ws:get($id, $lsp-util:id)
)}
})
};
(:~
: Sends a message to all clients, or to the clients of a specific user.
: @param $text text to be sent
: @param $to receiver of a private message (optional)
:)
declare function lsp-util:message(
$text as xs:string,
$to as xs:string?
) as empty-sequence() {
let $ws-ids := ws:ids()[not($to) or ws:get(., $lsp-util:id) = $to]
return ws:send(map{
'type': 'message',
'text': serialize($text),
'from': ws:get(ws:id(), $lsp-util:id),
'date': format-time(current-time(), '[H02]:[m02]:[s02]'),
'private': boolean($to)
}, $ws-ids)
};
(:~
: Closes all WebSocket connections from the specified user.
: @param $name username
:)
declare function lsp-util:close(
$name as xs:string
) as empty-sequence() {
for $id in ws:ids()
where ws:get($id, $lsp-util:id) = $name
return ws:close($id)
};

View file

@ -5,7 +5,7 @@
module namespace lsp-ws = 'lsp-ws';
import module namespace lsprpc = 'lsprpc' at 'jsonrpc.xqm';
import module namespace chat-util = 'chat/util' at 'lsp-util.xqm';
declare
%ws:error('/lsp', '{$error}')
@ -22,9 +22,7 @@ function lsp-ws:connect() as empty-sequence() {
let $id:=ws:id()=>trace("CONNECT: ")
return (
ws:set($id, "id", $id),
store:clear(),
store:put("id",$id),
store:write("lsp-store")
ws:set($id, "initialized", false())
)
};
@ -46,11 +44,10 @@ function lsp-ws:message(
(:~
: Closes a WebSocket connection. Unregisters the user and notifies all clients.
: Closes a WebSocket connection.
:)
declare
%ws:close('/lsp')
function lsp-ws:close() as empty-sequence() {
ws:delete(ws:id(), $chat-util:id),
chat-util:users()
message("SOCKET CLOSE: " || ws:id())
};