[add] fn completion
This commit is contained in:
parent
9894581d19
commit
24082ad97b
15 changed files with 123 additions and 56 deletions
47
webapp/lsp/context.xqm
Normal file
47
webapp/lsp/context.xqm
Normal 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
|
||||
)
|
||||
};
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"hoverProvider": false,
|
||||
"hoverProvider": true,
|
||||
"documentSymbolProvider": true,
|
||||
"documentRangeFormattingProvider": false,
|
||||
"colorProvider": false,
|
||||
|
|
|
|||
35785
webapp/lsp/etc/function-catalog.xml
Normal file
35785
webapp/lsp/etc/function-catalog.xml
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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}`
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue