[add] symbols
This commit is contained in:
parent
f867836ddf
commit
3465a751bb
4 changed files with 61 additions and 21 deletions
6
test/symbols.xq
Normal file
6
test/symbols.xq
Normal file
|
@ -0,0 +1,6 @@
|
|||
import module namespace hnd="lsp/handlers" at "../webapp/lsp/handlers.xqm";
|
||||
declare variable $src:="sample.docs/parse-pdfbox.xml";
|
||||
declare variable $parse:=doc($src)/*;
|
||||
|
||||
|
||||
hnd:symbols($parse )
|
|
@ -3,11 +3,9 @@
|
|||
:)
|
||||
module namespace hnd="lsp/handlers";
|
||||
import module namespace lspt = 'lsp-typedefs' at "lsp-typedefs.xqm";
|
||||
declare variable hnd:actions:={
|
||||
|
||||
}
|
||||
|
||||
declare record hnd:Hand(
|
||||
declare record hnd:Result(
|
||||
result as item()*,
|
||||
skipchildren? as xs:boolean:=false()
|
||||
);
|
||||
|
@ -15,9 +13,8 @@ declare record hnd:Hand(
|
|||
|
||||
declare function hnd:handle($el as element(*),$state)
|
||||
{
|
||||
|
||||
let $f:= function-lookup(xs:QName(name($el)=>trace("SSS")),2)
|
||||
otherwise fn($el,$state){hnd:Hand($state,false())}
|
||||
otherwise fn($el,$state){hnd:Result($state,false())}
|
||||
return $f($el,$state)
|
||||
};
|
||||
|
||||
|
@ -34,20 +31,57 @@ declare function hnd:diags($parse as element(),$diags:=())
|
|||
})
|
||||
};
|
||||
|
||||
declare function hnd:walk($parse as element(),
|
||||
$actions as map(*),
|
||||
$state as hnd:Result )
|
||||
as hnd:Result{
|
||||
|
||||
let $action:=$actions(name($parse))
|
||||
let $result:= if(exists($action))
|
||||
then $action($parse,$state)
|
||||
else hnd:Result($state)
|
||||
|
||||
declare function hnd:symbols($parse as element(),$syms as lspt:symbol* :=() )
|
||||
{
|
||||
'todo'
|
||||
return if($result?skipchildren)
|
||||
then $result
|
||||
else fold-left(
|
||||
$parse/*,$state,
|
||||
fn($state,$this){hnd:walk($this, $actions, $state)}
|
||||
)
|
||||
};
|
||||
|
||||
declare function hnd:anotated-declaration($parse as element(),$syms)
|
||||
as hnd:Hand
|
||||
|
||||
|
||||
declare function hnd:symbols($parse as element(),$syms as lspt:DocumentSymbol* :=() )
|
||||
{
|
||||
let $sym:=lspt:symbol(
|
||||
$parse/token,
|
||||
"AA"
|
||||
)
|
||||
return hnd:Hand(($syms,$sym),true())
|
||||
let $actions:={
|
||||
"ContextValueDecl": hnd:action#2,
|
||||
"VarDecl": hnd:VarDecl#2,
|
||||
"FunctionDecl": hnd:FunctionDecl#2,
|
||||
"ItemTypeDecl": hnd:action#2,
|
||||
"NamedRecordTypeDecl": hnd:action#2
|
||||
}
|
||||
let $state:= hnd:Result(())
|
||||
let $result:= hnd:walk($parse,$actions,$state)
|
||||
return $result?result
|
||||
};
|
||||
|
||||
declare function hnd:action($parse as element(),$state as hnd:Result )
|
||||
as hnd:Result{
|
||||
hnd:Result($state?result,true()) ,message(name($parse),"ACTION: ")
|
||||
};
|
||||
|
||||
declare function hnd:VarDecl($parse as element(VarDecl),$state as hnd:Result )
|
||||
as hnd:Result{
|
||||
let $name:=$parse/VarNameAndType/EQName
|
||||
let $range:=lspt:Range(lspt:Position(0,0),lspt:Position(0,3))
|
||||
let $sym:=lspt:DocumentSymbol($name,$lspt:SymbolKindMap('Variable'),$range,$range,"TODO")
|
||||
return ($state?result,$sym)=>hnd:Result(true())
|
||||
};
|
||||
|
||||
declare function hnd:FunctionDecl($parse as element(FunctionDecl),$state as hnd:Result )
|
||||
as hnd:Result{
|
||||
let $name:=$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())
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ as map(*)*{
|
|||
let $e:= number($xml/@e)-1
|
||||
return (
|
||||
(: mark error :)
|
||||
lspt:diagnostic(lspt:Range(pos:toPosition($text, $b),
|
||||
lspt:Diagnostic(lspt:Range(pos:toPosition($text, $b),
|
||||
pos:toPosition($text, $e)),
|
||||
1,
|
||||
$dmesg,'XPST0003'),
|
||||
|
@ -56,7 +56,7 @@ as map(*)*{
|
|||
(:mark after error:)
|
||||
if($e ge string-length($text))
|
||||
then ()
|
||||
else lspt:diagnostic(lspt:Range(pos:toPosition($text, $e +1 ),
|
||||
else lspt:Diagnostic(lspt:Range(pos:toPosition($text, $e +1 ),
|
||||
pos:toPosition($text, $last)),
|
||||
2,
|
||||
"Unparsed due to previous parser error.",
|
||||
|
|
|
@ -101,7 +101,7 @@ declare variable $lspt:DiagnosticSeverityKinds:={
|
|||
'hint':4
|
||||
};
|
||||
|
||||
declare record lspt:diagnostic(
|
||||
declare record lspt:Diagnostic(
|
||||
range as lspt:Range,
|
||||
severity as xs:integer, (: enum('error', 'hint', 'info', 'warning') :)
|
||||
message as xs:string,
|
||||
|
|
Loading…
Add table
Reference in a new issue