[mod] refactor
This commit is contained in:
parent
ab88b9139e
commit
ce69c61b6c
2 changed files with 58 additions and 16 deletions
45
webapp/lsp/docs.xqm
Normal file
45
webapp/lsp/docs.xqm
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
(: Store for XQuery document data , type, text,uri
|
||||||
|
on save parse is created and stored
|
||||||
|
implementation: data is stored in webSocket
|
||||||
|
@author Andy Bunce
|
||||||
|
:)
|
||||||
|
module namespace docs="lsp/docs";
|
||||||
|
import module namespace p="xq4" at "xq4.xqm";
|
||||||
|
|
||||||
|
(: document info :)
|
||||||
|
declare type docs:property as enum("textDocument","parse");
|
||||||
|
|
||||||
|
(: get $property for $file from session $socket :)
|
||||||
|
declare function docs:get(
|
||||||
|
$socket as xs:string,
|
||||||
|
$file as xs:string,
|
||||||
|
$property as docs:property
|
||||||
|
)
|
||||||
|
{
|
||||||
|
let $key:=ws:get($socket,"files")($file)($property)
|
||||||
|
return ws:get($socket,$key)
|
||||||
|
};
|
||||||
|
|
||||||
|
(: save $textDocument data as session $socket properties :)
|
||||||
|
declare function docs:save(
|
||||||
|
$socket as xs:string,
|
||||||
|
$textDocument as map(*)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
let $text as xs:string:=$textDocument?text
|
||||||
|
let $uri:=$textDocument?uri
|
||||||
|
let $files:=ws:get($socket,"files",{})
|
||||||
|
let $files:=if(map:contains($files,$uri))
|
||||||
|
then $files
|
||||||
|
else map:put($files,$uri,{
|
||||||
|
"textDocument":random:uuid(),
|
||||||
|
"parse":random:uuid() })
|
||||||
|
let $keys:=$files($uri)
|
||||||
|
let $xml:=p:parse-Module($text)
|
||||||
|
|
||||||
|
return (
|
||||||
|
ws:set($socket,"files",$files),
|
||||||
|
ws:set($socket,$keys?textDocument,$textDocument),
|
||||||
|
ws:set($socket,$keys?parse,$xml)
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
@ -1,24 +1,21 @@
|
||||||
(: parse a didOpen :)
|
(: Save an XQuery doc and it's parse :)
|
||||||
import module namespace p="xq4" at "xq4.xqm";
|
import module namespace docs="lsp/docs" at "docs.xqm";
|
||||||
|
|
||||||
declare variable $textDocument external;
|
declare variable $textDocument external;
|
||||||
declare variable $webSocket as xs:string external;
|
declare variable $webSocket as xs:string external;
|
||||||
|
|
||||||
let $text as xs:string:=$textDocument?text
|
docs:save(
|
||||||
let $uri:=$textDocument?uri
|
$webSocket,
|
||||||
let $files:=ws:get($webSocket,"files",{})
|
$textDocument
|
||||||
let $files:=if(map:contains($files,$uri))
|
),
|
||||||
then $files
|
|
||||||
else map:put($files,$uri,{"textDocument":random:uuid(),"parse":random:uuid() })
|
|
||||||
let $keys:=$files($uri)
|
|
||||||
let $xml:=p:parse-Module($text)
|
|
||||||
|
|
||||||
return (
|
ws:send(
|
||||||
ws:set($webSocket,"files",$files),
|
{"jsonrpc": "2.0",
|
||||||
ws:set($webSocket,$keys?textDocument,$textDocument),
|
"method":"window/logMessage",
|
||||||
ws:set($webSocket,$keys?parse,$xml),
|
"params":{"type":1,"message":"TODO"}
|
||||||
ws:send({"jsonrpc": "2.0","method":"window/logMessage",
|
},
|
||||||
"params":{"type":1,"message":"TODO"}},$webSocket)
|
$webSocket
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue