xq-lsp 1.8.0 → 1.8.2
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/CHANGELOG.md +15 -0
- package/dist/call-hierarchy.d.ts +2 -2
- package/dist/call-hierarchy.js +26 -11
- package/dist/code-lens.d.ts +2 -2
- package/dist/code-lens.js +2 -2
- package/dist/completion.js +14 -0
- package/dist/references.d.ts +13 -3
- package/dist/references.js +24 -14
- package/dist/runtimes/existdb/file.xq +53 -0
- package/dist/runtimes/existdb/request.xq +16 -0
- package/dist/runtimes/existdb/response.xq +57 -4
- package/dist/runtimes/existdb/scheduler.xq +173 -0
- package/dist/runtimes/existdb/system.xq +23 -5
- package/dist/runtimes/existdb/util.xq +91 -12
- package/dist/runtimes/existdb/xmldb.xq +12 -1
- package/dist/server.js +66 -34
- package/package.json +1 -1
- package/src/call-hierarchy.ts +23 -10
- package/src/code-lens.ts +9 -3
- package/src/completion.ts +15 -0
- package/src/references.ts +32 -9
- package/src/runtimes/existdb/file.xq +53 -0
- package/src/runtimes/existdb/request.xq +16 -0
- package/src/runtimes/existdb/response.xq +57 -4
- package/src/runtimes/existdb/scheduler.xq +173 -0
- package/src/runtimes/existdb/system.xq +23 -5
- package/src/runtimes/existdb/util.xq +91 -12
- package/src/runtimes/existdb/xmldb.xq +12 -1
- package/src/server.ts +69 -48
|
@@ -57,15 +57,21 @@ declare function system:enable-tracing($enable as xs:boolean) as empty-sequence(
|
|
|
57
57
|
declare function system:enable-tracing($enable as xs:boolean, $tracelog as xs:boolean) as empty-sequence() external;
|
|
58
58
|
|
|
59
59
|
(:~
|
|
60
|
+
: @param $dir This is an absolute path to where the backup will be written. Must be writeable by the eXist process.
|
|
61
|
+
: @param $incremental Flag to do incremental export.
|
|
62
|
+
: @param $zip Flag to do export to zip file.
|
|
60
63
|
: @return the export results
|
|
61
64
|
:)
|
|
62
|
-
declare function system:export() as node() external;
|
|
65
|
+
declare function system:export($dir as xs:string, $incremental as xs:boolean?, $zip as xs:boolean?) as node() external;
|
|
63
66
|
|
|
64
67
|
(:~
|
|
65
68
|
: Messagers from exporter reroute to logs.
|
|
69
|
+
: @param $dir This is an absolute path to where the backup will be written. Must be writeable by the eXist process.
|
|
70
|
+
: @param $incremental Flag to do incremental export.
|
|
71
|
+
: @param $zip Flag to do export to zip file.
|
|
66
72
|
: @return the export results
|
|
67
73
|
:)
|
|
68
|
-
declare function system:export-silently() as xs:boolean external;
|
|
74
|
+
declare function system:export-silently($dir as xs:string, $incremental as xs:boolean?, $zip as xs:boolean?) as xs:boolean external;
|
|
69
75
|
|
|
70
76
|
(:~
|
|
71
77
|
: A pseudo-function to execute a function as a different user. The first
|
|
@@ -187,17 +193,29 @@ declare function system:get-uptime() as xs:dayTimeDuration external;
|
|
|
187
193
|
:)
|
|
188
194
|
declare function system:get-version() as xs:string external;
|
|
189
195
|
|
|
190
|
-
|
|
196
|
+
(:~
|
|
197
|
+
: @param $admin-pass The password for the admin user
|
|
198
|
+
: @param $new-admin-pass Set the admin password to this new password.
|
|
199
|
+
:)
|
|
200
|
+
declare function system:import($dir-or-file as xs:string, $admin-pass as xs:string?, $new-admin-pass as xs:string?) as item()* external;
|
|
191
201
|
|
|
192
202
|
(:~
|
|
193
203
|
: Messagers from exporter reroute to logs.
|
|
204
|
+
: @param $admin-pass The password for the admin user
|
|
205
|
+
: @param $new-admin-pass Set the admin password to this new password.
|
|
206
|
+
:)
|
|
207
|
+
declare function system:import-silently($dir-or-file as xs:string, $admin-pass as xs:string?, $new-admin-pass as xs:string?) as item()* external;
|
|
208
|
+
|
|
209
|
+
(:~
|
|
210
|
+
: Kill a running XQuey (dba role only).
|
|
194
211
|
:)
|
|
195
|
-
declare function system:
|
|
212
|
+
declare function system:kill-running-xquery($xquery-id as xs:integer) as empty-sequence() external;
|
|
196
213
|
|
|
197
214
|
(:~
|
|
198
215
|
: Kill a running XQuey (dba role only).
|
|
216
|
+
: @param $wait-time The wait time in milliseconds before terminating the XQuery
|
|
199
217
|
:)
|
|
200
|
-
declare function system:kill-running-xquery() as empty-sequence() external;
|
|
218
|
+
declare function system:kill-running-xquery($xquery-id as xs:integer, $wait-time as xs:long) as empty-sequence() external;
|
|
201
219
|
|
|
202
220
|
(:~
|
|
203
221
|
: Restore the database or a section of the database (admin user only).
|
|
@@ -14,8 +14,10 @@ declare function util:absolute-resource-id($node-or-path as item()) as xs:intege
|
|
|
14
14
|
|
|
15
15
|
(:~
|
|
16
16
|
: Converts the number $number from base $base to xs:integer.
|
|
17
|
+
: @param $number The number to convert
|
|
18
|
+
: @param $base The base of $number
|
|
17
19
|
:)
|
|
18
|
-
declare function util:base-to-integer() as item()* external;
|
|
20
|
+
declare function util:base-to-integer($number as item(), $base as xs:integer) as item()* external;
|
|
19
21
|
|
|
20
22
|
(:~
|
|
21
23
|
: Decode the given Base64 encoded string back to clear text
|
|
@@ -409,8 +411,10 @@ declare function util:expand($node as node()*, $serialization-parameters as xs:s
|
|
|
409
411
|
: name and arity, an error is thrown. Please note: the arguments to this
|
|
410
412
|
: function have to be literals or need to be resolvable at compile time at
|
|
411
413
|
: least.
|
|
414
|
+
: @param $name The name of the function
|
|
415
|
+
: @param $arity The arity of the function
|
|
412
416
|
:)
|
|
413
|
-
declare function util:function() as item()* external;
|
|
417
|
+
declare function util:function($name as xs:QName, $arity as xs:integer) as item()* external;
|
|
414
418
|
|
|
415
419
|
(:~
|
|
416
420
|
: Serializes an XML fragment or a sequence of nodes between two elements
|
|
@@ -442,9 +446,10 @@ declare function util:get-fragment-between(
|
|
|
442
446
|
(:~
|
|
443
447
|
: Returns a short description of the module identified by the namespace URI.
|
|
444
448
|
: @deprecated Use inspect:inspect-module-uri#1 instead!
|
|
449
|
+
: @param $namespace-uri The namespace URI of the module
|
|
445
450
|
: @return the description of the active function module identified by the namespace URI
|
|
446
451
|
:)
|
|
447
|
-
declare function util:get-module-description() as xs:string+ external;
|
|
452
|
+
declare function util:get-module-description($namespace-uri as xs:string) as xs:string+ external;
|
|
448
453
|
|
|
449
454
|
(:~
|
|
450
455
|
: Returns an XML fragment providing additional information about the module
|
|
@@ -453,6 +458,15 @@ declare function util:get-module-description() as xs:string+ external;
|
|
|
453
458
|
:)
|
|
454
459
|
declare function util:get-module-info() as element() external;
|
|
455
460
|
|
|
461
|
+
(:~
|
|
462
|
+
: Returns an XML fragment providing additional information about the module
|
|
463
|
+
: identified by the namespace URI.
|
|
464
|
+
: @deprecated Use inspect:inspect-module-uri#1 instead!
|
|
465
|
+
: @param $namespace-uri The namespace URI of the module
|
|
466
|
+
: @return the description of the active function module identified by the namespace URI
|
|
467
|
+
:)
|
|
468
|
+
declare function util:get-module-info($namespace-uri as xs:string) as element() external;
|
|
469
|
+
|
|
456
470
|
(:~
|
|
457
471
|
: Gets the value of a serialization option as set with 'declare option'.
|
|
458
472
|
: @param $name The serialization option name
|
|
@@ -478,8 +492,18 @@ declare function util:get-sequence-type($sequence-type as xs:anyType*) as xs:str
|
|
|
478
492
|
|
|
479
493
|
(:~
|
|
480
494
|
: Calculates a hashcode from a string based on a specified algorithm.
|
|
495
|
+
: @param $message The string to generate the hashcode from
|
|
496
|
+
: @param $algorithm The algorithm used to generate the hashcode
|
|
497
|
+
:)
|
|
498
|
+
declare function util:hash($message as item(), $algorithm as xs:string) as item()* external;
|
|
499
|
+
|
|
500
|
+
(:~
|
|
501
|
+
: Calculates a hashcode from a string based on a specified algorithm.
|
|
502
|
+
: @param $message The string to generate the hashcode from
|
|
503
|
+
: @param $algorithm The algorithm used to generate the hashcode
|
|
504
|
+
: @param $base64flag The flag that specifies whether to return the result as Base64 encoded
|
|
481
505
|
:)
|
|
482
|
-
declare function util:hash() as item()* external;
|
|
506
|
+
declare function util:hash($message as item(), $algorithm as xs:string, $base64flag as xs:boolean) as item()* external;
|
|
483
507
|
|
|
484
508
|
(:~
|
|
485
509
|
: Dynamically imports an XQuery module into the current context. The
|
|
@@ -498,13 +522,33 @@ declare function util:import-module(
|
|
|
498
522
|
|
|
499
523
|
(:~
|
|
500
524
|
: Return the number of documents for an indexed value.
|
|
525
|
+
: @param $nodes The nodes whose content is indexed
|
|
526
|
+
: @param $value The indexed value to search for
|
|
501
527
|
:)
|
|
502
|
-
declare function util:index-key-documents() as item()* external;
|
|
528
|
+
declare function util:index-key-documents($nodes as node()*, $value as xs:anyAtomicType) as item()* external;
|
|
529
|
+
|
|
530
|
+
(:~
|
|
531
|
+
: Return the number of documents for an indexed value.
|
|
532
|
+
: @param $nodes The nodes whose content is indexed
|
|
533
|
+
: @param $value The indexed value to search for
|
|
534
|
+
: @param $index The index in which the search is made
|
|
535
|
+
:)
|
|
536
|
+
declare function util:index-key-documents($nodes as node()*, $value as xs:anyAtomicType, $index as xs:string) as item()* external;
|
|
503
537
|
|
|
504
538
|
(:~
|
|
505
539
|
: Return the number of occurrences for an indexed value.
|
|
540
|
+
: @param $nodes The nodes whose content is indexed
|
|
541
|
+
: @param $value The indexed value to search for
|
|
542
|
+
:)
|
|
543
|
+
declare function util:index-key-occurrences($nodes as node()*, $value as xs:anyAtomicType) as item()* external;
|
|
544
|
+
|
|
545
|
+
(:~
|
|
546
|
+
: Return the number of occurrences for an indexed value.
|
|
547
|
+
: @param $nodes The nodes whose content is indexed
|
|
548
|
+
: @param $value The indexed value to search for
|
|
549
|
+
: @param $index The index in which the search is made
|
|
506
550
|
:)
|
|
507
|
-
declare function util:index-key-occurrences() as item()* external;
|
|
551
|
+
declare function util:index-key-occurrences($nodes as node()*, $value as xs:anyAtomicType, $index as xs:string) as item()* external;
|
|
508
552
|
|
|
509
553
|
(:~
|
|
510
554
|
: Can be used to query existing range indexes defined on a set of nodes. All
|
|
@@ -589,8 +633,10 @@ declare function util:int-to-octal($int as xs:int) as xs:string external;
|
|
|
589
633
|
(:~
|
|
590
634
|
: Converts the xs:integer $number (unsigned) into base $base as xs:string.
|
|
591
635
|
: Bases 2, 8, and 16 are supported.
|
|
636
|
+
: @param $number The number to convert
|
|
637
|
+
: @param $base The base of $number
|
|
592
638
|
:)
|
|
593
|
-
declare function util:integer-to-base() as item()* external;
|
|
639
|
+
declare function util:integer-to-base($number as xs:integer, $base as xs:integer) as item()* external;
|
|
594
640
|
|
|
595
641
|
(:~
|
|
596
642
|
: Checks if the resource identified by $binary-resource is a binary resource.
|
|
@@ -602,16 +648,18 @@ declare function util:is-binary-doc($binary-resource as xs:string?) as xs:boolea
|
|
|
602
648
|
(:~
|
|
603
649
|
: Returns a Boolean value if the module statically mapped to a source location
|
|
604
650
|
: in the configuration file.
|
|
651
|
+
: @param $namespace-uri The namespace URI of the module
|
|
605
652
|
: @return true if the namespace URI is mapped as an active function module
|
|
606
653
|
:)
|
|
607
|
-
declare function util:is-module-mapped() as xs:boolean external;
|
|
654
|
+
declare function util:is-module-mapped($namespace-uri as xs:string) as xs:boolean external;
|
|
608
655
|
|
|
609
656
|
(:~
|
|
610
657
|
: Returns a Boolean value if the module identified by the namespace URI is
|
|
611
658
|
: registered.
|
|
659
|
+
: @param $namespace-uri The namespace URI of the module
|
|
612
660
|
: @return true if the namespace URI is registered as an active function module
|
|
613
661
|
:)
|
|
614
|
-
declare function util:is-module-registered() as xs:boolean external;
|
|
662
|
+
declare function util:is-module-registered($namespace-uri as xs:string) as xs:boolean external;
|
|
615
663
|
|
|
616
664
|
(:~
|
|
617
665
|
: Retrieves the line number of the expression
|
|
@@ -668,12 +716,41 @@ declare function util:list-functions() as function(*)* external;
|
|
|
668
716
|
:)
|
|
669
717
|
declare function util:list-functions($namespace-uri as xs:string) as function(*)* external;
|
|
670
718
|
|
|
719
|
+
(:~
|
|
720
|
+
: Logs the message to the current logger.
|
|
721
|
+
: @param $priority The logging priority: 'error', 'warn', 'debug', 'info', 'trace'
|
|
722
|
+
: @param $message The message to log
|
|
723
|
+
:)
|
|
724
|
+
declare function util:log($priority as xs:string, $message as item()*) as empty-sequence() external;
|
|
725
|
+
|
|
726
|
+
(:~
|
|
727
|
+
: Logs the message to the named logger
|
|
728
|
+
: @param $priority The logging priority: 'error', 'warn', 'debug', 'info', 'trace'
|
|
729
|
+
: @param $logger-name The name of the logger, eg: my.app.log
|
|
730
|
+
: @param $message The message to log
|
|
731
|
+
:)
|
|
732
|
+
declare function util:log-app($priority as xs:string, $logger-name as xs:string, $message as item()*) as empty-sequence() external;
|
|
733
|
+
|
|
734
|
+
(:~
|
|
735
|
+
: Logs the message to System.err.
|
|
736
|
+
: @param $message The message to log
|
|
737
|
+
:)
|
|
738
|
+
declare function util:log-system-err($message as item()*) as empty-sequence() external;
|
|
739
|
+
|
|
740
|
+
(:~
|
|
741
|
+
: Logs the message to System.out.
|
|
742
|
+
: @param $message The message to log
|
|
743
|
+
:)
|
|
744
|
+
declare function util:log-system-out($message as item()*) as empty-sequence() external;
|
|
745
|
+
|
|
671
746
|
(:~
|
|
672
747
|
: Map the module to a source location. This function is only available to the
|
|
673
748
|
: DBA role.
|
|
749
|
+
: @param $namespace-uri The namespace URI of the module
|
|
750
|
+
: @param $location-uri The location URI of the module
|
|
674
751
|
: @return Returns an empty sequence
|
|
675
752
|
:)
|
|
676
|
-
declare function util:map-module() as empty-sequence() external;
|
|
753
|
+
declare function util:map-module($namespace-uri as xs:string, $location-uri as xs:string) as empty-sequence() external;
|
|
677
754
|
|
|
678
755
|
(:~
|
|
679
756
|
: Returns a sequence containing the namespace URIs of all XQuery modules which
|
|
@@ -722,8 +799,9 @@ declare function util:octal-to-int($octal as xs:string) as xs:int external;
|
|
|
722
799
|
: be well-formed XML. It will be passed through the Neko HTML parser to make
|
|
723
800
|
: it well-formed. An empty sequence is returned if the argument is an empty
|
|
724
801
|
: string or sequence.
|
|
802
|
+
: @param $to-be-parsed The string to be parsed
|
|
725
803
|
:)
|
|
726
|
-
declare function util:parse-html() as item()* external;
|
|
804
|
+
declare function util:parse-html($to-be-parsed as xs:string?) as item()* external;
|
|
727
805
|
|
|
728
806
|
(:~
|
|
729
807
|
: Can be used to query existing qname indexes defined on a set of nodes.
|
|
@@ -865,9 +943,10 @@ declare function util:unescape-uri($escaped-string as xs:string, $encoding as xs
|
|
|
865
943
|
(:~
|
|
866
944
|
: Remove relation between module namespace and source location. This function
|
|
867
945
|
: is only available to the DBA role.
|
|
946
|
+
: @param $namespace-uri The namespace URI of the module
|
|
868
947
|
: @return Returns an empty sequence
|
|
869
948
|
:)
|
|
870
|
-
declare function util:unmap-module() as empty-sequence() external;
|
|
949
|
+
declare function util:unmap-module($namespace-uri as xs:string) as empty-sequence() external;
|
|
871
950
|
|
|
872
951
|
(:~
|
|
873
952
|
: Generate a version 4 (random) universally unique identifier (UUID) string,
|
|
@@ -285,8 +285,19 @@ declare function xmldb:match-collection($regexp as xs:string) as xs:string* exte
|
|
|
285
285
|
(:~
|
|
286
286
|
: Moves the collection $source-collection-uri into the collection
|
|
287
287
|
: $target-collection-uri.
|
|
288
|
+
: @param $source-collection-uri The source collection URI
|
|
289
|
+
: @param $target-collection-uri The target collection URI
|
|
290
|
+
:)
|
|
291
|
+
declare function xmldb:move($source-collection-uri as xs:string, $target-collection-uri as xs:string) as empty-sequence() external;
|
|
292
|
+
|
|
293
|
+
(:~
|
|
294
|
+
: Moves the resource $resource from the collection $source-collection-uri into
|
|
295
|
+
: collection $target-collection-uri.
|
|
296
|
+
: @param $source-collection-uri The source collection URI
|
|
297
|
+
: @param $target-collection-uri The target collection URI
|
|
298
|
+
: @param $resource The resource
|
|
288
299
|
:)
|
|
289
|
-
declare function xmldb:move() as empty-sequence() external;
|
|
300
|
+
declare function xmldb:move($source-collection-uri as xs:string, $target-collection-uri as xs:string, $resource as xs:string) as empty-sequence() external;
|
|
290
301
|
|
|
291
302
|
(:~
|
|
292
303
|
: Registers an XMLDB driver class with the XMLDB Database Manager. This is
|
package/dist/server.js
CHANGED
|
@@ -107,6 +107,38 @@ function mergeAnalyses(a, b) {
|
|
|
107
107
|
moduleVariables: [...a.moduleVariables, ...b.moduleVariables],
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
+
// Lightweight (ast-free) per-file records for every glob-matched file: source text plus the
|
|
111
|
+
// *extracted* FileAnalysis (functions, module variables, imports, namespace decls, ...), with
|
|
112
|
+
// the AST itself dropped once those fields are pulled out. xq-parser's AST runs roughly two
|
|
113
|
+
// orders of magnitude larger than the source text — XQuery's operator-precedence grammar wraps
|
|
114
|
+
// even a bare `$x` variable reference in ~30 levels of single-child wrapper nodes, none of them
|
|
115
|
+
// collapsed — so retaining a full AST for every glob-matched file (often hundreds, only a
|
|
116
|
+
// handful of which anyone is actually looking at) is the dominant memory cost of any glob-backed
|
|
117
|
+
// feature. None of the FileAnalysis fields other than `.ast` hold node references (they're all
|
|
118
|
+
// plain offsets/strings — see types.ts), so dropping `.ast` after extraction is safe: nothing
|
|
119
|
+
// downstream keeps the tree reachable. Populated lazily per config dir; never invalidated.
|
|
120
|
+
const globFileSummariesByConfigDir = new Map();
|
|
121
|
+
function buildGlobFileSummaries(config, configDir) {
|
|
122
|
+
const records = new Map();
|
|
123
|
+
for (const filePath of expandGlobs(config.globs, configDir)) {
|
|
124
|
+
const fileUri = pathToFileURL(filePath).toString();
|
|
125
|
+
try {
|
|
126
|
+
const text = fs.readFileSync(filePath, "utf-8");
|
|
127
|
+
const { analysis } = analyzeWithAst(text, fileUri);
|
|
128
|
+
records.set(fileUri, { uri: fileUri, text, analysis: { ...analysis, ast: undefined } });
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
/* unreadable file, skip */
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return records;
|
|
135
|
+
}
|
|
136
|
+
function getGlobFileSummaries(configDir, config) {
|
|
137
|
+
if (!globFileSummariesByConfigDir.has(configDir)) {
|
|
138
|
+
globFileSummariesByConfigDir.set(configDir, buildGlobFileSummaries(config, configDir));
|
|
139
|
+
}
|
|
140
|
+
return globFileSummariesByConfigDir.get(configDir);
|
|
141
|
+
}
|
|
110
142
|
function getGlobAnalyses(currentUri) {
|
|
111
143
|
const found = findConfig(currentUri);
|
|
112
144
|
if (!found)
|
|
@@ -117,43 +149,39 @@ function getGlobAnalyses(currentUri) {
|
|
|
117
149
|
return { byNamespace: globAnalysesByConfigDir.get(configDir), lib };
|
|
118
150
|
}
|
|
119
151
|
const byNamespace = new Map();
|
|
120
|
-
for (const
|
|
121
|
-
|
|
122
|
-
const imported = getImportedAnalysis(fileUri);
|
|
123
|
-
if (!imported?.moduleNamespaceUri)
|
|
152
|
+
for (const { analysis } of getGlobFileSummaries(configDir, config).values()) {
|
|
153
|
+
if (!analysis.moduleNamespaceUri)
|
|
124
154
|
continue;
|
|
125
|
-
const existing = byNamespace.get(
|
|
126
|
-
byNamespace.set(
|
|
155
|
+
const existing = byNamespace.get(analysis.moduleNamespaceUri);
|
|
156
|
+
byNamespace.set(analysis.moduleNamespaceUri, existing ? mergeAnalyses(existing, analysis) : analysis);
|
|
127
157
|
}
|
|
128
158
|
globAnalysesByConfigDir.set(configDir, byNamespace);
|
|
129
159
|
return { byNamespace, lib };
|
|
130
160
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Cross-file access for find-references / rename / call-hierarchy: `getOtherFiles` returns the
|
|
163
|
+
* cached, ast-free summaries above for cheap candidate filtering (see references.ts's text
|
|
164
|
+
* pre-filter); `loadAst` parses one specific candidate's full AST on demand, once it survives
|
|
165
|
+
* that filter, reusing `analysisCache` when the file is already resident (open document, or
|
|
166
|
+
* explicitly imported elsewhere) instead of re-parsing. The parsed result is intentionally NOT
|
|
167
|
+
* cached here — a cross-file search should never retain more than the handful of files it's
|
|
168
|
+
* actually walking.
|
|
169
|
+
*/
|
|
170
|
+
function getGlobFileAccess(currentUri) {
|
|
135
171
|
const found = findConfig(currentUri);
|
|
136
172
|
if (!found)
|
|
137
|
-
return () => [];
|
|
173
|
+
return { getOtherFiles: () => [], loadAst: () => null };
|
|
138
174
|
const { config, configDir } = found;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
/* unreadable file, skip */
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
globFileRecordsByConfigDir.set(configDir, records);
|
|
155
|
-
}
|
|
156
|
-
return [...globFileRecordsByConfigDir.get(configDir).values()];
|
|
175
|
+
const predeclaredNs = getRuntimePredeclaredNamespaces(config.lib);
|
|
176
|
+
return {
|
|
177
|
+
getOtherFiles: () => [...getGlobFileSummaries(configDir, config).values()].map((r) => ({ ...r, analysis: withPredeclaredNs(r.analysis, predeclaredNs) })),
|
|
178
|
+
loadAst: (uri, text) => {
|
|
179
|
+
const cached = analysisCache.get(uri);
|
|
180
|
+
if (cached?.ast)
|
|
181
|
+
return withPredeclaredNs(cached, predeclaredNs);
|
|
182
|
+
const { analysis } = analyzeWithAst(text, uri);
|
|
183
|
+
return withPredeclaredNs(analysis, predeclaredNs);
|
|
184
|
+
},
|
|
157
185
|
};
|
|
158
186
|
}
|
|
159
187
|
function resolveContext(currentUri, rawAnalysis) {
|
|
@@ -324,7 +352,7 @@ connection.onWorkspaceSymbol((params) => {
|
|
|
324
352
|
// No single document anchors a workspace-wide request, so gather config dirs from every open document.
|
|
325
353
|
const filesByUri = new Map();
|
|
326
354
|
for (const doc of documents.all()) {
|
|
327
|
-
for (const file of
|
|
355
|
+
for (const file of getGlobFileAccess(doc.uri).getOtherFiles())
|
|
328
356
|
filesByUri.set(file.uri, file);
|
|
329
357
|
}
|
|
330
358
|
return getWorkspaceSymbols([...filesByUri.values()], params.query);
|
|
@@ -343,7 +371,8 @@ connection.onReferences((params) => {
|
|
|
343
371
|
return [];
|
|
344
372
|
const rawAnalysis = analysisCache.get(doc.uri) ?? analyzeDocument(doc);
|
|
345
373
|
const { analysis } = resolveContext(doc.uri, rawAnalysis);
|
|
346
|
-
|
|
374
|
+
const { getOtherFiles, loadAst } = getGlobFileAccess(doc.uri);
|
|
375
|
+
return getReferences(doc.uri, doc.getText(), doc.offsetAt(params.position), analysis, params.context.includeDeclaration, getOtherFiles, loadAst);
|
|
347
376
|
});
|
|
348
377
|
const NCNAME_RE = /^[A-Za-z_][\w.-]*$/;
|
|
349
378
|
connection.onPrepareRename((params) => {
|
|
@@ -366,7 +395,8 @@ connection.onRenameRequest((params) => {
|
|
|
366
395
|
}
|
|
367
396
|
const rawAnalysis = analysisCache.get(doc.uri) ?? analyzeDocument(doc);
|
|
368
397
|
const { analysis } = resolveContext(doc.uri, rawAnalysis);
|
|
369
|
-
const
|
|
398
|
+
const { getOtherFiles, loadAst } = getGlobFileAccess(doc.uri);
|
|
399
|
+
const locations = getRenameLocations(doc.uri, doc.getText(), doc.offsetAt(params.position), analysis, getOtherFiles, loadAst);
|
|
370
400
|
if (!locations)
|
|
371
401
|
return null;
|
|
372
402
|
const changes = {};
|
|
@@ -408,7 +438,8 @@ connection.onCodeLensResolve((lens) => {
|
|
|
408
438
|
return { ...lens, command: { title: "0 references", command: "" } };
|
|
409
439
|
const rawAnalysis = analysisCache.get(doc.uri) ?? analyzeDocument(doc);
|
|
410
440
|
const { analysis } = resolveContext(doc.uri, rawAnalysis);
|
|
411
|
-
|
|
441
|
+
const { getOtherFiles, loadAst } = getGlobFileAccess(doc.uri);
|
|
442
|
+
return resolveCodeLens(lens, doc.getText(), analysis, getOtherFiles, loadAst);
|
|
412
443
|
});
|
|
413
444
|
connection.onDocumentLinks((params) => {
|
|
414
445
|
const doc = documents.get(params.textDocument.uri);
|
|
@@ -431,7 +462,8 @@ connection.languages.callHierarchy.onIncomingCalls((params) => {
|
|
|
431
462
|
if (!loaded)
|
|
432
463
|
return null;
|
|
433
464
|
const { analysis } = resolveContext(params.item.uri, loaded.analysis);
|
|
434
|
-
|
|
465
|
+
const { getOtherFiles, loadAst } = getGlobFileAccess(params.item.uri);
|
|
466
|
+
return getIncomingCalls(params.item, loaded.text, analysis, getOtherFiles, loadAst);
|
|
435
467
|
});
|
|
436
468
|
connection.languages.callHierarchy.onOutgoingCalls((params) => {
|
|
437
469
|
const loaded = loadAnalysisForUri(params.item.uri);
|
package/package.json
CHANGED
package/src/call-hierarchy.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { findAll, directChildOf, nodeStackAtOffset } from "./analyzer.ts";
|
|
|
10
10
|
import { asFunctionDecl, asFunctionCall } from "./ast-nodes.ts";
|
|
11
11
|
import { resolveFunctionAtOffset, allFunctions } from "./hover-core.ts";
|
|
12
12
|
import { getReferences } from "./references.ts";
|
|
13
|
-
import type { FileRecord } from "./references.ts";
|
|
13
|
+
import type { FileRecord, LoadAst } from "./references.ts";
|
|
14
14
|
|
|
15
15
|
/** Identifies the function a CallHierarchyItem refers to, round-tripped via `item.data`. */
|
|
16
16
|
interface CallHierarchyFunctionData {
|
|
@@ -180,34 +180,47 @@ export function getIncomingCalls(
|
|
|
180
180
|
itemText: string,
|
|
181
181
|
itemAnalysis: FileAnalysis,
|
|
182
182
|
getOtherFiles: () => FileRecord[],
|
|
183
|
+
loadAst: LoadAst,
|
|
183
184
|
): CallHierarchyIncomingCall[] {
|
|
184
185
|
const offset = toOffset(itemText, item.selectionRange.start);
|
|
185
186
|
// includeDeclaration:false — we only want actual call sites, not the declaration itself.
|
|
186
|
-
const callSites = getReferences(item.uri, itemText, offset, itemAnalysis, false, getOtherFiles);
|
|
187
|
+
const callSites = getReferences(item.uri, itemText, offset, itemAnalysis, false, getOtherFiles, loadAst);
|
|
187
188
|
if (callSites.length === 0) return [];
|
|
188
189
|
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
// getOtherFiles() returns cached, ast-free records — cheap to re-iterate for a uri->text
|
|
191
|
+
// lookup. The full (ast-bearing) analysis for each call site's file is fetched below, once
|
|
192
|
+
// per distinct uri, via loadAst.
|
|
193
|
+
const textByUri = new Map<string, string>([[item.uri, itemText]]);
|
|
194
|
+
for (const file of getOtherFiles()) if (!textByUri.has(file.uri)) textByUri.set(file.uri, file.text);
|
|
191
195
|
|
|
196
|
+
const analysisByUri = new Map<string, FileAnalysis>([[item.uri, itemAnalysis]]);
|
|
192
197
|
const groups = new Map<string, { from: CallHierarchyItem; ranges: Range[] }>();
|
|
193
198
|
|
|
194
199
|
for (const loc of callSites) {
|
|
195
|
-
const
|
|
196
|
-
if (
|
|
200
|
+
const text = textByUri.get(loc.uri);
|
|
201
|
+
if (text === undefined) continue;
|
|
202
|
+
let fileAnalysis = analysisByUri.get(loc.uri);
|
|
203
|
+
if (!fileAnalysis) {
|
|
204
|
+
const loaded = loadAst(loc.uri, text);
|
|
205
|
+
if (!loaded) continue;
|
|
206
|
+
fileAnalysis = loaded;
|
|
207
|
+
analysisByUri.set(loc.uri, fileAnalysis);
|
|
208
|
+
}
|
|
209
|
+
if (!fileAnalysis.ast) continue;
|
|
197
210
|
|
|
198
|
-
const callOffset = toOffset(
|
|
199
|
-
const stack = nodeStackAtOffset(
|
|
211
|
+
const callOffset = toOffset(text, loc.range.start);
|
|
212
|
+
const stack = nodeStackAtOffset(fileAnalysis.ast, callOffset);
|
|
200
213
|
// Function declarations can't nest in XQuery, so at most one AnnotatedDecl/FunctionDecl
|
|
201
214
|
// pair appears in the stack; a call at module level (no enclosing function) has none.
|
|
202
215
|
const enclosingDecl = stack.find((n) => n.type === "AnnotatedDecl" && directChildOf(n, "FunctionDecl"));
|
|
203
216
|
if (!enclosingDecl) continue;
|
|
204
|
-
const enclosingFn =
|
|
217
|
+
const enclosingFn = fileAnalysis.functions.find((f) => f.sourceOffset === enclosingDecl.start);
|
|
205
218
|
if (!enclosingFn) continue;
|
|
206
219
|
|
|
207
220
|
const key = `${qnameKey(enclosingFn.qname)}#${enclosingFn.arity}@${loc.uri}`;
|
|
208
221
|
let group = groups.get(key);
|
|
209
222
|
if (!group) {
|
|
210
|
-
const from = buildItemForFunction(enclosingFn,
|
|
223
|
+
const from = buildItemForFunction(enclosingFn, fileAnalysis, loc.uri, text);
|
|
211
224
|
if (!from) continue;
|
|
212
225
|
group = { from, ranges: [] };
|
|
213
226
|
groups.set(key, group);
|
package/src/code-lens.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { FileAnalysis } from "./types.ts";
|
|
|
5
5
|
import { findAll } from "./analyzer.ts";
|
|
6
6
|
import { asFunctionDeclaration, asVarDecl } from "./ast-nodes.ts";
|
|
7
7
|
import { getReferences } from "./references.ts";
|
|
8
|
-
import type { FileRecord } from "./references.ts";
|
|
8
|
+
import type { FileRecord, LoadAst } from "./references.ts";
|
|
9
9
|
|
|
10
10
|
/** Carried on each unresolved lens so `resolveCodeLens` can find the declaration again later. */
|
|
11
11
|
export interface CodeLensData {
|
|
@@ -74,11 +74,17 @@ function findNameOffset(ast: Node, analysis: FileAnalysis, data: CodeLensData):
|
|
|
74
74
|
* reference search `textDocument/references` uses. Declarations aren't counted as
|
|
75
75
|
* references. 0 references is reported as-is — it's a useful signal, not hidden.
|
|
76
76
|
*/
|
|
77
|
-
export function resolveCodeLens(
|
|
77
|
+
export function resolveCodeLens(
|
|
78
|
+
lens: CodeLens,
|
|
79
|
+
text: string,
|
|
80
|
+
analysis: FileAnalysis,
|
|
81
|
+
getOtherFiles: () => FileRecord[],
|
|
82
|
+
loadAst: LoadAst,
|
|
83
|
+
): CodeLens {
|
|
78
84
|
const data = lens.data as CodeLensData | undefined;
|
|
79
85
|
const ast = analysis.ast;
|
|
80
86
|
const offset = data && ast ? findNameOffset(ast, analysis, data) : null;
|
|
81
|
-
const count = data && offset !== null ? getReferences(data.uri, text, offset, analysis, false, getOtherFiles).length : 0;
|
|
87
|
+
const count = data && offset !== null ? getReferences(data.uri, text, offset, analysis, false, getOtherFiles, loadAst).length : 0;
|
|
82
88
|
|
|
83
89
|
return { ...lens, command: { title: `${count} references`, command: "" } };
|
|
84
90
|
}
|
package/src/completion.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { FileAnalysis } from "./types.ts";
|
|
|
3
3
|
import { getCompletions as getCoreCompletions } from "./completion-core.ts";
|
|
4
4
|
import type { CompletionContext } from "./completion-core.ts";
|
|
5
5
|
import { findImportInsertPosition, findDeclareNsInsertPosition, computeRelativePath } from "./namespace-diagnostics.ts";
|
|
6
|
+
import { offsetToPosition } from "./references.ts";
|
|
6
7
|
|
|
7
8
|
export type { CompletionContext } from "./completion-core.ts";
|
|
8
9
|
|
|
@@ -53,6 +54,20 @@ export function getCompletions(
|
|
|
53
54
|
newText = `declare namespace ${e.additionalEdit.prefix} = "${e.additionalEdit.namespaceUri}";\n`;
|
|
54
55
|
}
|
|
55
56
|
item.additionalTextEdits = [{ range: { start: insertPos, end: insertPos }, newText }];
|
|
57
|
+
|
|
58
|
+
// The "declare namespace" entry's own insertText is just an echo of what's already
|
|
59
|
+
// typed after the prefix (often ""). Some clients (e.g. eglot) fall back to inserting
|
|
60
|
+
// the item's label verbatim at the cursor when insertText is empty, which would dump
|
|
61
|
+
// the whole `declare namespace tei = "...";` statement inline. An explicit textEdit
|
|
62
|
+
// with a concrete range forces every spec-compliant client onto the deterministic
|
|
63
|
+
// replace path instead of guessing, so only the additionalTextEdit above lands the text.
|
|
64
|
+
if (e.additionalEdit.kind === "declare-namespace") {
|
|
65
|
+
const start = ctx.cursorOffset - e.insertText.length;
|
|
66
|
+
item.textEdit = {
|
|
67
|
+
range: { start: offsetToPosition(docText, start), end: offsetToPosition(docText, ctx.cursorOffset) },
|
|
68
|
+
newText: e.insertText,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
return item;
|