@g3nomaly/analyze 0.1.6 → 0.1.7

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.
@@ -17,6 +17,14 @@ export declare function nodeId(graph: Graph, node: NodeRef): string;
17
17
  * @returns The id without the file, `#/` or slashes around it, with percent escapes decoded.
18
18
  */
19
19
  export declare function normalizeId(text: string): string;
20
+ /**
21
+ * @brief Finds the path on disk that belongs to a node.
22
+ *
23
+ * @param graph - Graph the node belongs to.
24
+ * @param node - The node to look up.
25
+ * @returns The path of the node itself, else of the file it is in. `null` for a section or a folder.
26
+ */
27
+ export declare function pathOf(graph: Graph, node: NodeRef): string | null;
20
28
  /**
21
29
  * @brief Describes a node in one row: what a search hit, a list row and a reference show.
22
30
  *
@@ -1,8 +1,12 @@
1
- import type { EdgeKind, NodeRef } from '../model';
1
+ import { type EdgeKind, type NodeRef } from '../model';
2
2
  import type { Graph } from '../query';
3
3
  import type { Reference } from './report';
4
4
  /** Most references a walk lists without a limit. */
5
5
  export declare const DEFAULT_WALK_LIMIT = 50;
6
+ /** Levels a walk can follow links at: between pages and entries, or between the files that hold them. */
7
+ export declare const WALK_LEVELS: readonly ['entries', 'files'];
8
+ /** A level a walk follows links at. */
9
+ export type WalkLevel = (typeof WALK_LEVELS)[number];
6
10
  /**
7
11
  * @brief How far a walk of the references of a node goes.
8
12
  *
@@ -10,12 +14,15 @@ export declare const DEFAULT_WALK_LIMIT = 50;
10
14
  * @property kinds - Edge kinds to follow. Empty follows every kind.
11
15
  * @property depth - Hops to follow from the node. 1 lists its own references.
12
16
  * @property limit - Most references to list, both directions and every hop together.
17
+ * @property level - `entries` follows the stored links. `files` follows them between the files that hold their
18
+ * ends, as the file level of the graph page draws them, and starts at the file of the node.
13
19
  */
14
20
  export interface WalkOptions {
15
21
  readonly direction: 'in' | 'out' | 'both';
16
22
  readonly kinds: readonly EdgeKind[];
17
23
  readonly depth: number;
18
24
  readonly limit: number;
25
+ readonly level: WalkLevel;
19
26
  }
20
27
  /**
21
28
  * @brief A reference with the references of its node one hop further, in the same direction.
@@ -56,11 +63,15 @@ export declare function walkReferences(graph: Graph, start: NodeRef, options: Wa
56
63
  /**
57
64
  * @brief Finds the shortest chain of edges from one node to another, following edges the way they point.
58
65
  *
66
+ * Of the chains that are equally short, the one with the fewest `mentions` steps wins, so a link a description makes
67
+ * only stands in for code where code offers no chain as short.
68
+ *
59
69
  * @param graph - Graph both nodes belong to.
60
70
  * @param from - The node the chain starts at.
61
71
  * @param to - The node the chain ends at.
62
- * @param kinds - Edge kinds to follow. Empty follows every kind.
72
+ * @param kinds - Edge kinds to follow. Empty follows every kind but `mentions`, unless `includeMentions` is set.
73
+ * @param includeMentions - Whether an empty `kinds` follows `mentions` too.
63
74
  * @returns The references from `from` to `to`, in order, each to the next node of the chain. Empty when `from` is
64
75
  * `to`. `null` when no chain leads there.
65
76
  */
66
- export declare function shortestPath(graph: Graph, from: NodeRef, to: NodeRef, kinds: readonly EdgeKind[]): Reference[] | null;
77
+ export declare function shortestPath(graph: Graph, from: NodeRef, to: NodeRef, kinds: readonly EdgeKind[], includeMentions?: boolean): Reference[] | null;
@@ -25,6 +25,14 @@ export interface RawCall {
25
25
  readonly via: CallVia;
26
26
  readonly qualifier: readonly string[];
27
27
  }
