xq-lsp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -0
- package/builtins/builtins-array.xq +160 -0
- package/builtins/builtins-fn.xq +1100 -0
- package/builtins/builtins-map.xq +86 -0
- package/builtins/builtins-math.xq +100 -0
- package/dist/analyzer.d.ts +14 -0
- package/dist/analyzer.js +363 -0
- package/dist/builtins.d.ts +2 -0
- package/dist/builtins.js +28 -0
- package/dist/completion.d.ts +9 -0
- package/dist/completion.js +152 -0
- package/dist/features.d.ts +8 -0
- package/dist/features.js +214 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +145 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +0 -0
- package/package.json +29 -0
- package/src/analyzer.ts +402 -0
- package/src/builtins.ts +33 -0
- package/src/completion.ts +179 -0
- package/src/features.ts +260 -0
- package/src/server.ts +165 -0
- package/src/types.ts +47 -0
- package/tsconfig.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# xq-lsp
|
|
2
|
+
|
|
3
|
+
Language Server Protocol implementation for XQuery, providing autocompletion, hover documentation, signature help, go-to-definition, and diagnostics.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Completion** — functions declared in the current file, imported modules, and variables in scope
|
|
8
|
+
- **Hover** — function signatures on hover
|
|
9
|
+
- **Signature help** — active parameter hints inside function calls
|
|
10
|
+
- **Go to definition** — jump to function or variable declarations, including across imported files
|
|
11
|
+
- **Document symbols** — file outline of all declared functions and variables
|
|
12
|
+
- **Diagnostics** — syntax errors as you type
|
|
13
|
+
|
|
14
|
+
Imports written as `import module namespace prefix="uri" at "./other-file.xq"` are followed automatically; symbols from imported files are included in completions.
|
|
15
|
+
|
|
16
|
+
For files with syntax errors (common while editing), the server falls back to regex-based extraction so completions keep working.
|
|
17
|
+
|
|
18
|
+
## Emacs
|
|
19
|
+
|
|
20
|
+
### With eglot (built-in since Emacs 29)
|
|
21
|
+
|
|
22
|
+
Install `xquery-mode` from MELPA:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
M-x package-install RET xquery-mode RET
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add to your `init.el`:
|
|
29
|
+
|
|
30
|
+
```elisp
|
|
31
|
+
(with-eval-after-load 'eglot
|
|
32
|
+
(add-to-list 'eglot-server-programs
|
|
33
|
+
'(xquery-mode . ("npx" "xq-lsp" "--stdio"))))
|
|
34
|
+
|
|
35
|
+
(add-hook 'xquery-mode-hook #'eglot-ensure)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Open any `.xq` file and eglot starts the server automatically. Run `M-x eglot` to start it manually.
|
|
39
|
+
|
|
40
|
+
**Key bindings:**
|
|
41
|
+
|
|
42
|
+
| Action | Key |
|
|
43
|
+
|---|---|
|
|
44
|
+
| Completion | `C-M-i` |
|
|
45
|
+
| Hover / docs | `C-c C-d` |
|
|
46
|
+
| Signature help | automatic in minibuffer |
|
|
47
|
+
| Go to definition | `M-.` |
|
|
48
|
+
| Go back | `M-,` |
|
|
49
|
+
| Document symbols | `M-x imenu` |
|
|
50
|
+
| Diagnostics | `M-x flymake-show-buffer-diagnostics` |
|
|
51
|
+
|
|
52
|
+
### With lsp-mode
|
|
53
|
+
|
|
54
|
+
```elisp
|
|
55
|
+
(with-eval-after-load 'lsp-mode
|
|
56
|
+
(add-to-list 'lsp-language-id-configuration '(xquery-mode . "xquery"))
|
|
57
|
+
|
|
58
|
+
(lsp-register-client
|
|
59
|
+
(make-lsp-client
|
|
60
|
+
:new-connection (lsp-stdio-connection '("npx" "xq-lsp" "--stdio"))
|
|
61
|
+
:major-modes '(xquery-mode)
|
|
62
|
+
:language-id "xquery"
|
|
63
|
+
:server-id 'xquery-lsp)))
|
|
64
|
+
|
|
65
|
+
(add-hook 'xquery-mode-hook #'lsp)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## VS Code
|
|
69
|
+
|
|
70
|
+
A minimal VS Code extension lives in [`editors/vscode/`](./editors/vscode/).
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
cd editors/vscode
|
|
74
|
+
npm install
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Open the `editors/vscode` folder in VS Code and press `F5` to launch a development host with the extension active. To install it permanently, package it with [`vsce`](https://github.com/microsoft/vscode-vsce):
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
npx vsce package
|
|
81
|
+
code --install-extension xquery-lsp-vscode-*.vsix
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The extension registers `.xq`, `.xql`, `.xqm`, and `.xqy` files as XQuery and starts `xq-lsp` automatically when you open one.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
module namespace array="http://www.w3.org/2005/xpath-functions/array";
|
|
2
|
+
|
|
3
|
+
(:~
|
|
4
|
+
: Returns the number of members in an array.
|
|
5
|
+
: @param $array The array
|
|
6
|
+
: @return The number of members
|
|
7
|
+
:)
|
|
8
|
+
declare function array:size($array as array(*)) as xs:integer external;
|
|
9
|
+
|
|
10
|
+
(:~
|
|
11
|
+
: Returns the member at a given position.
|
|
12
|
+
: @param $array The array
|
|
13
|
+
: @param $index 1-based position
|
|
14
|
+
: @return The member value
|
|
15
|
+
:)
|
|
16
|
+
declare function array:get($array as array(*), $index as xs:integer) as item()* external;
|
|
17
|
+
|
|
18
|
+
(:~
|
|
19
|
+
: Returns a new array with the member at a given position replaced.
|
|
20
|
+
: @param $array The array
|
|
21
|
+
: @param $index 1-based position
|
|
22
|
+
: @param $member The new value
|
|
23
|
+
: @return A new array with the replacement
|
|
24
|
+
:)
|
|
25
|
+
declare function array:put($array as array(*), $index as xs:integer, $member as item()*) as array(*) external;
|
|
26
|
+
|
|
27
|
+
(:~
|
|
28
|
+
: Returns a new array with an additional member appended.
|
|
29
|
+
: @param $array The array
|
|
30
|
+
: @param $appendage The value to append
|
|
31
|
+
: @return A new array with the value appended
|
|
32
|
+
:)
|
|
33
|
+
declare function array:append($array as array(*), $appendage as item()*) as array(*) external;
|
|
34
|
+
|
|
35
|
+
(:~
|
|
36
|
+
: Returns a subarray starting at a given position.
|
|
37
|
+
: @param $array The array
|
|
38
|
+
: @param $start 1-based start position
|
|
39
|
+
: @return The subarray from $start to the end
|
|
40
|
+
:)
|
|
41
|
+
declare function array:subarray($array as array(*), $start as xs:integer) as array(*) external;
|
|
42
|
+
(:~
|
|
43
|
+
: Returns a subarray of a given length starting at a given position.
|
|
44
|
+
: @param $array The array
|
|
45
|
+
: @param $start 1-based start position
|
|
46
|
+
: @param $length Number of members
|
|
47
|
+
: @return The subarray
|
|
48
|
+
:)
|
|
49
|
+
declare function array:subarray($array as array(*), $start as xs:integer, $length as xs:integer) as array(*) external;
|
|
50
|
+
|
|
51
|
+
(:~
|
|
52
|
+
: Returns a new array with members at given positions removed.
|
|
53
|
+
: @param $array The array
|
|
54
|
+
: @param $positions 1-based positions to remove
|
|
55
|
+
: @return A new array without the specified members
|
|
56
|
+
:)
|
|
57
|
+
declare function array:remove($array as array(*), $positions as xs:integer*) as array(*) external;
|
|
58
|
+
|
|
59
|
+
(:~
|
|
60
|
+
: Returns a new array with a member inserted before a given position.
|
|
61
|
+
: @param $array The array
|
|
62
|
+
: @param $position 1-based insertion point
|
|
63
|
+
: @param $member The value to insert
|
|
64
|
+
: @return A new array with the member inserted
|
|
65
|
+
:)
|
|
66
|
+
declare function array:insert-before($array as array(*), $position as xs:integer, $member as item()*) as array(*) external;
|
|
67
|
+
|
|
68
|
+
(:~
|
|
69
|
+
: Returns the first member of an array.
|
|
70
|
+
: @param $array The array
|
|
71
|
+
: @return The first member value
|
|
72
|
+
:)
|
|
73
|
+
declare function array:head($array as array(*)) as item()* external;
|
|
74
|
+
|
|
75
|
+
(:~
|
|
76
|
+
: Returns an array containing all but the first member.
|
|
77
|
+
: @param $array The array
|
|
78
|
+
: @return A new array without the first member
|
|
79
|
+
:)
|
|
80
|
+
declare function array:tail($array as array(*)) as array(*) external;
|
|
81
|
+
|
|
82
|
+
(:~
|
|
83
|
+
: Returns a new array with members in reverse order.
|
|
84
|
+
: @param $array The array
|
|
85
|
+
: @return The reversed array
|
|
86
|
+
:)
|
|
87
|
+
declare function array:reverse($array as array(*)) as array(*) external;
|
|
88
|
+
|
|
89
|
+
(:~
|
|
90
|
+
: Concatenates arrays into a single array.
|
|
91
|
+
: @param $arrays Sequence of arrays to join
|
|
92
|
+
: @return A single array containing all members
|
|
93
|
+
:)
|
|
94
|
+
declare function array:join($arrays as array(*)*) as array(*) external;
|
|
95
|
+
|
|
96
|
+
(:~
|
|
97
|
+
: Applies a function to each member, returning a new array of results.
|
|
98
|
+
: @param $array The input array
|
|
99
|
+
: @param $action Function to apply to each member
|
|
100
|
+
: @return A new array of results
|
|
101
|
+
:)
|
|
102
|
+
declare function array:for-each($array as array(*), $action as function(item()*) as item()*) as array(*) external;
|
|
103
|
+
|
|
104
|
+
(:~
|
|
105
|
+
: Returns an array of members for which a predicate returns true.
|
|
106
|
+
: @param $array The input array
|
|
107
|
+
: @param $function Predicate function
|
|
108
|
+
: @return A new array of matching members
|
|
109
|
+
:)
|
|
110
|
+
declare function array:filter($array as array(*), $function as function(item()*) as xs:boolean) as array(*) external;
|
|
111
|
+
|
|
112
|
+
(:~
|
|
113
|
+
: Reduces an array to a single value by applying a function from the left.
|
|
114
|
+
: @param $array The input array
|
|
115
|
+
: @param $zero Initial accumulator value
|
|
116
|
+
: @param $f Combining function
|
|
117
|
+
: @return The accumulated result
|
|
118
|
+
:)
|
|
119
|
+
declare function array:fold-left($array as array(*), $zero as item()*, $f as function(item()*, item()*) as item()*) as item()* external;
|
|
120
|
+
|
|
121
|
+
(:~
|
|
122
|
+
: Reduces an array to a single value by applying a function from the right.
|
|
123
|
+
: @param $array The input array
|
|
124
|
+
: @param $zero Initial accumulator value
|
|
125
|
+
: @param $f Combining function
|
|
126
|
+
: @return The accumulated result
|
|
127
|
+
:)
|
|
128
|
+
declare function array:fold-right($array as array(*), $zero as item()*, $f as function(item()*, item()*) as item()*) as item()* external;
|
|
129
|
+
|
|
130
|
+
(:~
|
|
131
|
+
: Applies a function pairwise to members of two arrays.
|
|
132
|
+
: @param $array1 First array
|
|
133
|
+
: @param $array2 Second array
|
|
134
|
+
: @param $f Function to apply to each pair
|
|
135
|
+
: @return A new array of results
|
|
136
|
+
:)
|
|
137
|
+
declare function array:for-each-pair($array1 as array(*), $array2 as array(*), $f as function(item()*, item()*) as item()*) as array(*) external;
|
|
138
|
+
|
|
139
|
+
(:~
|
|
140
|
+
: Sorts the members of an array.
|
|
141
|
+
: @param $array The array to sort
|
|
142
|
+
: @return A new sorted array
|
|
143
|
+
:)
|
|
144
|
+
declare function array:sort($array as array(*)) as array(*) external;
|
|
145
|
+
(:~ @param $array Array @param $collation Collation URI or empty :)
|
|
146
|
+
declare function array:sort($array as array(*), $collation as xs:string?) as array(*) external;
|
|
147
|
+
(:~
|
|
148
|
+
: @param $array Array
|
|
149
|
+
: @param $collation Collation URI or empty
|
|
150
|
+
: @param $key Function to extract the sort key from each member
|
|
151
|
+
: @return A new sorted array
|
|
152
|
+
:)
|
|
153
|
+
declare function array:sort($array as array(*), $collation as xs:string?, $key as function(item()*) as xs:anyAtomicType*) as array(*) external;
|
|
154
|
+
|
|
155
|
+
(:~
|
|
156
|
+
: Flattens nested arrays into a sequence of atomic values and non-array items.
|
|
157
|
+
: @param $input The sequence or array to flatten
|
|
158
|
+
: @return The flattened sequence
|
|
159
|
+
:)
|
|
160
|
+
declare function array:flatten($input as item()*) as item()* external;
|