[add] fn completion

This commit is contained in:
Andy Bunce 2025-10-11 15:50:06 +01:00
parent 9894581d19
commit 24082ad97b
15 changed files with 123 additions and 56 deletions

View file

@ -308,6 +308,8 @@ public class xq4
{
try
{
Atts atts = new Atts();
atts.add(Token.token("b"), Token.token(pe.getBegin() + 1));
builder.openElem(Token.token(name), atts, nsp);
}
catch (IOException e)

View file

@ -1 +1 @@
{"cells":[{"kind":2,"language":"xquery","value":"(:<:)\r\n\r\nimport module namespace docs=\"lsp/docs\" at \"/srv/basex/webapp/lsp/docs.xqm\";\r\ndeclare variable $LAST:=foot(ws:ids());"},{"kind":2,"language":"xquery","value":"2+2"},{"kind":2,"language":"xquery","value":"ws:ids()"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn $t?text=>substring(1,100)"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"parse\")\r\nreturn $t?text"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn $t"},{"kind":2,"language":"xquery","value":"(: client capabilities :)\r\nws:get($LAST,\"client\")"}]}
{"cells":[{"kind":2,"language":"xquery","value":"(:<:)\r\n\r\nimport module namespace docs=\"lsp/docs\" at \"/srv/basex/webapp/lsp/docs.xqm\";\r\ndeclare variable $LAST:=foot(ws:ids());"},{"kind":2,"language":"xquery","value":"2+2"},{"kind":2,"language":"xquery","value":"ws:ids()"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn $t?text=>substring(1,100)"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"parse\")\r\nreturn $t?text"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn $t"},{"kind":2,"language":"xquery","value":"(: client capabilities :)\r\nws:get($LAST,\"client\")=>serialize({ \"method\": \"json\",\"indent\": true()})"}]}

View file

@ -1 +1 @@
{"cells":[{"kind":1,"language":"markdown","value":"XPath name charactors"},{"kind":2,"language":"xquery","value":"let $s:=`[A-Z]\r\n | '_'\r\n | [a-z]\r\n | [#xC0-#xD6]\r\n | [#xD8-#xF6]\r\n | [#xF8-#x2FF]\r\n | [#x370-#x37D]\r\n | [#x37F-#x1FFF]\r\n | [#x200C-#x200D]\r\n | [#x2070-#x218F]\r\n | [#x2C00-#x2FEF]\r\n | [#x3001-#xD7FF]\r\n | [#xF900-#xFDCF]\r\n | [#xFDF0-#xFFFD]\r\n `\r\nlet $sreg:= normalize-space($s)\r\n =>tokenize(\"\\|\")\r\n =!>normalize-space()\r\n =!>replace(\"(#x[0-9A-F]+)\",fn($s,$m){\r\n convert:integer-from-base(substring($m,3),16)\r\n =>codepoints-to-string()\r\n })\r\n =!>translate(\"'\",\"\")\r\n =>string-join(\"|\")\r\nreturn $sreg"}]}
{"cells":[{"kind":1,"language":"markdown","value":"XPath name charactors"},{"kind":2,"language":"xquery","value":"let $s:=`[A-Z]\r\n | '_'\r\n | [a-z]\r\n | [#xC0-#xD6]\r\n | [#xD8-#xF6]\r\n | [#xF8-#x2FF]\r\n | [#x370-#x37D]\r\n | [#x37F-#x1FFF]\r\n | [#x200C-#x200D]\r\n | [#x2070-#x218F]\r\n | [#x2C00-#x2FEF]\r\n | [#x3001-#xD7FF]\r\n | [#xF900-#xFDCF]\r\n | [#xFDF0-#xFFFD]\r\n `\r\nlet $sreg:= normalize-space($s)\r\n =>tokenize(\"\\|\")\r\n =!>normalize-space()\r\n =!>replace(\"(#x[0-9A-F]+)\",fn($s,$m){\r\n convert:integer-from-base(substring($m,3),16)\r\n =>codepoints-to-string()\r\n })\r\n =!>translate(\"'\",\"\")\r\n =>string-join(\"|\")\r\nreturn $sreg"},{"kind":1,"language":"markdown","value":"# Functions"},{"kind":2,"language":"xquery","value":"declare namespace fos=\"http://www.w3.org/xpath-functions/spec/namespace\";\r\ndoc(\"C:/Users/mrwhe/git/quodatum/basex-lsp/bundles/grammar/function-catalog.xml\")\r\n//fos:function[@prefix=\"fn\"]/@name"}]}

4
test/context.xq Normal file
View file

@ -0,0 +1,4 @@
import module namespace ctx="lsp/context" at "../webapp/lsp/context.xqm";
ctx:functions("fn")!ctx:map(.)=>trace("AA")

47
webapp/lsp/context.xqm Normal file
View file

@ -0,0 +1,47 @@
(: context information xpath functions etc
@author Andy Bunce
:)
module namespace ctx="lsp/context";
import module namespace lspt = 'lsp-typedefs' at 'lsp-typedefs.xqm';
declare namespace fos="http://www.w3.org/xpath-functions/spec/namespace";
declare variable $ctx:catalog:=doc("etc/function-catalog.xml");
declare variable $ctx:ns:=('fn', 'op','math','map','array');
declare variable $ctx:doclink:="https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-";
declare function ctx:functions($ns as xs:string)
as element(fos:function)*{
$ctx:catalog//fos:function[@prefix=$ns]
};
declare function ctx:map($fn as element(fos:function))
{
$fn!map{
"label":string(@name),
"kind": 3,
"detail":ctx:summary(.),
"documentation":`<a href="{ $ctx:doclink }{ string(@name) }" target="_blank">spec</a>`
!lspt:MarkupContent("markdown",.)
}
};
declare function ctx:summary($fn as element(fos:function))
{
$fn/fos:summary/*
=>ctx:strip-ns()
=>serialize({ 'method': 'html' })
};
declare function ctx:strip-ns($n as node()) as node() {
if($n instance of element()) then (
element { node-name($n) } {
$n/@*,
$n/node()/ctx:strip-ns(.)
}
) else if($n instance of document-node()) then (
document { ctx:strip-ns($n/node()) }
) else (
$n
)
};

View file

@ -13,7 +13,7 @@
}
]
},
"hoverProvider": false,
"hoverProvider": true,
"documentSymbolProvider": true,
"documentRangeFormattingProvider": false,
"colorProvider": false,

View file

@ -12,13 +12,13 @@ declare record hnd:Result(
declare type hnd:actionFn as fn($parse as element(),$state as hnd:Result ) as hnd:Result;
declare type hnd:actionMap as map(xs:string,hnd:actionFn)
;
declare type hnd:actionMap as map(xs:string,hnd:actionFn);
declare function hnd:walk($parse as element(),
$actions as hnd:actionMap,
$state as hnd:Result )
as hnd:Result{
as hnd:Result
{
let $action:=$actions(name($parse))
let $result:= if(exists($action))
then $action($parse,$state)

View file

@ -52,7 +52,7 @@ as map(*)?
{
let $doc:=$json?params?textDocument?uri
let $context:=$json?params?context (:{"triggerCharacter":":","triggerKind":2.0e0}:)
let $result:=comp:dummy($context)
let $result:=comp:list($context)
return rpc:result($json,array:build($result))
};

View file

@ -1,22 +1,28 @@
module namespace comp = 'lsp-completions';
import module namespace lspt = 'lsp-typedefs' at "../lsp-typedefs.xqm";
import module namespace ctx="lsp/context" at "../context.xqm";
(: (:{"triggerCharacter":":","triggerKind":2.0e0}:):)
declare function comp:list($context as map(*))
as lspt:CompletionItem*{
as lspt:CompletionItem*
{
message($context,"context: "),
(1 to 20)!lspt:CompletionItem("item"||.,.)
ctx:functions("fn")!ctx:map(.)=>trace("aaa")
};
declare function comp:dummy($context as map(*))
as lspt:CompletionItem*{
as lspt:CompletionItem*
{
message($context,"context: "),
map:for-each(
$lspt:CompletionItemKindMap,
fn($k,$v){
let $d:=lspt:MarkupContent(
'markdown',
'[path](https://quodatum.github.io/basex-xqparse/i-BaseX.xhtml#EQName)'
`More about
<a href="https://quodatum.github.io/basex-xqparse/i-BaseX.xhtml#EQName" target="_blank">{$k}</a>
`
)
return lspt:CompletionItem($k,$v,detail:="detail",documentation:=$d)
})

View file

@ -19,6 +19,7 @@ as lspt:DocumentSymbol*{
return $result?result
};
(: for testing only:)
declare function syms:dummy($parse as element(),$text as xs:string )
as lspt:DocumentSymbol*{
let $fr:=(pos:full-range($text),message("dummy"))
@ -38,7 +39,7 @@ as hnd:Result{
declare function syms:VarDecl($parse as element(VarDecl),$state as hnd:Result )
as hnd:Result{
let $name:=$parse/VarNameAndType/EQName
let $name:=syms:localName($parse/VarNameAndType/EQName)
let $length:=string($parse)=>string-length()
let $range:=lspt:Range(lspt:Position(0,0),lspt:Position(0,3))
let $sym:=lspt:DocumentSymbol($name,$lspt:SymbolKindMap('Variable'),$range,$range,"TODO")
@ -47,11 +48,17 @@ as hnd:Result{
declare function syms:FunctionDecl($parse as element(FunctionDecl),$state as hnd:Result )
as hnd:Result{
let $name:=$parse/UnreservedFunctionEQName
let $name:=syms:localName($parse/UnreservedFunctionEQName)
let $range:=lspt:Range(lspt:Position(0,0),lspt:Position(0,3))
let $sym:=lspt:DocumentSymbol($name,$lspt:SymbolKindMap('Method'),$range,$range,"TODO")
return ($state?result,$sym)=>hnd:Result(true())
};
declare function syms:localName($name as xs:string )
as xs:string{
if(starts-with($name,"Q{"))
then substring-after($name,"}")
else if(contains($name,":"))
then substring-after($name,":")
else $name
};

View file

@ -6,7 +6,7 @@ declare function hov:list($uri, $pos as map(*))
as xs:string*{
let $word:="TODO"
return `Hover { pos:ln-col($pos) }, uri: {$uri},
[path](https://quodatum.github.io/basex-xqparse/i-BaseX.xhtml#EQName)
<a href="https://quodatum.github.io/basex-xqparse/i-BaseX.xhtml#EQName" target="_blank">Path</a>
WordAt: {$word}`
};

View file

@ -31,32 +31,32 @@
<li class="nav-item">
<a class="nav-link" href="/dba/logs" target="dba">Dba</a>
</li>
</ul>
<select id="load">
<option selected value="">load..</option>
<optgroup label="XQuery3">
<option
value="https://raw.githubusercontent.com/expkg-zone58/pdfbox/refs/heads/main/src/Pdfbox3.xqm">
Pdfbox3.xqm</option>
<option
value="https://raw.githubusercontent.com/Quodatum/xqdoca/refs/heads/master/src/main/lib/model.xqm">
model.xqm</option>
</optgroup>
<optgroup label="XQuery4">
<option
value="https://git.quodatum.duckdns.org/quodatum/basex-lsp/raw/branch/main/webapp/lsp/lsp-text.xqm">
lsp-text.xqm</option>
<option value="../../../lsp/lsp-text.xqm">
lsp-text.xqm</option>
</optgroup>
<optgroup label="xpath">
<option
value="https://raw.githubusercontent.com/dnovatchev/Articles/refs/heads/main/Generators/Code/generator.xq">
generator.xquery</option>
</optgroup>
</select>
</ul>
<select id="load">
<option selected value="">load..</option>
<optgroup label="XQuery3">
<option
value="https://raw.githubusercontent.com/expkg-zone58/pdfbox/refs/heads/main/src/Pdfbox3.xqm">
Pdfbox3.xqm</option>
<option
value="https://raw.githubusercontent.com/Quodatum/xqdoca/refs/heads/master/src/main/lib/model.xqm">
model.xqm</option>
</optgroup>
<optgroup label="XQuery4">
<option
value="https://git.quodatum.duckdns.org/quodatum/basex-lsp/raw/branch/main/webapp/lsp/lsp-text.xqm">
lsp-text.xqm</option>
<option value="../../../lsp/lsp-text.xqm">
lsp-text.xqm</option>
</optgroup>
<optgroup label="xpath">
<option
value="https://raw.githubusercontent.com/dnovatchev/Articles/refs/heads/main/Generators/Code/generator.xq">
generator.xquery</option>
</optgroup>
</select>
</div>
</nav>
</header>
@ -98,9 +98,7 @@
<button id="syntax" type="button" class="btn btn-light" title="Unused"><i
class="codicon codicon-comment"></i></button>
<button id="cmd" type="button" class="btn btn-light" title="Cmd list to console">
<i class="codicon codicon-debug-console"></i>
</button>
<button id="wordAt" type="button" class="btn btn-light" title="word at">
<i>1</i></button>
@ -121,7 +119,7 @@
<details id="workspacePanel" open="open">
<summary class='bg-info'>Workspace <b>0</b></summary>
<ul id="traffic" style="overflow: scroll;">
<li>-</li>
@ -130,7 +128,7 @@
<details id="symPanel">
<summary>OutLine <b>0</b></summary>
<json-list id="symList"></json-list>
<qd-list id="symList"></qd-list>
</details>
<details id="msgPanel">
@ -147,14 +145,17 @@
<option value="xml">xml</option>
</select>
<button popovertarget="popHelp"><i class="codicon codicon-info"></i></button>
<button id="cmd" type="button" class="btn btn-light" title="Command and key mapping help">
<i class="codicon codicon-record-keys"></i>
</button>
</footer>
</div>
<!-- Popovers -->
<dialog id="popConnect" popover>
<form>
<header>Connect to LSP
<button type="button" class="btn-close" aria-label="Close"
onclick="$('popConnect').hidePopover(); "></button>
<button type="button" class="btn-close" aria-label="Close"
onclick="$('popConnect').hidePopover(); "></button>
</header>
<div class="modal-body">
<div id="state">🔴</div>
@ -166,17 +167,17 @@
</form>
</dialog>
<dialog id="popHelp" popover>
<dialog id="popHelp" popover>
<form>
<header>Commands and keys
<button type="button" class="btn-close" aria-label="Close"
onclick="$('popHelp').hidePopover(); "></button>
<button type="button" class="btn-close" aria-label="Close"
onclick="$('popHelp').hidePopover(); "></button>
</header>
<div id="popHelpInfo" class="modal-body" style="height: 50vh;overflow:scroll;">
TODO
</div>
<div class="modal-footer">
</div>
</form>
</dialog>
@ -186,7 +187,7 @@
<dialog id="popSettings" popover>
<form id="fSettings">
<header>Editor configuration
<button type="button" class="btn-close" aria-label="Close"
<button type="button" class="btn-close" aria-label="Close"
onclick="$('popSettings').hidePopover(); "></button>
</header>
<div class="modal-body">
@ -208,7 +209,7 @@
<!-- CodeMirror 6 -->
<script src="./lsp.bundle.js"></script>
<script src="./script.js"></script>
<script src="./list.js"></script>
<script src="./wc-qd-list.js"></script>
</body>

View file

@ -83,4 +83,4 @@ class ListComponent extends HTMLElement {
}
/* Define the new custom element */
customElements.define('json-list', ListComponent);
customElements.define('qd-list', ListComponent);