28
+ /**
29
+ * @brief A call or a passed value of a function body, with every line it is on.
30
+ *
31
+ * @property lines - Lines of the file it is written on, in order, such as `[86, 112]` for a function called twice.
32
+ */
33
+ export interface LocatedCall extends RawCall {
34
+ readonly lines: readonly number[];
35
+ }
28
36
  /**
29
37
  * @brief The calls in a function body, and the functions it passes on as values.
30
38
  *
@@ -33,8 +41,8 @@ export interface RawCall {
33
41
  * `run(onDone)` or the entry of `{ add: addCommand }`, each once. A name the body binds itself is left out.
34
42
  */
35
43
  export interface BodyReferences {
36
- readonly calls: readonly RawCall[];
37
- readonly passes: readonly RawCall[];
44
+ readonly calls: readonly LocatedCall[];
45
+ readonly passes: readonly LocatedCall[];
38
46
  }
39
47
  /**
40
48
  * @brief Reads the calls of a function body, and the functions it passes on as values.
@@ -129,7 +137,7 @@ export declare class CallLinker {
129
137
  * @param context - Where the function is.
130
138
  * @param kind - `calls` for calls, `passes` for values passed on.
131
139
  */
132
- link(from: NodeRef, calls: readonly RawCall[], context: CallContext, kind: 'calls' | 'passes'): void;
140
+ link(from: NodeRef, calls: readonly LocatedCall[], context: CallContext, kind: 'calls' | 'passes'): void;
133
141
  /**
134
142
  * @brief Records that a method is a getter or a setter, which a value names without handing it on.
135
143
  *
@@ -2,12 +2,30 @@ import type { Node } from 'web-tree-sitter';
2
2
  import type { NodeRef } from '../../model';
3
3
  import { type FileExports } from './exports';
4
4
  /**
5
- * @brief One import of a file: the paths it can stand for, most specific first. The first one that names a
6
- * file of the scan wins.
5
+ * @brief One way to read an import: the path it names, and what it takes from that file.
7
6
  *
8
- * `from .models import Booking` is `['.models.Booking', '.models']`: `Booking` may be a module of its own.
7
+ * @property specifier - The path as written, such as `./store`, `slam/pose.hpp` or `.models`.
8
+ * @property whole - Whether it takes the file as a whole: `import './x'`, `import * as x`, a default import,
9
+ * `export * from`, `require('./x')`, an `#include`, or Python's `import a.b`.
10
+ * @property names - Names it takes from the file, as that file exports them: `['load']` for
11
+ * `import { load as start } from './x'` or `export { load } from './x'`.
9
12
  */
10
- export type ImportRequest = readonly string[];
13
+ export interface ImportTarget {
14
+ readonly specifier: string;
15
+ readonly whole: boolean;
16
+ readonly names: readonly string[];
17
+ }
18
+ /**
19
+ * @brief One import of a file: the ways it can be read, and the line it is on.
20
+ *
21
+ * @property targets - The ways to read it, most specific first. The first whose path names a file of the scan wins.
22
+ * `from .models import Booking` gives the module `.models.Booking` as a whole, then the name `Booking` of `.models`.
23
+ * @property line - Line of the file the import starts on.
24
+ */
25
+ export interface ImportRequest {
26
+ readonly targets: readonly ImportTarget[];
27
+ readonly line: number;
28
+ }
11
29
  /**
12
30
  * @brief How a language names the files a file imports.
13
31
  *
@@ -54,6 +72,7 @@ export interface ImportSyntax {
54
72
  * @property entryPoints - The subpaths each package is imported by, by the name its manifest gives.
55
73
  * @property resolved - Display paths each file imports, resolved on first use.
56
74
  * @property seen - Display paths each file sees, computed on first use.
75
+ * @property declarations - Node of each top-level declaration of each file, by display path and then by name.
57
76
  */
