@g3nomaly/analyze 0.1.3 → 0.1.4
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 +22 -7
- package/dist/api/bundle-cache.d.ts +3 -1
- package/dist/api/graph.d.ts +131 -0
- package/dist/api/list.d.ts +2 -0
- package/dist/api/options.d.ts +2 -1
- package/dist/api/refs.d.ts +6 -2
- package/dist/api/scan.d.ts +8 -1
- package/dist/api/search.d.ts +5 -2
- package/dist/api/services.d.ts +1 -1
- package/dist/api/show.d.ts +2 -0
- package/dist/cli.js +1677 -596
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1592 -556
- package/dist/model/index.d.ts +26 -0
- package/dist/model/registry.d.ts +24 -0
- package/dist/query/graph-view.d.ts +105 -0
- package/dist/query/graph.d.ts +22 -0
- package/dist/query/index.d.ts +3 -2
- package/dist/query/name-search.d.ts +1 -1
- package/dist/query/semantic.d.ts +10 -0
- package/dist/retrieval/filter.d.ts +4 -1
- package/dist/retrieval/graph-export.d.ts +82 -0
- package/dist/retrieval/index.d.ts +1 -0
- package/dist/retrieval/retriever.d.ts +21 -2
- package/dist/scanner/code/calls.d.ts +136 -0
- package/dist/scanner/code/extract.d.ts +10 -2
- package/dist/scanner/code/imports.d.ts +147 -0
- package/dist/scanner/code/language.d.ts +14 -0
- package/dist/scanner/code/planner.d.ts +16 -4
- package/dist/scanner/code/symbols.d.ts +19 -3
- package/dist/scanner/code/types.d.ts +76 -17
- package/dist/scanner/graph/builder.d.ts +14 -3
- package/dist/scanner/graph/communities.d.ts +17 -0
- package/dist/scanner/ignore.d.ts +5 -7
- package/dist/scanner/index.d.ts +4 -1
- package/dist/scanner/markdown/outline.d.ts +2 -0
- package/dist/scanner/packages.d.ts +6 -0
- package/dist/scanner/scanner.d.ts +2 -2
- package/package.json +3 -3
package/dist/model/index.d.ts
CHANGED
|
@@ -628,6 +628,16 @@ export type EntryNode = SymbolNode | TermNode | DecisionNode | OperationNode | D
|
|
|
628
628
|
* @param node - Node to test.
|
|
629
629
|
*/
|
|
630
630
|
export declare function isSymbolNode(node: GraphNode): node is SymbolNode;
|
|
631
|
+
/**
|
|
632
|
+
* @brief Tells a placeholder from the others: a type the scanner inferred from members defined outside it, such
|
|
633
|
+
* as the class around `Registry::run` in a C++ source file.
|
|
634
|
+
*
|
|
635
|
+
* It groups those members on the page of their file and declares nothing of its own, so search, `list` and lookup
|
|
636
|
+
* by name leave it out, and the real declaration answers for the type.
|
|
637
|
+
*
|
|
638
|
+
* @param node - Node to test.
|
|
639
|
+
*/
|
|
640
|
+
export declare function isPlaceholderNode(node: GraphNode): boolean;
|
|
631
641
|
/**
|
|
632
642
|
* Tells an entry node, a symbol included, from the others.
|
|
633
643
|
*
|
|
@@ -699,6 +709,20 @@ export interface SemanticIndex {
|
|
|
699
709
|
readonly words: string;
|
|
700
710
|
readonly nodeWords: readonly (readonly [name: readonly number[], text: readonly number[]])[];
|
|
701
711
|
}
|
|
712
|
+
/**
|
|
713
|
+
* @brief The communities of a bundle: groups of nodes that link to each other more than to the rest, found once
|
|
714
|
+
* per scan by `detectCommunities` in `scanner/graph/communities.ts`.
|
|
715
|
+
*
|
|
716
|
+
* A community is a plain value of a node. Nothing in the layout of the graph page pulls a community together.
|
|
717
|
+
*
|
|
718
|
+
* @property labels - Label of each community, by id: the name of its best-linked node. Id 0 is the largest community.
|
|
719
|
+
* @property of - Community id of each node, by `NodeRef`. A parameter or field has the id of the entry it belongs
|
|
720
|
+
* to. `-1` for a section, folder or package, which belong to none.
|
|
721
|
+
*/
|
|
722
|
+
export interface CommunityIndex {
|
|
723
|
+
readonly labels: readonly string[];
|
|
724
|
+
readonly of: readonly number[];
|
|
725
|
+
}
|
|
702
726
|
/**
|
|
703
727
|
* @brief The data contract between the scanner and the web app: the CLI serializes
|
|
704
728
|
* one bundle into the generated HTML file, and the app reads it back.
|
|
@@ -713,12 +737,14 @@ export interface SemanticIndex {
|
|
|
713
737
|
* @property nodes - Every node. A node comes after its parent, and siblings are in display order.
|
|
714
738
|
* @property edges - Relations other than `parent`.
|
|
715
739
|
* @property semantic - Index for search by meaning. Left out when the site was generated without embeddings.
|
|
740
|
+
* @property communities - Community of every node. Left out by a bundle written before communities existed.
|
|
716
741
|
*/
|
|
717
742
|
export interface DocsBundle {
|
|
718
743
|
readonly meta: BundleMeta;
|
|
719
744
|
readonly nodes: readonly GraphNode[];
|
|
720
745
|
readonly edges: readonly Edge[];
|
|
721
746
|
readonly semantic?: SemanticIndex;
|
|
747
|
+
readonly communities?: CommunityIndex;
|
|
722
748
|
}
|
|
723
749
|
/**
|
|
724
750
|
* Where a node is shown: a page, and for an entry an anchor on that page.
|
package/dist/model/registry.d.ts
CHANGED
|
@@ -503,6 +503,11 @@ export declare const RELATION_FAMILY_REGISTRY: {
|
|
|
503
503
|
readonly description: 'What a task names, and what it waits for.';
|
|
504
504
|
readonly colorToken: '--edge-task';
|
|
505
505
|
};
|
|
506
|
+
readonly code: {
|
|
507
|
+
readonly label: 'code';
|
|
508
|
+
readonly description: 'What a source file includes, and what a function calls.';
|
|
509
|
+
readonly colorToken: '--edge-code';
|
|
510
|
+
};
|
|
506
511
|
};
|
|
507
512
|
/** Every relation kind other than `parent`, in the order the site lists them. */
|
|
508
513
|
export declare const RELATION_KIND_REGISTRY: {
|
|
@@ -619,6 +624,25 @@ export declare const RELATION_KIND_REGISTRY: {
|
|
|
619
624
|
readonly family: 'task';
|
|
620
625
|
readonly dashed: true;
|
|
621
626
|
};
|
|
627
|
+
readonly imports: {
|
|
628
|
+
readonly label: 'imports';
|
|
629
|
+
readonly description: 'A source file includes or imports that source file.';
|
|
630
|
+
readonly forward: 'imports';
|
|
631
|
+
readonly backward: 'is imported by';
|
|
632
|
+
readonly from: 'source file';
|
|
633
|
+
readonly to: 'source file';
|
|
634
|
+
readonly family: 'code';
|
|
635
|
+
};
|
|
636
|
+
readonly calls: {
|
|
637
|
+
readonly label: 'calls';
|
|
638
|
+
readonly description: 'A function or method calls that function or method.';
|
|
639
|
+
readonly forward: 'calls';
|
|
640
|
+
readonly backward: 'is called by';
|
|
641
|
+
readonly from: 'function or method';
|
|
642
|
+
readonly to: 'function or method';
|
|
643
|
+
readonly family: 'code';
|
|
644
|
+
readonly dashed: true;
|
|
645
|
+
};
|
|
622
646
|
};
|
|
623
647
|
/** Slug of a top-level section, such as `code`. */
|
|
624
648
|
export type Section = keyof typeof SECTION_REGISTRY;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type EdgeKind, type NodeRef, type NodeType, type Section } from '../model';
|
|
2
|
+
import { type Graph } from './graph';
|
|
3
|
+
/**
|
|
4
|
+
* How much of the bundle the graph view draws.
|
|
5
|
+
* - `files`: sections, folders, packages and files, plans and phases. References between entries are drawn between their files.
|
|
6
|
+
* - `entries`: `files`, plus every class, function, glossary term, decision, table, query and task.
|
|
7
|
+
* - `all`: `entries`, plus every operation and definition, and each parameter and field that refers to a type of the repository.
|
|
8
|
+
*/
|
|
9
|
+
export declare const GRAPH_LEVELS: readonly ['files', 'entries', 'all'];
|
|
10
|
+
/** One of `GRAPH_LEVELS`. */
|
|
11
|
+
export type GraphLevel = (typeof GRAPH_LEVELS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* @brief One dot of the graph view.
|
|
14
|
+
*
|
|
15
|
+
* @property ref - The node of the bundle the dot stands for.
|
|
16
|
+
* @property kind - Kind of that node.
|
|
17
|
+
* @property name - Name of the node, shown as the label of the dot.
|
|
18
|
+
* @property section - Section the dot is in.
|
|
19
|
+
* @property parent - Index of the parent dot in `GraphView.nodes`, or `null` for a section.
|
|
20
|
+
* @property package - Display path of the package the node is or is in, such as `packages/core`, or `null` outside every package.
|
|
21
|
+
* @property community - Id of the community of the node, or `null` for a section, folder or package.
|
|
22
|
+
*/
|
|
23
|
+
export interface ViewNode {
|
|
24
|
+
readonly ref: NodeRef;
|
|
25
|
+
readonly kind: NodeType;
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly section: Section;
|
|
28
|
+
readonly parent: number | null;
|
|
29
|
+
readonly package: string | null;
|
|
30
|
+
readonly community: number | null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @brief One arrow of the graph view, between two dots.
|
|
34
|
+
*
|
|
35
|
+
* @property source - Index of the dot the arrow starts at, in `GraphView.nodes`.
|
|
36
|
+
* @property target - Index of the dot the arrow points at, in `GraphView.nodes`.
|
|
37
|
+
* @property kind - Kind of the references the arrow stands for.
|
|
38
|
+
* @property count - Number of edges of the bundle the arrow stands for.
|
|
39
|
+
*/
|
|
40
|
+
export interface ViewReference {
|
|
41
|
+
readonly source: number;
|
|
42
|
+
readonly target: number;
|
|
43
|
+
readonly kind: EdgeKind;
|
|
44
|
+
readonly count: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @brief The dots and arrows of one level, and which dot shows each node of the bundle.
|
|
48
|
+
*
|
|
49
|
+
* A parent precedes its children, as in the bundle. Built by `buildGraphView`
|
|
50
|
+
* for the graph page, and read by `GraphCanvas`, the graph details panel and
|
|
51
|
+
* the force layout in `force-graph.ts`.
|
|
52
|
+
*
|
|
53
|
+
* @property level - Level the view was built for.
|
|
54
|
+
* @property nodes - Dots, parents before children.
|
|
55
|
+
* @property references - Arrows between the dots.
|
|
56
|
+
* @property shownBy - Bundle node to the index of the dot that shows it.
|
|
57
|
+
*/
|
|
58
|
+
export declare class GraphView {
|
|
59
|
+
readonly level: GraphLevel;
|
|
60
|
+
readonly nodes: readonly ViewNode[];
|
|
61
|
+
readonly references: readonly ViewReference[];
|
|
62
|
+
private readonly shownBy;
|
|
63
|
+
/**
|
|
64
|
+
* @brief Holds the dots, the arrows and the map from bundle nodes to dots.
|
|
65
|
+
*
|
|
66
|
+
* @param level - Level the view was built for.
|
|
67
|
+
* @param nodes - Dots, parents before children.
|
|
68
|
+
* @param references - Arrows between the dots.
|
|
69
|
+
* @param shownBy - Bundle node to the index of the dot that shows it.
|
|
70
|
+
*/
|
|
71
|
+
constructor(level: GraphLevel, nodes: readonly ViewNode[], references: readonly ViewReference[], shownBy: ReadonlyMap<NodeRef, number>);
|
|
72
|
+
/**
|
|
73
|
+
* @brief Finds the dot that shows a node of the bundle: its own dot, or the dot
|
|
74
|
+
* of its nearest drawn ancestor, such as the function of a parameter.
|
|
75
|
+
*
|
|
76
|
+
* @param ref - Bundle node to locate.
|
|
77
|
+
* @returns Index of the dot in `GraphView.nodes`, or `undefined` when no dot shows the node.
|
|
78
|
+
*/
|
|
79
|
+
locate(ref: NodeRef): number | undefined;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @brief Builds the view of one level.
|
|
83
|
+
*
|
|
84
|
+
* A node the level does not draw, such as a parameter below `all`, is shown by its nearest drawn ancestor:
|
|
85
|
+
* its edges start or end there. A package has one `package` node, in the code section. A folder of the docs
|
|
86
|
+
* section at the path of a package is in that package too.
|
|
87
|
+
*
|
|
88
|
+
* @param graph - Graph to draw.
|
|
89
|
+
* @param level - Level to build.
|
|
90
|
+
* @returns The dots and arrows of the level.
|
|
91
|
+
*/
|
|
92
|
+
export declare function buildGraphView(graph: Graph, level: GraphLevel): GraphView;
|
|
93
|
+
/**
|
|
94
|
+
* @brief Picks the level the view opens at: every entry while the graph stays readable, files otherwise.
|
|
95
|
+
*
|
|
96
|
+
* @param graph - Graph to draw.
|
|
97
|
+
* @returns `entries` while at most `ENTRIES_LIMIT` dots would be drawn, else `files`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function defaultGraphLevel(graph: Graph): GraphLevel;
|
|
100
|
+
/**
|
|
101
|
+
* @brief Lists the packages of a graph.
|
|
102
|
+
*
|
|
103
|
+
* @returns Display paths of the packages, such as `packages/core`, each once, sorted.
|
|
104
|
+
*/
|
|
105
|
+
export declare function packagesIn(graph: Graph): string[];
|
package/dist/query/graph.d.ts
CHANGED
|
@@ -5,6 +5,18 @@ import { type BundleMeta, type DocsBundle, type Edge, type GraphNode, type NodeT
|
|
|
5
5
|
* @param kind - Kind of a node, such as `parameter`.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isDeclarationKind(kind: NodeType): kind is 'parameter' | 'field';
|
|
8
|
+
/**
|
|
9
|
+
* @brief One community of a bundle.
|
|
10
|
+
*
|
|
11
|
+
* @property id - Id of the community. 0 is the largest.
|
|
12
|
+
* @property label - Name of its best-linked node.
|
|
13
|
+
* @property size - Number of pages and entries in it. Parameters and fields count with their entry.
|
|
14
|
+
*/
|
|
15
|
+
export interface Community {
|
|
16
|
+
readonly id: number;
|
|
17
|
+
readonly label: string;
|
|
18
|
+
readonly size: number;
|
|
19
|
+
}
|
|
8
20
|
/**
|
|
9
21
|
* @brief The bundle as a graph the app can walk: children, routes and edges in both
|
|
10
22
|
* directions. Built once at startup.
|
|
@@ -20,6 +32,7 @@ export declare function isDeclarationKind(kind: NodeType): kind is 'parameter' |
|
|
|
20
32
|
* @property meta - Title, generation time and generator of the bundle.
|
|
21
33
|
* @property semantic - The embedding model and node vectors for search by meaning, when the bundle has them.
|
|
22
34
|
* @property sections - The sections of the bundle, in display order. Some bundles lack `database`, so a walk over every section goes through this list.
|
|
35
|
+
* @property communities - The communities of the bundle, by id. Empty for a bundle written before communities existed.
|
|
23
36
|
*/
|
|
24
37
|
export declare class Graph {
|
|
25
38
|
readonly meta: BundleMeta;
|
|
@@ -35,12 +48,21 @@ export declare class Graph {
|
|
|
35
48
|
readonly slug: Section;
|
|
36
49
|
readonly node: NodeRef;
|
|
37
50
|
}[];
|
|
51
|
+
readonly communities: readonly Community[];
|
|
52
|
+
private readonly communityIndex;
|
|
38
53
|
/**
|
|
39
54
|
* Indexes the nodes and edges of a bundle.
|
|
40
55
|
*
|
|
41
56
|
* @param bundle - Bundle to index, from the embedded data or a loaded file.
|
|
42
57
|
*/
|
|
43
58
|
constructor(bundle: DocsBundle);
|
|
59
|
+
/**
|
|
60
|
+
* @brief The community a node is in.
|
|
61
|
+
*
|
|
62
|
+
* @param ref - Index of the node in the bundle.
|
|
63
|
+
* @returns The id of its community, or `null` for a section, folder or package, and in a bundle without communities.
|
|
64
|
+
*/
|
|
65
|
+
communityOf(ref: NodeRef): number | null;
|
|
44
66
|
/**
|
|
45
67
|
* Returns the node at `ref`, and throws when there is none.
|
|
46
68
|
*
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Graph, isDeclarationKind } from './graph';
|
|
1
|
+
export { type Community, Graph, isDeclarationKind } from './graph';
|
|
2
2
|
export { buildSearchIndex, type SearchEntry, type SearchMatch, search } from './name-search';
|
|
3
|
-
export { embeddingModelName, type MeaningOptions, searchByMeaning, similarNodes } from './semantic';
|
|
3
|
+
export { embeddingModelName, type MeaningOptions, searchByMeaning, searchWeakMeaning, similarNodes } from './semantic';
|
|
4
4
|
export { codeText, firstParagraph, plainText } from './text';
|
|
5
|
+
export { buildGraphView, defaultGraphLevel, GRAPH_LEVELS, type GraphLevel, GraphView, packagesIn, type ViewNode, type ViewReference, } from './graph-view';
|
|
@@ -41,7 +41,7 @@ export interface SearchMatch {
|
|
|
41
41
|
* @brief Builds the index for search by words: one entry per file, symbol, glossary term, decision, table,
|
|
42
42
|
* query and task.
|
|
43
43
|
*
|
|
44
|
-
* Folders are not searched. The name and the text of a parameter, field, operation or definition are added to
|
|
44
|
+
* Folders and placeholders are not searched. The name and the text of a parameter, field, operation or definition are added to
|
|
45
45
|
* the entry of the nearest ancestor that is none of these, such as its function or its file, so a search for
|
|
46
46
|
* it finds that node. It also gets an entry of its own, marked `member`, for a query that keeps to its kind.
|
|
47
47
|
*
|
package/dist/query/semantic.d.ts
CHANGED
|
@@ -21,6 +21,16 @@ export interface MeaningOptions {
|
|
|
21
21
|
* @returns The closest nodes, best first. Empty for a graph without embeddings.
|
|
22
22
|
*/
|
|
23
23
|
export declare function searchByMeaning(graph: Graph, query: string, exclude: ReadonlySet<NodeRef>, options?: MeaningOptions): SemanticHit[];
|
|
24
|
+
/**
|
|
25
|
+
* @brief Finds the nodes closest to a query that score below the cut-off of {@link searchByMeaning}, for a search
|
|
26
|
+
* that found nothing above it. They may still be what the reader means, worded otherwise.
|
|
27
|
+
*
|
|
28
|
+
* @param graph - Graph to search.
|
|
29
|
+
* @param query - What the reader typed.
|
|
30
|
+
* @param accepts - Says which nodes count.
|
|
31
|
+
* @returns Up to `WEAK_LIMIT` hits that score from `WEAK_MIN_SCORE` up to the cut-off, best first. Empty for a graph without embeddings.
|
|
32
|
+
*/
|
|
33
|
+
export declare function searchWeakMeaning(graph: Graph, query: string, accepts: (node: NodeRef) => boolean): SemanticHit[];
|
|
24
34
|
/**
|
|
25
35
|
* Finds the nodes whose meaning is closest to that of a node.
|
|
26
36
|
*
|
|
@@ -5,10 +5,13 @@ import type { Graph } from '../query';
|
|
|
5
5
|
*
|
|
6
6
|
* @property kinds - Kinds to match, such as `function` or `field`. Empty matches every kind. A member kind matches its nodes, and the query returns the node each belongs to.
|
|
7
7
|
* @property section - Section the results are in. `null` looks in every section.
|
|
8
|
+
* @property communities - Ids of the communities the results are in. Absent or empty looks in every community. A
|
|
9
|
+
* section, folder or package is in none, so a filter with communities leaves them out.
|
|
8
10
|
*/
|
|
9
11
|
export interface NodeFilter {
|
|
10
12
|
readonly kinds: readonly NodeKind[];
|
|
11
13
|
readonly section: Section | null;
|
|
14
|
+
readonly communities?: readonly number[];
|
|
12
15
|
}
|
|
13
16
|
/** The filter that keeps every node. */
|
|
14
17
|
export declare const NO_FILTER: NodeFilter;
|
|
@@ -24,7 +27,7 @@ export declare function resultOf(graph: Graph, node: NodeRef): NodeRef;
|
|
|
24
27
|
/**
|
|
25
28
|
* @brief Turns a filter into a test for one node that a query matches against.
|
|
26
29
|
*
|
|
27
|
-
* @returns A function that says whether a node matches. A section never
|
|
30
|
+
* @returns A function that says whether a node matches. A section and a placeholder never match. A member node matches by its own kind and by the section of its result.
|
|
28
31
|
*/
|
|
29
32
|
export declare function nodeTest(graph: Graph, filter: NodeFilter): (node: NodeRef) => boolean;
|
|
30
33
|
/**
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type EdgeKind, type NodeKind, type NodeType } from '../model';
|
|
2
|
+
import { type Graph } from '../query';
|
|
3
|
+
import type { NodeFilter } from './filter';
|
|
4
|
+
/**
|
|
5
|
+
* How much of the bundle an export holds.
|
|
6
|
+
* - `packages`: one node per package, and the edges between packages, each the sum of the edges between their nodes.
|
|
7
|
+
* - `communities`: one node per community, and the edges between communities, summed the same way.
|
|
8
|
+
* - `files`, `entries` and `all`: the levels of the graph page of the site, see `GRAPH_LEVELS`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const EXPORT_LEVELS: readonly ["packages", "communities", "files", "entries", "all"];
|
|
11
|
+
/** One of {@link EXPORT_LEVELS}. */
|
|
12
|
+
export type ExportLevel = (typeof EXPORT_LEVELS)[number];
|
|
13
|
+
/**
|
|
14
|
+
* @brief What to export: the level, which nodes and which edges.
|
|
15
|
+
*
|
|
16
|
+
* @property level - How much of the bundle the export holds.
|
|
17
|
+
* @property filter - Kinds and section of the nodes to keep. An edge is kept when both its ends are.
|
|
18
|
+
* @property edges - Edge kinds to keep. Empty keeps every kind.
|
|
19
|
+
*/
|
|
20
|
+
export interface GraphExportOptions {
|
|
21
|
+
readonly level: ExportLevel;
|
|
22
|
+
readonly filter: NodeFilter;
|
|
23
|
+
readonly edges: readonly EdgeKind[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @brief One node of an export.
|
|
27
|
+
*
|
|
28
|
+
* @property id - Id of the node, as `show` and `refs` take it.
|
|
29
|
+
* @property kind - Kind of the node, such as `package`, `file` or `function`.
|
|
30
|
+
* @property type - Type of the node, such as `source` or `method`.
|
|
31
|
+
* @property name - Name of the node. For a package, the name its manifest gives.
|
|
32
|
+
* @property package - Display path of the package the node is or is in, such as `libs/slam`, or `null`.
|
|
33
|
+
* @property community - Id of the community of the node, or `null` for a section, folder or package.
|
|
34
|
+
* @property parent - Id of the node it is drawn in, such as the folder of a file, or `null`. Always `null` at the
|
|
35
|
+
* `packages` and `communities` levels.
|
|
36
|
+
*/
|
|
37
|
+
export interface ExportNode {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly kind: NodeKind | 'community';
|
|
40
|
+
readonly type: NodeType | 'community';
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly package: string | null;
|
|
43
|
+
readonly community: number | null;
|
|
44
|
+
readonly parent: string | null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @brief Edges of one kind between two nodes of an export.
|
|
48
|
+
*
|
|
49
|
+
* An edge of a node the level does not hold, such as a call between two functions at the `files` level, counts
|
|
50
|
+
* for the nodes that hold its ends, such as their files.
|
|
51
|
+
*
|
|
52
|
+
* @property from - Id of the node the edges start at.
|
|
53
|
+
* @property kind - Kind of the edges.
|
|
54
|
+
* @property to - Id of the node the edges point at.
|
|
55
|
+
* @property count - Number of edges of the bundle this one stands for.
|
|
56
|
+
*/
|
|
57
|
+
export interface ExportEdge {
|
|
58
|
+
readonly from: string;
|
|
59
|
+
readonly kind: EdgeKind;
|
|
60
|
+
readonly to: string;
|
|
61
|
+
readonly count: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @brief The nodes and edges of one level of a bundle, with ids instead of refs.
|
|
65
|
+
*
|
|
66
|
+
* @property level - The level exported.
|
|
67
|
+
* @property nodes - The nodes, in the order of the navigation.
|
|
68
|
+
* @property edges - The edges, sorted by source, kind and target.
|
|
69
|
+
*/
|
|
70
|
+
export interface GraphExport {
|
|
71
|
+
readonly level: ExportLevel;
|
|
72
|
+
readonly nodes: readonly ExportNode[];
|
|
73
|
+
readonly edges: readonly ExportEdge[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @brief Exports one level of a graph.
|
|
77
|
+
*
|
|
78
|
+
* @param graph - Graph of the bundle.
|
|
79
|
+
* @param options - Level, node filter and edge kinds.
|
|
80
|
+
* @returns The nodes and edges of the level.
|
|
81
|
+
*/
|
|
82
|
+
export declare function exportGraph(graph: Graph, options: GraphExportOptions): GraphExport;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ALL_REFERENCES, describeNode, type ReferenceOptions, referencesOf } from './describe';
|
|
2
2
|
export { NO_FILTER, type NodeFilter, nodeTest, resultOf, resultsOf } from './filter';
|
|
3
|
+
export { EXPORT_LEVELS, type ExportEdge, type ExportLevel, type ExportNode, type GraphExport, type GraphExportOptions, exportGraph, } from './graph-export';
|
|
3
4
|
export { codeBlock, htmlToMarkdown } from './markdown';
|
|
4
5
|
export type { ContentReport, DatabaseObjectReport, DeclarationReport, ForeignKeyReport, NodeReport, NodeSummary, OperationReport, QueryReport, Reference, References, TableReport, TagReport, TaskReport, } from './report';
|
|
5
6
|
export { type Resolution, resolveNode } from './resolve';
|
|
@@ -2,6 +2,7 @@ import type { NodeRef } from '../model';
|
|
|
2
2
|
import { type Graph } from '../query';
|
|
3
3
|
import { type ReferenceOptions } from './describe';
|
|
4
4
|
import { type NodeFilter } from './filter';
|
|
5
|
+
import { type GraphExport, type GraphExportOptions } from './graph-export';
|
|
5
6
|
import type { NodeReport, NodeSummary, References } from './report';
|
|
6
7
|
import { type Resolution } from './resolve';
|
|
7
8
|
/** The search modes a caller can pick from, the default first. */
|
|
@@ -25,17 +26,19 @@ export interface SearchOptions {
|
|
|
25
26
|
*
|
|
26
27
|
* @property match - `name`: every word of the query is in the name or the path of the node. `text`: at least one word is only in its description. `meaning`: the node is close to the query in the embedding model.
|
|
27
28
|
* @property score - From 0 to 1 for a match by meaning. `null` for a match by words.
|
|
29
|
+
* @property weak - `true` for a match by meaning below the cut-off, which only a search that found nothing else returns. Absent on every other hit.
|
|
28
30
|
*/
|
|
29
31
|
export interface SearchHit extends NodeSummary {
|
|
30
32
|
readonly match: 'name' | 'text' | 'meaning';
|
|
31
33
|
readonly score: number | null;
|
|
34
|
+
readonly weak?: true;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
|
-
* @brief Answers queries on one bundle: search, list, look up, describe.
|
|
37
|
+
* @brief Answers queries on one bundle: search, list, look up, describe, export.
|
|
35
38
|
*
|
|
36
39
|
* Holds the graph of the bundle and, after the first search by name, the
|
|
37
40
|
* search index. `openRetriever` in `api/source.ts` creates one per request from
|
|
38
|
-
* a `Graph`; `listIn`, `searchIn`, `showIn` and `
|
|
41
|
+
* a `Graph`; `listIn`, `searchIn`, `showIn`, `refsIn` and `graphIn` in `api/` each call one
|
|
39
42
|
* method. Create one with `new Retriever(new Graph(bundle))`. Every answer is
|
|
40
43
|
* plain data with ids, so a caller can print it, serialize it or feed an id into
|
|
41
44
|
* the next call.
|
|
@@ -64,6 +67,15 @@ export declare class Retriever {
|
|
|
64
67
|
* @returns The hits, each once.
|
|
65
68
|
*/
|
|
66
69
|
search(query: string, options: SearchOptions): SearchHit[];
|
|
70
|
+
/**
|
|
71
|
+
* @brief Finds the few nodes closest in meaning to a query below the cut-off of `search`, for a search that found
|
|
72
|
+
* nothing. The caller shows them as weak matches.
|
|
73
|
+
*
|
|
74
|
+
* @param query - The query that found nothing.
|
|
75
|
+
* @param options - Mode and filter of that search. Its limit caps the hits too.
|
|
76
|
+
* @returns The hits, best first, each with `weak: true`. Empty for a search by name or a bundle without embeddings.
|
|
77
|
+
*/
|
|
78
|
+
searchWeak(query: string, options: SearchOptions): SearchHit[];
|
|
67
79
|
/**
|
|
68
80
|
* @brief Lists pages and entries in display order.
|
|
69
81
|
*
|
|
@@ -102,4 +114,11 @@ export declare class Retriever {
|
|
|
102
114
|
* @returns What the node links to and what links to it.
|
|
103
115
|
*/
|
|
104
116
|
references(node: NodeRef, options?: ReferenceOptions): References;
|
|
117
|
+
/**
|
|
118
|
+
* @brief Exports one level of the bundle as nodes and edges.
|
|
119
|
+
*
|
|
120
|
+
* @param options - Level, node filter and edge kinds.
|
|
121
|
+
* @returns The nodes and edges of the level, with ids.
|
|
122
|
+
*/
|
|
123
|
+
exportGraph(options: GraphExportOptions): GraphExport;
|
|
105
124
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Node } from 'web-tree-sitter';
|
|
2
|
+
import type { NodeRef } from '../../model';
|
|
3
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
4
|
+
import type { SourceFileIndex } from './imports';
|
|
5
|
+
import { type CallableIndex, type TypeIndex, type TypeScope } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* @brief How a call names what it calls.
|
|
8
|
+
*
|
|
9
|
+
* - `bare`: by name alone, as in `helper()`.
|
|
10
|
+
* - `scoped`: through a namespace or a type, as in `geo::distance()` or `Timer::once()`.
|
|
11
|
+
* - `self`: through the instance it runs on, as in `this->flush()` or `self.flush()`.
|
|
12
|
+
* - `member`: through another value, as in `store.flush()` or `store->flush()`.
|
|
13
|
+
*/
|
|
14
|
+
export type CallVia = 'bare' | 'scoped' | 'self' | 'member';
|
|
15
|
+
/**
|
|
16
|
+
* @brief One call in the body of a function, as written.
|
|
17
|
+
*
|
|
18
|
+
* @property name - Name of the function the call names, such as `flush`.
|
|
19
|
+
* @property via - How the call names it.
|
|
20
|
+
* @property qualifier - For a `scoped` call, the names in front of `name`, outermost first, such as `['geo']`.
|
|
21
|
+
* For a `member` call, the variable it goes through, such as `['store']`, or `[]` when that is an expression.
|
|
22
|
+
*/
|
|
23
|
+
export interface RawCall {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly via: CallVia;
|
|
26
|
+
readonly qualifier: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @brief Reads every call in a function body, each once, in the order they first appear.
|
|
30
|
+
*
|
|
31
|
+
* Calls inside a nested definition belong to that definition and are left out. Calls inside a lambda or a
|
|
32
|
+
* closure belong to the function around it. A call through a variable the body declares itself keeps no
|
|
33
|
+
* variable, since that local may hide a parameter or field of the same name and its type is unknown.
|
|
34
|
+
*
|
|
35
|
+
* @param body - Body node of the function.
|
|
36
|
+
* @param definitions - Ids of the definition nodes of the file.
|
|
37
|
+
* @returns The calls the body makes.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readCalls(body: Node, definitions: ReadonlySet<number>): RawCall[];
|
|
40
|
+
/**
|
|
41
|
+
* @brief What a call can be resolved with: where it is, the names around its function, and the declared types
|
|
42
|
+
* of the variables it can go through.
|
|
43
|
+
*
|
|
44
|
+
* @property scope - Where the call is.
|
|
45
|
+
* @property owners - Names of the namespaces and types around the calling function, outermost first.
|
|
46
|
+
* @property variables - Declared type of each parameter of the calling function and each field of its type, by name.
|
|
47
|
+
* @property inType - Whether the innermost owner is a type rather than a namespace.
|
|
48
|
+
* @property implicitReceiver - Whether a bare call in a method can mean another method of its type, from the spec.
|
|
49
|
+
*/
|
|
50
|
+
export interface CallContext {
|
|
51
|
+
readonly scope: TypeScope;
|
|
52
|
+
readonly owners: readonly string[];
|
|
53
|
+
readonly variables: ReadonlyMap<string, string>;
|
|
54
|
+
readonly inType: boolean;
|
|
55
|
+
readonly implicitReceiver: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @brief Turns the calls of a function into `calls` edges to the functions of the scan they reach.
|
|
59
|
+
*
|
|
60
|
+
* A call only links when it names one function its file sees: one in the same file or in a file it imports, directly
|
|
61
|
+
* or not. For a language whose imports the scan does not read, a bare call only reaches a free function of the same
|
|
62
|
+
* directory. A bare call reaches a function of the calling type where the language allows it, else a free function. A scoped call reaches a member of the namespace or type it names. A member call reaches a method of
|
|
63
|
+
* the declared type of the parameter or field it goes through, else a static method of a type of that name; a call
|
|
64
|
+
* through any other expression links nowhere, since its type is unknown.
|
|
65
|
+
*
|
|
66
|
+
* Holds the indexes it resolves against, the graph it adds edges to, and the fields of each type. Created per scan
|
|
67
|
+
* by `RepositoryScanner` in `scanner/scanner.ts`; `SymbolPlanner` in `symbols.ts` registers the fields of each type
|
|
68
|
+
* and links the calls of each function once every declaration is known.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* const calls = new CallLinker(types, callables, sources, graph);
|
|
72
|
+
* calls.link(functionRef, rawSymbol.calls, { scope, owners: ['geo'], variables: new Map() });
|
|
73
|
+
*/
|
|
74
|
+
export declare class CallLinker {
|
|
75
|
+
private readonly types;
|
|
76
|
+
private readonly callables;
|
|
77
|
+
private readonly sources;
|
|
78
|
+
private readonly graph;
|
|
79
|
+
private readonly fields;
|
|
80
|
+
/**
|
|
81
|
+
* Takes the indexes the calls resolve against and the graph the edges are added to.
|
|
82
|
+
*
|
|
83
|
+
* @param types - Type declarations, for the type of a variable and the owner of a method.
|
|
84
|
+
* @param callables - Functions and methods the calls reach.
|
|
85
|
+
* @param sources - Source files with their imports, to tell which files a call can reach.
|
|
86
|
+
* @param graph - Graph the edges are added to.
|
|
87
|
+
*/
|
|
88
|
+
constructor(types: TypeIndex, callables: CallableIndex, sources: SourceFileIndex, graph: GraphBuilder);
|
|
89
|
+
/**
|
|
90
|
+
* @brief Records the declared types of the fields of a type, for the calls of its methods.
|
|
91
|
+
*
|
|
92
|
+
* @param type - Node of the type.
|
|
93
|
+
* @param fields - Declared type of each field, by name.
|
|
94
|
+
*/
|
|
95
|
+
registerFields(type: NodeRef, fields: ReadonlyMap<string, string>): void;
|
|
96
|
+
/**
|
|
97
|
+
* @brief The declared types of the fields of the type a function belongs to, even when the function is defined
|
|
98
|
+
* outside it, as a C++ method in its source file is.
|
|
99
|
+
*
|
|
100
|
+
* @param context - Where the function is.
|
|
101
|
+
* @returns The field types by name, empty when the function belongs to no type of the scan.
|
|
102
|
+
*/
|
|
103
|
+
fieldsAround(context: Pick<CallContext, 'scope' | 'owners'>): ReadonlyMap<string, string>;
|
|
104
|
+
/**
|
|
105
|
+
* @brief Records a `calls` edge from `from` to each function its calls reach.
|
|
106
|
+
*
|
|
107
|
+
* @param from - Node of the calling function.
|
|
108
|
+
* @param calls - The calls in its body.
|
|
109
|
+
* @param context - Where the function is.
|
|
110
|
+
*/
|
|
111
|
+
link(from: NodeRef, calls: readonly RawCall[], context: CallContext): void;
|
|
112
|
+
/**
|
|
113
|
+
* @brief The function one call reaches.
|
|
114
|
+
*
|
|
115
|
+
* @param call - The call.
|
|
116
|
+
* @param context - Where the calling function is.
|
|
117
|
+
* @returns The function, or `null` when the call reaches none or more than one.
|
|
118
|
+
*/
|
|
119
|
+
private resolve;
|
|
120
|
+
/**
|
|
121
|
+
* @brief Where a bare call looks for a free function. A file whose imports the scan does not read only sees its
|
|
122
|
+
* own directory, so a common name never reaches across the repository.
|
|
123
|
+
*
|
|
124
|
+
* @param scope - Where the call is.
|
|
125
|
+
* @returns The same scope, limited to the directory of the file when its imports are unknown.
|
|
126
|
+
*/
|
|
127
|
+
private freeFunctionScope;
|
|
128
|
+
/**
|
|
129
|
+
* @brief The method a call through a variable reaches, from the declared type of that variable.
|
|
130
|
+
*
|
|
131
|
+
* @param call - A `member` call.
|
|
132
|
+
* @param context - Where the calling function is.
|
|
133
|
+
* @returns The method, or `null` when the type of the variable is unknown or names no single method.
|
|
134
|
+
*/
|
|
135
|
+
private resolveMember;
|
|
136
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type SymbolKind } from '../../model';
|
|
2
2
|
import type { Node, Query } from 'web-tree-sitter';
|
|
3
|
+
import { type RawCall } from './calls';
|
|
4
|
+
import type { ImportRequest } from './imports';
|
|
3
5
|
import type { LanguageSpec } from './language';
|
|
4
6
|
/**
|
|
5
7
|
* One parameter as declared.
|
|
@@ -51,6 +53,8 @@ export interface RawField {
|
|
|
51
53
|
* @property isStatic - True for a method called on its type rather than on an instance.
|
|
52
54
|
* @property returnsValue - True when a call to the symbol yields a value.
|
|
53
55
|
* @property inferred - True for an owner type that is not declared in this file.
|
|
56
|
+
* @property internal - True for a function only its own file can call, as the spec's `isInternal` decides.
|
|
57
|
+
* @property calls - For a function or method: the calls in its body, each once.
|
|
54
58
|
* @property children - Members nested under this symbol.
|
|
55
59
|
*/
|
|
56
60
|
export interface RawSymbol {
|
|
@@ -71,17 +75,21 @@ export interface RawSymbol {
|
|
|
71
75
|
isStatic: boolean;
|
|
72
76
|
returnsValue: boolean;
|
|
73
77
|
readonly inferred: boolean;
|
|
78
|
+
readonly internal: boolean;
|
|
79
|
+
readonly calls: readonly RawCall[];
|
|
74
80
|
readonly children: RawSymbol[];
|
|
75
81
|
}
|
|
76
82
|
/**
|
|
77
|
-
* Symbols
|
|
83
|
+
* Symbols, package name and imports extracted from one source file.
|
|
78
84
|
*
|
|
79
85
|
* @property symbols - Top-level symbols of the file, each with its members nested under it.
|
|
80
86
|
* @property packageName - Package or namespace the file declares, or `null` when the language has none.
|
|
87
|
+
* @property imports - The files the file imports, as it writes them. Empty for a language without `imports`.
|
|
81
88
|
*/
|
|
82
89
|
export interface ExtractedFile {
|
|
83
90
|
readonly symbols: RawSymbol[];
|
|
84
91
|
readonly packageName: string | null;
|
|
92
|
+
readonly imports: readonly ImportRequest[];
|
|
85
93
|
}
|
|
86
94
|
/**
|
|
87
95
|
* @brief Turns a parsed file into a tree of {@link RawSymbol}s, driven by a {@link LanguageSpec}.
|
|
@@ -98,7 +106,7 @@ export declare class SymbolExtractor {
|
|
|
98
106
|
* @param query - Compiled tags query of the language.
|
|
99
107
|
* @param spec - Language spec that drives the extraction.
|
|
100
108
|
* @param source - Full text of the file the tree was parsed from; node offsets index into it.
|
|
101
|
-
* @returns Symbols of the file
|
|
109
|
+
* @returns Symbols of the file, its declared package name and its imports.
|
|
102
110
|
*/
|
|
103
111
|
extract(root: Node, query: Query, spec: LanguageSpec, source: string): ExtractedFile;
|
|
104
112
|
/**
|