xq-lsp 1.8.2 → 1.8.3-next.430

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.
@@ -2,6 +2,53 @@ import type { Node } from "xq-parser";
2
2
  import type { XQueryType, TypeDiagnostic, FileAnalysis, FunctionSymbol } from "./types.ts";
3
3
  export declare function parseType(typeStr: string): XQueryType;
4
4
  export declare function isAssignable(from: XQueryType, to: XQueryType): boolean;
5
+ /** The type of a single item of `t` — e.g. what a `for` variable over `t` holds. */
6
+ export declare function itemTypeOf(t: XQueryType): XQueryType;
7
+ /** Type of an expression that yields either `a` or `b` (if/else, switch, typeswitch, try/catch). */
8
+ export declare function choiceType(a: XQueryType, b: XQueryType): XQueryType;
9
+ /** Type of the sequence `(a, b)`. */
10
+ export declare function concatType(a: XQueryType, b: XQueryType): XQueryType;
11
+ /** Finds the declaration a call with `argCount` arguments resolves to, honouring variadic functions. */
12
+ export declare function resolveFunction(qname: {
13
+ namespaceUri: string;
14
+ localName: string;
15
+ }, argCount: number, allFns: FunctionSymbol[]): FunctionSymbol | undefined;
16
+ /**
17
+ * Lets callers observe the sub-expressions a scoped construct evaluates (with the scope
18
+ * they're evaluated in) and the bindings it introduces. `binding` fires only for bindings
19
+ * without a declared type — those are the ones whose type is inferred.
20
+ */
21
+ export interface ScopeVisitor {
22
+ expr?(node: Node, scope: Map<string, XQueryType>): void;
23
+ binding?(nameNode: Node, type: XQueryType): void;
24
+ }
5
25
  export declare function inferExprType(node: Node, varTypes: Map<string, XQueryType>, analysis: FileAnalysis, allFns: FunctionSymbol[]): XQueryType;
6
26
  export declare function formatType(t: XQueryType): string;
7
- export declare function checkTypes(ast: Node, text: string, analysis: FileAnalysis, importedAnalyses: Map<string, FileAnalysis>): TypeDiagnostic[];
27
+ export interface ScopeWalkHooks {
28
+ /** Called for every non-terminal, with the variable types in scope at that point. */
29
+ onNode?(node: Node, scope: Map<string, XQueryType>): void;
30
+ /** Called for every variable binding without a declared type, with its inferred type. */
31
+ onBinding?(nameNode: Node, type: XQueryType): void;
32
+ }
33
+ /**
34
+ * Fills in `returnType` for functions in this module declared without `as …`, inferred from
35
+ * their bodies. Iterates to a fixpoint (bounded) so functions calling other untyped functions,
36
+ * declared before or after them, resolve too; directly recursive functions stay unknown unless
37
+ * a non-recursive branch alone determines the type. Callers use the returned list in place of
38
+ * `allFns` so every call site — hints and type checks alike — sees the inferred types.
39
+ */
40
+ export declare function withInferredReturnTypes(ast: Node, analysis: FileAnalysis, allFns: FunctionSymbol[], outerScope?: Map<string, XQueryType>): FunctionSymbol[];
41
+ /**
42
+ * Types of variables visible in this module without being declared in its source: variables
43
+ * of imported modules and runtime-predeclared ones. A declared `as` type is used as written;
44
+ * an untyped imported variable is inferred from its initializer when that module's AST is at
45
+ * hand (it isn't for lightweight glob summaries).
46
+ */
47
+ export declare function externalVariableTypes(analysis: FileAnalysis, imported: Iterable<FileAnalysis>, allFns: FunctionSymbol[]): Map<string, XQueryType>;
48
+ /**
49
+ * Walks a whole module with lexically correct variable scopes: module variables (declared or
50
+ * inferred, in declaration order), function parameters inside each function body, and
51
+ * FLWOR / quantified / typeswitch / inline-function bindings within their own sub-trees.
52
+ */
53
+ export declare function walkModuleScopes(ast: Node, analysis: FileAnalysis, allFns: FunctionSymbol[], hooks: ScopeWalkHooks, outerScope?: Map<string, XQueryType>): void;
54
+ export declare function checkTypes(ast: Node, _text: string, analysis: FileAnalysis, importedAnalyses: Map<string, FileAnalysis>): TypeDiagnostic[];