58
77
  export declare class SourceFileIndex {
59
78
  private readonly entries;
@@ -62,6 +81,7 @@ export declare class SourceFileIndex {
62
81
  private entryPoints;
63
82
  private readonly resolved;
64
83
  private readonly seen;
84
+ private readonly declarations;
65
85
  /**
66
86
  * @brief Adds a source file.
67
87
  *
@@ -117,6 +137,14 @@ export declare class SourceFileIndex {
117
137
  * @returns Its exports, empty for a file the scan does not have.
118
138
  */
119
139
  exportsOf(path: string): FileExports;
140
+ /**
141
+ * @brief Tells whether other files can import a name a file declares.
142
+ *
143
+ * @param path - Display path of the file.
144
+ * @param name - Name the file declares, such as `hashFile`.
145
+ * @returns True when the file exports the name, and always for a file whose exports the scan does not read.
146
+ */
147
+ exportsName(path: string, name: string): boolean;
120
148
  /**
121
149
  * @brief Node of the source file at `path`.
122
150
  *
@@ -145,6 +173,43 @@ export declare class SourceFileIndex {
145
173
  * @returns Display paths of the imported files, in the order the file imports them.
146
174
  */
147
175
  importsOf(path: string): readonly string[];
176
+ /**
177
+ * @brief What the imports of a file link to, each with the lines of the imports. An import of a whole file links
178
+ * to the file. An import by name links to the declaration of each name, through any `export … from` files in
179
+ * between, and to the file it names for a name that is no declaration of the scan, such as a constant.
180
+ *
181
+ * @param path - Display path of the importing file.
182
+ * @returns Each node the file imports, once, with the lines of the imports that reach it, in file order.
183
+ */
184
+ importLinksOf(path: string): {
185
+ readonly to: NodeRef;
186
+ readonly lines: readonly number[];
187
+ }[];
188
+ /**
189
+ * @brief Each import of a file that names a file of the scan, with that file and the way of reading it that won.
190
+ *
191
+ * @param path - Normalized display path of the importing file.
192
+ * @returns Every such import in file order.
193
+ */
194
+ private resolvedRequests;
195
+ /**
196
+ * @brief Records a top-level declaration of a file, so an import of its name can reach its node. The first
197
+ * declaration of a name wins, as for the overloads of one function.
198
+ *
199
+ * @param path - Display path of the file.
200
+ * @param name - Name it is declared with, such as `hashFile`.
201
+ * @param ref - Node of the declaration.
202
+ */
203
+ declare(path: string, name: string, ref: NodeRef): void;
204
+ /**
205
+ * @brief The declaration a file hands out under a name: its own, or one it re-exports from another file.
206
+ *
207
+ * @param path - Display path of the file.
208
+ * @param name - Name the file exports, such as `recordedHashes`.
209
+ * @param visited - Files already followed, so a cycle of re-exports ends.
210
+ * @returns Node of the declaration, or `null` when the file exports no declaration of the scan under the name.
211
+ */
212
+ private declarationOf;
148
213
  /**
149
214
  * @brief Tells whether the scan reads the imports of a file, so what it sees is known.
150
215
  *
@@ -102,7 +102,8 @@ export declare class CodePlanner {
102
102
  */
103
103
  private add;
104
104
  /**
105
- * @brief Records an `imports` edge from a file to each file of the scan it imports.
105
+ * @brief Records an `imports` edge from a file to each file it imports as a whole and to each declaration it
106
+ * imports by name, with the lines of its imports.
106
107
  *
107
108
  * @param from - Node of the importing file.
108
109
  * @param path - Display path of the importing file.
@@ -73,6 +73,14 @@ export declare class SymbolPlanner {
73
73
  * @param scope - Where the symbol sits in the file.
74
74
  */
75
75
  private planSymbol;
76
+ /**
77
+ * @brief Tells whether a name in a file can mean a declaration: only a test file reaches into test files, and only
78
+ * the package of a declaration reaches one it does not export.
79
+ *
80
+ * @param from - Display path of the file the name is in.
81
+ * @param declaration - Declaration the name may mean.
82
+ */
83
+ private admits;
76
84
  /**
77
85
  * @brief Builds the content of a symbol node: highlighted signature, rendered description,
78
86
  * return value, tags and example.
@@ -10,6 +10,11 @@ import type { GraphBuilder } from '../graph/builder';
10
10
  * `namespaceSeparator`. Unset where a qualifier may be a module or a variable, which says nothing about the declaration.
11
11
  * @property sees - Tells whether the file of the name sees a file, through what it imports. Unset where every file
12
12
  * counts, as for prose.
13
+ * @property admits - Tells whether the name can mean the declaration it resolves to, whether the file sees it or
14
+ * not: one that another package does not export, or a test helper outside the tests, it cannot. Unset where every
15
+ * declaration can, as for prose.
16
+ * @property locals - Names the symbol of a description declares itself, its parameters and fields. Inline code with
17
+ * one of these names means that one, so it never links. Unset outside descriptions.
13
18
  */
14
19
  export interface TypeScope {
15
20
  readonly path: string | null;
@@ -17,6 +22,8 @@ export interface TypeScope {
17
22
  readonly typeParameters: ReadonlySet<string>;
18
23
  readonly namespaceSeparator?: string;
19
24
  readonly sees?: (path: string) => boolean;
25
+ readonly admits?: (declaration: DeclarationSite) => boolean;
26
+ readonly locals?: ReadonlySet<string>;
20
27
  }
21
28
  /** Scope of a name in a document: any language, no file. */
22
29
  export declare const PROSE_SCOPE: TypeScope;
@@ -30,6 +37,8 @@ export declare const PROSE_SCOPE: TypeScope;
30
37
  * @property local - Whether only its own file can see it, as a type in a C++ source file or a `static` C function.
31
38
  * @property privateFile - Whether its file is one the other files cannot see, such as a C++ source file. A
32
39
  * declaration there that has a twin in a header is the definition of that twin.
40
+ * @property exported - Whether other files can import it: its file exports its outermost name, or its language has
41
+ * no exports the scan reads.
33
42
  */
34
43
  export interface DeclarationSite {
35
44
  readonly ref: NodeRef;
@@ -38,6 +47,7 @@ export interface DeclarationSite {
38
47
  readonly owners: readonly string[];
39
48
  readonly local: boolean;
40
49
  readonly privateFile: boolean;
50
+ readonly exported: boolean;
41
51
  }
42
52
  /**
43
53
  * @brief Every class, interface, struct, enum, trait and type alias of the scan, by name.
@@ -100,6 +110,9 @@ export declare class CallableIndex {
100
110
  /**
101
111
  * @brief The function a piece of inline code names.
102
112
  *
113
+ * A bare name names a method only in the file of that method. Elsewhere a method is named with its owner, as
114
+ * `Invoice.add`.
115
+ *
103
116
  * @param text - Inline code, such as `choose_route()` or `Invoice.add`.
104
117
  * @param scope - Where the code is used.
105
118
  * @returns The function, or `null` when the text names none or more than one.
@@ -179,7 +192,8 @@ export declare class TypeLinker {
179
192
  * @param from - Node the code is written in. The edge starts here.
180
193
  * @param scope - Where the code is used.
181
194
  * @param relation - Kind of edge to record, `mentions` by default.
182
- * @returns The node the code names, or `null` when it names none, more than one, or `from` itself.
195
+ * @returns The node the code names, or `null` when it names none, more than one, a parameter or field of the
196
+ * symbol it describes, or `from` itself.
183
197
  */
184
198
  mention(text: string, from: NodeRef, scope: TypeScope, relation?: EdgeKind): NodeRef | null;
185
199
  }
@@ -100,13 +100,15 @@ export declare class GraphBuilder {
100
100
  */
101
101
  href(ref: NodeRef, fragment?: string): string;
102
102
  /**
103
- * @brief Records an edge. The same edge recorded twice is kept once.
103
+ * @brief Records an edge. The same edge recorded twice is kept once, with the lines of both.
104
104
  *
105
105
  * @param from - Node the edge starts at.
106
106
  * @param kind - Relation the edge expresses.
107
107
  * @param to - Node the edge ends at.
108
+ * @param lines - Lines of the file of `from` where the link is made, such as those of a call. Empty when the link
109
+ * has no line of its own.
108
110
  */
109
- link(from: NodeRef, kind: EdgeKind, to: NodeRef): void;
111
+ link(from: NodeRef, kind: EdgeKind, to: NodeRef, lines?: readonly number[]): void;
110
112
  /**
111
113
  * @brief Runs the content source of every node and returns the finished graph.
112
114
  *
@@ -1,4 +1,4 @@
1
- export { type BodyReferences, CallLinker, type CallContext, type CallVia, type RawCall, readReferences } from './code/calls';
1
+ export { type BodyReferences, CallLinker, type CallContext, type CallVia, type LocatedCall, type RawCall, readReferences } from './code/calls';
2
2
  export { type ExtractedFile, type RawField, type RawParameter, type RawSymbol, SymbolExtractor } from './code/extract';
3
3
  export { GrammarLoader } from './code/grammar';
4
4
  export { C_INCLUDES, ECMASCRIPT_IMPORTS, type ImportRequest, type ImportSyntax, PYTHON_IMPORTS, SourceFileIndex, } from './code/imports';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g3nomaly/analyze",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Turns a repository into one offline HTML documentation site, and queries the same linked model from the terminal and from hooks.",
5
5
  "keywords": [
6
6
  "documentation",