From 47b49c36f4c9fedba22ad0fbf7d649979c233258 Mon Sep 17 00:00:00 2001 From: Andy Bunce Date: Fri, 12 Sep 2025 22:52:50 +0100 Subject: [PATCH] [add] symbols --- webapp/lsp/documentSymbols.xqm | 64 ++++++++++++++++++++++++++++++++++ webapp/lsp/lsp-text.xqm | 12 +++---- 2 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 webapp/lsp/documentSymbols.xqm diff --git a/webapp/lsp/documentSymbols.xqm b/webapp/lsp/documentSymbols.xqm new file mode 100644 index 0000000..3458f1f --- /dev/null +++ b/webapp/lsp/documentSymbols.xqm @@ -0,0 +1,64 @@ +xquery version '4.0'; +(:~ Symbols from XQuery source file :) +module namespace syms="lsp/symbols"; +import module namespace pos="lsp/position" at "position.xqm"; +declare type syms:SymbolKind as xs:integer; +declare type syms:SymbolTag as xs:string; + +declare variable $syms:SymbolKindMap :={ + 'File': 1 , + 'Module': 2 , + 'Namespace': 3 , + 'Package': 4 , + 'Class': 5 , + 'Method': 6 , + 'Property': 7 , + 'Field': 8 , + 'Constructor': 9 , + 'Enum': 10 , + 'Interface': 11 , + 'Function': 12 , + 'Variable': 13 , + 'Constant': 14 , + 'String': 15 , + 'Number': 16 , + 'Boolean': 17 , + 'Array': 18 , + 'Object': 19 , + 'Key': 20 , + 'Null': 21 , + 'EnumMember': 22 , + 'Struct': 23 , + 'Event': 24 , + 'Operator': 25 , + 'TypeParameter': 26 +}; + +declare record syms:DocumentSymbol( +(: The name of this symbol. Will be displayed in the user interface and +therefore must not be an empty string or a string only consisting of white spaces. +:) + name as xs:string, + +(: The kind of this symbol. :) + kind as syms:SymbolKind, + +(: + * The range enclosing this symbol not including leading/trailing whitespace + * but everything else like comments. This information is typically used to + * determine if the clients cursor is inside the symbol to reveal it in the + * UI. :) + range as pos:Range, + +(:The range that should be selected and revealed when this symbol is being + * picked, e.g. the name of a function. Must be contained by the `range`. :) + selectionRange as pos:Range, +(: More detail for this symbol, e.g the signature of a function.:) + detail? as xs:string, + +(: Tags for this document symbol. @since 3.16.0 :) + tags? as syms:SymbolTag*, + +(: Children of this symbol, e.g. properties of a class. :) + children? as syms:DocumentSymbol* +); \ No newline at end of file diff --git a/webapp/lsp/lsp-text.xqm b/webapp/lsp/lsp-text.xqm index 5a1c05a..e2f3103 100644 --- a/webapp/lsp/lsp-text.xqm +++ b/webapp/lsp/lsp-text.xqm @@ -57,13 +57,11 @@ as map(*)? return if($xml/self::ERROR) then rpc:error("Syntax errors found.",$json) else - let $xml:=$xml update {lsp-text:tidy(.)} - let $fmt:=`(: formatting to do :) - ` - return rpc:result([{ - "range":pos:full-range($text), - "newText": $fmt || string($xml) - }],$json) + let $xml:=$xml update {lsp-text:tidy(.)} + return rpc:result([{ + "range":pos:full-range($text), + "newText": string($xml) + }],$json) }; (:~ didOpen method response :)