@g3nomaly/analyze 0.0.0-stage → 0.1.1
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/LICENSE +95 -0
- package/README.md +76 -2
- package/dist/THIRD_PARTY_LICENSES.txt +1904 -0
- package/dist/api/bundle-builder.d.ts +94 -0
- package/dist/api/bundle-cache.d.ts +73 -0
- package/dist/api/bundle-loader.d.ts +65 -0
- package/dist/api/create-docs.d.ts +91 -0
- package/dist/api/embedding.d.ts +41 -0
- package/dist/api/errors.d.ts +35 -0
- package/dist/api/list.d.ts +106 -0
- package/dist/api/options.d.ts +74 -0
- package/dist/api/refs.d.ts +136 -0
- package/dist/api/scan.d.ts +56 -0
- package/dist/api/search.d.ts +132 -0
- package/dist/api/services.d.ts +15 -0
- package/dist/api/show.d.ts +100 -0
- package/dist/api/site-reader.d.ts +19 -0
- package/dist/api/site-writer.d.ts +43 -0
- package/dist/api/source.d.ts +57 -0
- package/dist/api/target.d.ts +12 -0
- package/dist/api/template.d.ts +5 -0
- package/dist/assets/tree-sitter-c-sharp.wasm +0 -0
- package/dist/assets/tree-sitter-c.wasm +0 -0
- package/dist/assets/tree-sitter-cpp.wasm +0 -0
- package/dist/assets/tree-sitter-go.wasm +0 -0
- package/dist/assets/tree-sitter-java.wasm +0 -0
- package/dist/assets/tree-sitter-javascript.wasm +0 -0
- package/dist/assets/tree-sitter-kotlin.wasm +0 -0
- package/dist/assets/tree-sitter-php.wasm +0 -0
- package/dist/assets/tree-sitter-python.wasm +0 -0
- package/dist/assets/tree-sitter-ruby.wasm +0 -0
- package/dist/assets/tree-sitter-rust.wasm +0 -0
- package/dist/assets/tree-sitter-scala.wasm +0 -0
- package/dist/assets/tree-sitter-tsx.wasm +0 -0
- package/dist/assets/tree-sitter-typescript.wasm +0 -0
- package/dist/assets/vectors.bin +0 -0
- package/dist/assets/vocab.txt +33731 -0
- package/dist/cli.js +9317 -0
- package/dist/embeddings/abbreviations.d.ts +7 -0
- package/dist/embeddings/index-builder.d.ts +12 -0
- package/dist/embeddings/index.d.ts +10 -0
- package/dist/embeddings/model.d.ts +126 -0
- package/dist/embeddings/searcher.d.ts +84 -0
- package/dist/embeddings/vectors.d.ts +77 -0
- package/dist/embeddings/words.d.ts +46 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8747 -0
- package/dist/model/index.d.ts +788 -0
- package/dist/model/registry.d.ts +687 -0
- package/dist/query/graph.d.ts +123 -0
- package/dist/query/index.d.ts +4 -0
- package/dist/query/name-search.d.ts +65 -0
- package/dist/query/semantic.d.ts +38 -0
- package/dist/query/text.d.ts +22 -0
- package/dist/retrieval/describe.d.ts +33 -0
- package/dist/retrieval/filter.d.ts +36 -0
- package/dist/retrieval/index.d.ts +7 -0
- package/dist/retrieval/markdown.d.ts +17 -0
- package/dist/retrieval/report.d.ts +291 -0
- package/dist/retrieval/resolve.d.ts +31 -0
- package/dist/retrieval/retriever.d.ts +105 -0
- package/dist/retrieval/summary.d.ts +27 -0
- package/dist/scanner/code/doc/clean.d.ts +36 -0
- package/dist/scanner/code/doc/index.d.ts +12 -0
- package/dist/scanner/code/doc/markdown.d.ts +8 -0
- package/dist/scanner/code/doc/python.d.ts +8 -0
- package/dist/scanner/code/doc/tagged.d.ts +19 -0
- package/dist/scanner/code/doc/types.d.ts +33 -0
- package/dist/scanner/code/doc/xml.d.ts +8 -0
- package/dist/scanner/code/example.d.ts +57 -0
- package/dist/scanner/code/extract.d.ts +113 -0
- package/dist/scanner/code/grammar.d.ts +44 -0
- package/dist/scanner/code/language.d.ts +183 -0
- package/dist/scanner/code/languages/c-family.d.ts +5 -0
- package/dist/scanner/code/languages/csharp.d.ts +3 -0
- package/dist/scanner/code/languages/ecmascript.d.ts +7 -0
- package/dist/scanner/code/languages/go.d.ts +3 -0
- package/dist/scanner/code/languages/index.d.ts +33 -0
- package/dist/scanner/code/languages/java.d.ts +3 -0
- package/dist/scanner/code/languages/kotlin.d.ts +3 -0
- package/dist/scanner/code/languages/php.d.ts +3 -0
- package/dist/scanner/code/languages/python.d.ts +3 -0
- package/dist/scanner/code/languages/ruby.d.ts +3 -0
- package/dist/scanner/code/languages/rust.d.ts +3 -0
- package/dist/scanner/code/languages/scala.d.ts +3 -0
- package/dist/scanner/code/languages/shared.d.ts +36 -0
- package/dist/scanner/code/planner.d.ts +107 -0
- package/dist/scanner/code/symbols.d.ts +134 -0
- package/dist/scanner/code/types.d.ts +126 -0
- package/dist/scanner/config.d.ts +42 -0
- package/dist/scanner/content.d.ts +73 -0
- package/dist/scanner/decisions/parse.d.ts +37 -0
- package/dist/scanner/decisions/planner.d.ts +42 -0
- package/dist/scanner/docs.d.ts +69 -0
- package/dist/scanner/files.d.ts +85 -0
- package/dist/scanner/glossary/parse.d.ts +40 -0
- package/dist/scanner/glossary/planner.d.ts +49 -0
- package/dist/scanner/glossary/terms.d.ts +116 -0
- package/dist/scanner/graph/builder.d.ts +114 -0
- package/dist/scanner/highlight.d.ts +54 -0
- package/dist/scanner/ignore.d.ts +25 -0
- package/dist/scanner/index.d.ts +43 -0
- package/dist/scanner/markdown/frontmatter.d.ts +24 -0
- package/dist/scanner/markdown/links.d.ts +60 -0
- package/dist/scanner/markdown/outline.d.ts +35 -0
- package/dist/scanner/markdown/renderer.d.ts +63 -0
- package/dist/scanner/openapi/planner.d.ts +96 -0
- package/dist/scanner/packages.d.ts +28 -0
- package/dist/scanner/reporter.d.ts +10 -0
- package/dist/scanner/scanner.d.ts +66 -0
- package/dist/scanner/schema/definitions.d.ts +79 -0
- package/dist/scanner/schema/describe.d.ts +105 -0
- package/dist/scanner/schema/planner.d.ts +49 -0
- package/dist/scanner/schema/registry.d.ts +68 -0
- package/dist/scanner/skills/classify.d.ts +21 -0
- package/dist/scanner/skills/layout.d.ts +46 -0
- package/dist/scanner/skills/planner.d.ts +61 -0
- package/dist/scanner/specs.d.ts +56 -0
- package/dist/scanner/sql/catalog.d.ts +98 -0
- package/dist/scanner/sql/cursor.d.ts +112 -0
- package/dist/scanner/sql/database.d.ts +51 -0
- package/dist/scanner/sql/parse.d.ts +122 -0
- package/dist/scanner/sql/planner.d.ts +69 -0
- package/dist/scanner/sql/query.d.ts +73 -0
- package/dist/scanner/sql/registry.d.ts +63 -0
- package/dist/scanner/sql/source.d.ts +10 -0
- package/dist/scanner/sql/statements.d.ts +42 -0
- package/dist/scanner/sql/tokens.d.ts +51 -0
- package/dist/scanner/tasks/layout.d.ts +52 -0
- package/dist/scanner/tasks/planner.d.ts +130 -0
- package/dist/scanner/tasks/schema.d.ts +88 -0
- package/dist/scanner/text.d.ts +14 -0
- package/package.json +104 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type LanguageSpec } from '../language';
|
|
2
|
+
/** JavaScript, including JSX. */
|
|
3
|
+
export declare const javascript: LanguageSpec;
|
|
4
|
+
/** TypeScript without JSX. */
|
|
5
|
+
export declare const typescript: LanguageSpec;
|
|
6
|
+
/** TypeScript with JSX, in `.tsx` files. */
|
|
7
|
+
export declare const tsx: LanguageSpec;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LanguageSpec } from '../language';
|
|
2
|
+
/** Every supported language. Add a spec here to support another one. */
|
|
3
|
+
export declare const LANGUAGES: readonly LanguageSpec[];
|
|
4
|
+
/**
|
|
5
|
+
* @brief Maps files to language specs, by extension and, where languages share one, by content.
|
|
6
|
+
*
|
|
7
|
+
* Holds the specs that claim each lowercase extension, in registry order. Created with
|
|
8
|
+
* `new LanguageRegistry()` by `RepositoryScanner` in `scanner/scanner.ts`, and consumed by
|
|
9
|
+
* `CodePlanner` in `code/planner.ts`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class LanguageRegistry {
|
|
12
|
+
private readonly byExtension;
|
|
13
|
+
/**
|
|
14
|
+
* Indexes the specs by extension. Order matters: `forFile` tries them in this order.
|
|
15
|
+
*
|
|
16
|
+
* @param languages - Specs to index, in priority order. Defaults to {@link LANGUAGES}.
|
|
17
|
+
*/
|
|
18
|
+
constructor(languages?: readonly LanguageSpec[]);
|
|
19
|
+
/**
|
|
20
|
+
* True when some language claims the extension of `path`.
|
|
21
|
+
*
|
|
22
|
+
* @param path - File path; the extension is matched case-insensitively.
|
|
23
|
+
*/
|
|
24
|
+
supports(path: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The first language that accepts the source. Falls back to the last one that claims the extension.
|
|
27
|
+
*
|
|
28
|
+
* @param path - File path; its extension selects the candidates.
|
|
29
|
+
* @param source - Full text of the file, given to each candidate's `accepts`.
|
|
30
|
+
* @returns The chosen spec, or `null` when no language claims the extension.
|
|
31
|
+
*/
|
|
32
|
+
forFile(path: string, source: string): LanguageSpec | null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Node } from 'web-tree-sitter';
|
|
2
|
+
import type { DefinitionFacts, ImportContext } from '../language';
|
|
3
|
+
/**
|
|
4
|
+
* True when the declaration head contains the `static` keyword.
|
|
5
|
+
*
|
|
6
|
+
* @param facts - What the spec can inspect about the definition.
|
|
7
|
+
*/
|
|
8
|
+
export declare function hasStaticKeyword(facts: DefinitionFacts): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* @brief Walks up from a definition and reports whether it reaches one of `staticScopes`
|
|
11
|
+
* before one of `instanceScopes`. Used for Kotlin and Scala `object` members.
|
|
12
|
+
*
|
|
13
|
+
* @param node - Tree-sitter node of the definition.
|
|
14
|
+
* @param staticScopes - Node types whose members are static.
|
|
15
|
+
* @param instanceScopes - Node types whose members are instance members, which stop the walk.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isInsideScope(node: Node, staticScopes: readonly string[], instanceScopes: readonly string[]): boolean;
|
|
18
|
+
/** False for a Kotlin or Scala `object` declaration head, which declares a singleton. */
|
|
19
|
+
export declare function isNotSingleton(signature: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* `*` or `&` when a C or C++ function returns a pointer or reference, which the `type` field does not show.
|
|
22
|
+
*
|
|
23
|
+
* @param node - Function definition node.
|
|
24
|
+
* @returns One mark per pointer or reference layer, or `''` for a plain return.
|
|
25
|
+
*/
|
|
26
|
+
export declare function returnIndirection(node: Node): string;
|
|
27
|
+
/** Path of a file without its extension, for module specifiers. */
|
|
28
|
+
export declare function withoutExtension(path: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* `import pkg.Name` in the given statement shape, for languages with a declared package.
|
|
31
|
+
*
|
|
32
|
+
* @param context - What the import needs to know about the symbol.
|
|
33
|
+
* @param format - Builds the statement from the qualified name, such as `import pkg.Name;`.
|
|
34
|
+
* @returns The statement, or `null` when the file declares no package.
|
|
35
|
+
*/
|
|
36
|
+
export declare function packageImport(context: ImportContext, format: (qualifiedName: string) => string): string | null;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
import type { ConfigPlanner } from '../config';
|
|
3
|
+
import type { FileRenderer } from '../content';
|
|
4
|
+
import { type Source } from '../files';
|
|
5
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
6
|
+
import { type Reporter } from '../reporter';
|
|
7
|
+
import type { SqlPlanner } from '../sql/planner';
|
|
8
|
+
import type { SymbolExtractor } from './extract';
|
|
9
|
+
import type { GrammarLoader } from './grammar';
|
|
10
|
+
import type { LanguageRegistry } from './languages';
|
|
11
|
+
import type { SymbolPlanner } from './symbols';
|
|
12
|
+
/**
|
|
13
|
+
* @brief One source file to add.
|
|
14
|
+
*
|
|
15
|
+
* @property root - Absolute directory `path` is relative to.
|
|
16
|
+
* @property path - Path of the file below `root`, in POSIX form.
|
|
17
|
+
* @property displayPath - Path as the bundle shows it: `path` behind the prefix of its source.
|
|
18
|
+
*/
|
|
19
|
+
export interface SourceFile {
|
|
20
|
+
readonly root: string;
|
|
21
|
+
readonly path: string;
|
|
22
|
+
readonly displayPath: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @brief Adds source files and their symbols to the graph.
|
|
26
|
+
*
|
|
27
|
+
* The SQL files of a repository are no code: `DatabasePlanner` adds them. A SQL file of a skill
|
|
28
|
+
* that creates tables goes to the `SqlPlanner`.
|
|
29
|
+
*
|
|
30
|
+
* Holds the planners and loaders it delegates to: it parses a file with the
|
|
31
|
+
* grammar from `GrammarLoader`, extracts symbols with `SymbolExtractor`, and
|
|
32
|
+
* hands them to `SymbolPlanner`. Created per scan by `RepositoryScanner` in
|
|
33
|
+
* `scanner/scanner.ts`, which calls `planTree` for the code section;
|
|
34
|
+
* `SkillPlanner` in `skills/planner.ts` calls `isSource` and `planFile`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const code = new CodePlanner(graph, registry, grammars, extractor, symbols, files, sql, reporter);
|
|
38
|
+
* await code.planTree(sections.code, source);
|
|
39
|
+
*/
|
|
40
|
+
export declare class CodePlanner {
|
|
41
|
+
private readonly graph;
|
|
42
|
+
private readonly registry;
|
|
43
|
+
private readonly grammars;
|
|
44
|
+
private readonly extractor;
|
|
45
|
+
private readonly symbols;
|
|
46
|
+
private readonly files;
|
|
47
|
+
private readonly sql;
|
|
48
|
+
private readonly reporter;
|
|
49
|
+
/**
|
|
50
|
+
* Takes the graph it adds nodes to and the helpers it delegates each file to.
|
|
51
|
+
*
|
|
52
|
+
* @param graph - Graph the source nodes are added to.
|
|
53
|
+
* @param registry - Says which languages are supported and which spec reads a file.
|
|
54
|
+
* @param grammars - Loads the parser and query of a language spec.
|
|
55
|
+
* @param extractor - Extracts the raw symbols from a parsed syntax tree.
|
|
56
|
+
* @param symbols - Adds the symbols of a file below its source node.
|
|
57
|
+
* @param files - Reads the text of a file, to embed it in its node.
|
|
58
|
+
* @param sql - Adds SQL files that create tables as databases.
|
|
59
|
+
* @param reporter - Receives a warning for each file that cannot be read or parsed. Silent by default.
|
|
60
|
+
*/
|
|
61
|
+
constructor(graph: GraphBuilder, registry: LanguageRegistry, grammars: GrammarLoader, extractor: SymbolExtractor, symbols: SymbolPlanner, files: FileRenderer, sql: SqlPlanner, reporter?: Reporter);
|
|
62
|
+
/**
|
|
63
|
+
* @brief Tells whether a file is source code, whether or not the scanner can read its symbols.
|
|
64
|
+
*
|
|
65
|
+
* @param path - Path of the file, with its extension.
|
|
66
|
+
*/
|
|
67
|
+
isSource(path: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* @brief Adds every file of `source` that declares a class or a function, in folders below `section`.
|
|
70
|
+
*
|
|
71
|
+
* Files in unsupported languages are skipped. JSON, TOML and YAML files go to `configs`, in the same
|
|
72
|
+
* pass, so the tree stays in path order.
|
|
73
|
+
*
|
|
74
|
+
* @param section - Node the folders are added below.
|
|
75
|
+
* @param source - Directory whose files are read.
|
|
76
|
+
* @param configs - Plans the JSON, TOML and YAML files. Without it they are skipped.
|
|
77
|
+
*/
|
|
78
|
+
planTree(section: NodeRef, source: Source, configs?: ConfigPlanner): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* @brief Adds one file below `parent` with its text embedded, whatever it declares.
|
|
81
|
+
*
|
|
82
|
+
* A SQL file that creates tables is added as a database instead.
|
|
83
|
+
*
|
|
84
|
+
* @param parent - Node the file is added below.
|
|
85
|
+
* @param file - File to add.
|
|
86
|
+
* @returns Node of the file, or of the database it creates.
|
|
87
|
+
*/
|
|
88
|
+
planFile(parent: NodeRef, file: SourceFile): Promise<NodeRef>;
|
|
89
|
+
/**
|
|
90
|
+
* @brief Adds a `source` node for the file below `parent`, registers its display path, and plans its symbols.
|
|
91
|
+
*
|
|
92
|
+
* @param parent - Node the file is added below.
|
|
93
|
+
* @param file - File to add.
|
|
94
|
+
* @param extracted - Symbols of the file, or `null` to add the file without symbols.
|
|
95
|
+
* @param embedText - Whether the node carries the file's full text.
|
|
96
|
+
* @returns Node of the file.
|
|
97
|
+
*/
|
|
98
|
+
private add;
|
|
99
|
+
/**
|
|
100
|
+
* @brief Reads the symbols of a file.
|
|
101
|
+
*
|
|
102
|
+
* @param file - File to read.
|
|
103
|
+
* @returns Symbols with their language spec, or `null` when the language is unsupported, the file is
|
|
104
|
+
* missing or larger than `MAX_SOURCE_BYTES`, or it cannot be parsed.
|
|
105
|
+
*/
|
|
106
|
+
private extract;
|
|
107
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { type NodeRef } from '../../model';
|
|
2
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
3
|
+
import type { CodeHighlighter } from '../highlight';
|
|
4
|
+
import type { ProseResolvers } from '../markdown/links';
|
|
5
|
+
import type { MarkdownRenderer } from '../markdown/renderer';
|
|
6
|
+
import type { RawSymbol } from './extract';
|
|
7
|
+
import { type LanguageSpec } from './language';
|
|
8
|
+
import type { CallableIndex, TypeIndex, TypeLinker } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* @brief What the planner needs to know about the file a symbol tree comes from.
|
|
11
|
+
*
|
|
12
|
+
* @property spec - Language spec that reads the file.
|
|
13
|
+
* @property path - Display path of the file: its path below the source root, behind the source's prefix.
|
|
14
|
+
* @property packageName - Package or namespace the file declares, or `null`.
|
|
15
|
+
*/
|
|
16
|
+
export interface FileContext {
|
|
17
|
+
readonly spec: LanguageSpec;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly packageName: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @brief Adds the symbols of a file to the graph: one node per class or function,
|
|
23
|
+
* with a child node per parameter and field.
|
|
24
|
+
*
|
|
25
|
+
* Type names in signatures become links to the types they name. Holds the graph, the renderers,
|
|
26
|
+
* and the indexes and linkers it registers into and links through. Created per scan by
|
|
27
|
+
* `RepositoryScanner` in `scanner/scanner.ts`; `CodePlanner` in `planner.ts` calls `plan` for
|
|
28
|
+
* each file it extracts symbols from.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const symbols = new SymbolPlanner(graph, highlighter, markdown, types, callables, linker, resolvers);
|
|
32
|
+
* symbols.plan(fileRef, { spec, path: 'src/app.ts', packageName: null }, extracted.symbols);
|
|
33
|
+
*/
|
|
34
|
+
export declare class SymbolPlanner {
|
|
35
|
+
private readonly graph;
|
|
36
|
+
private readonly highlighter;
|
|
37
|
+
private readonly markdown;
|
|
38
|
+
private readonly types;
|
|
39
|
+
private readonly callables;
|
|
40
|
+
private readonly linker;
|
|
41
|
+
private readonly resolvers;
|
|
42
|
+
/**
|
|
43
|
+
* Takes the graph and renderers it writes with, and the indexes and linkers that resolve names.
|
|
44
|
+
*
|
|
45
|
+
* @param graph - Graph the symbol nodes are added to.
|
|
46
|
+
* @param highlighter - Highlights signatures and examples as HTML.
|
|
47
|
+
* @param markdown - Renders doc descriptions as HTML.
|
|
48
|
+
* @param types - Index of type declarations, where each new type is registered.
|
|
49
|
+
* @param callables - Index of functions and methods, where each new callable is registered.
|
|
50
|
+
* @param linker - Links the type names of signatures to their declarations.
|
|
51
|
+
* @param resolvers - Resolves the names in prose descriptions to links.
|
|
52
|
+
*/
|
|
53
|
+
constructor(graph: GraphBuilder, highlighter: CodeHighlighter, markdown: MarkdownRenderer, types: TypeIndex, callables: CallableIndex, linker: TypeLinker, resolvers: ProseResolvers);
|
|
54
|
+
/**
|
|
55
|
+
* @brief Adds `symbols` and everything inside them below the file node `fileRef`.
|
|
56
|
+
*
|
|
57
|
+
* @param fileRef - Node of the file the symbols are in.
|
|
58
|
+
* @param file - Language spec and path of the file.
|
|
59
|
+
* @param symbols - Top-level symbols of the file, in file order.
|
|
60
|
+
*/
|
|
61
|
+
plan(fileRef: NodeRef, file: FileContext, symbols: readonly RawSymbol[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* @brief Adds one symbol node with its parameter and field nodes, registers it in the type or
|
|
64
|
+
* callable index, and recurses into its children.
|
|
65
|
+
*
|
|
66
|
+
* @param symbol - Symbol to add, as the extractor found it.
|
|
67
|
+
* @param scope - Where the symbol sits in the file.
|
|
68
|
+
*/
|
|
69
|
+
private planSymbol;
|
|
70
|
+
/**
|
|
71
|
+
* @brief Builds the content of a symbol node: highlighted signature, rendered description,
|
|
72
|
+
* return value, tags and example.
|
|
73
|
+
*
|
|
74
|
+
* Records `extends` edges for its heritage.
|
|
75
|
+
*
|
|
76
|
+
* @param symbol - Symbol the content is built for.
|
|
77
|
+
* @param doc - Parsed doc comment of the symbol.
|
|
78
|
+
* @param scope - Where the symbol sits in the file.
|
|
79
|
+
* @param typeScope - Scope that the names of the symbol resolve in.
|
|
80
|
+
* @param self - Node of the symbol itself, where the edges start.
|
|
81
|
+
* @returns Content of the symbol node.
|
|
82
|
+
*/
|
|
83
|
+
private symbolContent;
|
|
84
|
+
/**
|
|
85
|
+
* @brief Builds the content of a parameter or field node: linked type, default, optional flag and rendered description.
|
|
86
|
+
*
|
|
87
|
+
* @param declaration - Parameter or field to build the content of.
|
|
88
|
+
* @param self - Node of the parameter or field itself, where the type edge starts.
|
|
89
|
+
* @param file - File the declaration is in.
|
|
90
|
+
* @param typeScope - Scope that the type name resolves in.
|
|
91
|
+
* @returns Content of the node.
|
|
92
|
+
*/
|
|
93
|
+
private declarationContent;
|
|
94
|
+
/**
|
|
95
|
+
* @brief Builds the return value of a symbol from its declared return type and `@returns` tag.
|
|
96
|
+
*
|
|
97
|
+
* @param symbol - Symbol whose return value is built.
|
|
98
|
+
* @param doc - Parsed doc comment of the symbol.
|
|
99
|
+
* @param self - Node of the symbol, where the type edge starts.
|
|
100
|
+
* @param file - File the symbol is in.
|
|
101
|
+
* @param typeScope - Scope that the type name resolves in.
|
|
102
|
+
* @returns The return value, or `null` when there is no tag and the symbol returns no typed value.
|
|
103
|
+
*/
|
|
104
|
+
private returns;
|
|
105
|
+
/**
|
|
106
|
+
* @brief Builds the example of a symbol: the documented one, or one generated from its signature.
|
|
107
|
+
*
|
|
108
|
+
* @param symbol - Symbol the example is for.
|
|
109
|
+
* @param scope - Where the symbol sits in the file.
|
|
110
|
+
* @param documented - Example from the doc comment, or `null` when there is none.
|
|
111
|
+
* @returns The highlighted example with its origin, or `null` when none can be built.
|
|
112
|
+
*/
|
|
113
|
+
private example;
|
|
114
|
+
/**
|
|
115
|
+
* @brief Renders a plain doc tag. The subject of a `throws` tag links to the types it names.
|
|
116
|
+
*
|
|
117
|
+
* @param tag - Tag to render.
|
|
118
|
+
* @param self - Node of the symbol the tag belongs to.
|
|
119
|
+
* @param file - File the symbol is in.
|
|
120
|
+
* @param typeScope - Scope that the names in the tag resolve in.
|
|
121
|
+
* @returns The tag as the symbol's page shows it.
|
|
122
|
+
*/
|
|
123
|
+
private tag;
|
|
124
|
+
/**
|
|
125
|
+
* @brief Renders a description. Inline code that names a type or function, and glossary terms, become links.
|
|
126
|
+
*
|
|
127
|
+
* @param markdown - Markdown to render.
|
|
128
|
+
* @param from - Node the description belongs to. Links start here.
|
|
129
|
+
* @param file - File the description is in.
|
|
130
|
+
* @param typeScope - Scope that the names in the description resolve in.
|
|
131
|
+
* @returns The rendered HTML, `''` for an empty description.
|
|
132
|
+
*/
|
|
133
|
+
private html;
|
|
134
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { EdgeKind, LinkedText, NodeRef } from '../../model';
|
|
2
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
3
|
+
/**
|
|
4
|
+
* @brief Where a type name is used. Decides which declaration it means.
|
|
5
|
+
*
|
|
6
|
+
* @property path - Display path of the file the name is in. `null` for a name in prose, which has no file of its own.
|
|
7
|
+
* @property family - Language family of the name. `null` matches every language.
|
|
8
|
+
* @property typeParameters - Type parameters in scope, such as `T`. They are never linked.
|
|
9
|
+
*/
|
|
10
|
+
export interface TypeScope {
|
|
11
|
+
readonly path: string | null;
|
|
12
|
+
readonly family: string | null;
|
|
13
|
+
readonly typeParameters: ReadonlySet<string>;
|
|
14
|
+
}
|
|
15
|
+
/** Scope of a name in a document: any language, no file. */
|
|
16
|
+
export declare const PROSE_SCOPE: TypeScope;
|
|
17
|
+
/**
|
|
18
|
+
* @brief Every class, interface, struct, enum, trait and type alias of the scan, by name.
|
|
19
|
+
*
|
|
20
|
+
* Holds every declaration of each name. Created per scan by `RepositoryScanner` in
|
|
21
|
+
* `scanner/scanner.ts`; `SymbolPlanner` in `symbols.ts` registers each type it adds,
|
|
22
|
+
* and {@link TypeLinker} resolves names against it. Created with `new TypeIndex()`.
|
|
23
|
+
*
|
|
24
|
+
* @property byName - Declarations of each name.
|
|
25
|
+
*/
|
|
26
|
+
export declare class TypeIndex {
|
|
27
|
+
private readonly byName;
|
|
28
|
+
/**
|
|
29
|
+
* @brief Adds a type declaration under its name.
|
|
30
|
+
*
|
|
31
|
+
* @param name - Name the type is declared with.
|
|
32
|
+
* @param ref - Node of the declaration.
|
|
33
|
+
* @param path - Display path of the file that declares it.
|
|
34
|
+
* @param family - Language family of that file, from `familyOf`.
|
|
35
|
+
*/
|
|
36
|
+
register(name: string, ref: NodeRef, path: string, family: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* @brief The declaration a name refers to, or `null` when there is none or the name is ambiguous.
|
|
39
|
+
*
|
|
40
|
+
* A declaration in the same file wins, then the one whose directory is closest.
|
|
41
|
+
*
|
|
42
|
+
* @param name - Identifier to resolve.
|
|
43
|
+
* @param scope - Where the name is used.
|
|
44
|
+
* @returns The node of the declaration, or `null`.
|
|
45
|
+
*/
|
|
46
|
+
resolve(name: string, scope: TypeScope): NodeRef | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @brief Every function and method of the scan, by name and by `Owner.name`. Lets
|
|
50
|
+
* prose refer to a function the way it refers to a type.
|
|
51
|
+
*
|
|
52
|
+
* Holds every declaration of each key. Created per scan by `RepositoryScanner` in
|
|
53
|
+
* `scanner/scanner.ts`; `SymbolPlanner` in `symbols.ts` registers each function and
|
|
54
|
+
* method it adds, and {@link TypeLinker.mention} resolves inline code against it.
|
|
55
|
+
* Created with `new CallableIndex()`.
|
|
56
|
+
*
|
|
57
|
+
* @property byName - Declarations of each key: the name, and `Owner.name` for a method.
|
|
58
|
+
*/
|
|
59
|
+
export declare class CallableIndex {
|
|
60
|
+
private readonly byName;
|
|
61
|
+
/**
|
|
62
|
+
* @brief Adds a function or method under its name and, when it has an owner, under `Owner.name`.
|
|
63
|
+
*
|
|
64
|
+
* @param name - Name the function is declared with.
|
|
65
|
+
* @param owner - Name of the type or namespace it is declared in, or `null`.
|
|
66
|
+
* @param ref - Node of the declaration.
|
|
67
|
+
* @param path - Display path of its file.
|
|
68
|
+
* @param family - Language family of its file, from `familyOf`.
|
|
69
|
+
*/
|
|
70
|
+
register(name: string, owner: string | null, ref: NodeRef, path: string, family: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* @brief The function a piece of inline code names.
|
|
73
|
+
*
|
|
74
|
+
* @param text - Inline code, such as `choose_route()` or `Invoice.add`.
|
|
75
|
+
* @param scope - Where the code is used.
|
|
76
|
+
* @returns The function, or `null` when the text names none or more than one.
|
|
77
|
+
*/
|
|
78
|
+
resolve(text: string, scope: TypeScope): NodeRef | null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @brief Turns type names in source text into links between nodes, and records each link as an edge.
|
|
82
|
+
*
|
|
83
|
+
* Holds the type and callable indexes it resolves names against and the graph it adds
|
|
84
|
+
* edges to. Created per scan by `RepositoryScanner` in `scanner/scanner.ts`; used by
|
|
85
|
+
* `SymbolPlanner` in `symbols.ts` for signatures and by the resolvers in
|
|
86
|
+
* `markdown/links.ts` for inline code in prose.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const linker = new TypeLinker(new TypeIndex(), new CallableIndex(), graph);
|
|
90
|
+
* const type = linker.link('Promise<Booking>', methodRef, 'returns', scope);
|
|
91
|
+
*/
|
|
92
|
+
export declare class TypeLinker {
|
|
93
|
+
private readonly index;
|
|
94
|
+
private readonly callables;
|
|
95
|
+
private readonly graph;
|
|
96
|
+
/**
|
|
97
|
+
* Takes the indexes it resolves names against and the graph it adds edges to.
|
|
98
|
+
*
|
|
99
|
+
* @param index - Type declarations the names resolve against.
|
|
100
|
+
* @param callables - Functions and methods the inline code resolves against.
|
|
101
|
+
* @param graph - Graph the edges are added to.
|
|
102
|
+
*/
|
|
103
|
+
constructor(index: TypeIndex, callables: CallableIndex, graph: GraphBuilder);
|
|
104
|
+
/**
|
|
105
|
+
* @brief Links every known type name in `text`, such as `Booking` in `Promise<Booking>`.
|
|
106
|
+
*
|
|
107
|
+
* Records one `relation` edge from `from` to each type it finds.
|
|
108
|
+
*
|
|
109
|
+
* @param text - Source text to scan for names.
|
|
110
|
+
* @param from - Node the text belongs to. The edges start here.
|
|
111
|
+
* @param relation - Kind of edge to record.
|
|
112
|
+
* @param scope - Where the names are used.
|
|
113
|
+
* @returns The text with the links to the types it names.
|
|
114
|
+
*/
|
|
115
|
+
link(text: string, from: NodeRef, relation: EdgeKind, scope: TypeScope): LinkedText;
|
|
116
|
+
/**
|
|
117
|
+
* @brief The type or function that inline code names, and an edge to it.
|
|
118
|
+
*
|
|
119
|
+
* @param text - Inline code, such as `Booking` or `choose_route()`.
|
|
120
|
+
* @param from - Node the code is written in. The edge starts here.
|
|
121
|
+
* @param scope - Where the code is used.
|
|
122
|
+
* @param relation - Kind of edge to record, `mentions` by default.
|
|
123
|
+
* @returns The node the code names, or `null` when it names none, more than one, or `from` itself.
|
|
124
|
+
*/
|
|
125
|
+
mention(text: string, from: NodeRef, scope: TypeScope, relation?: EdgeKind): NodeRef | null;
|
|
126
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { NodeRef } from '../model';
|
|
2
|
+
import type { FileRenderer } from './content';
|
|
3
|
+
import type { Source } from './files';
|
|
4
|
+
import type { GraphBuilder } from './graph/builder';
|
|
5
|
+
import type { ProseResolvers } from './markdown/links';
|
|
6
|
+
import type { SpecPlanner } from './specs';
|
|
7
|
+
/**
|
|
8
|
+
* @brief Adds the JSON, TOML and YAML files of the code section to the graph, in the folders they are in.
|
|
9
|
+
*
|
|
10
|
+
* A file that is an OpenAPI document or a JSON Schema goes to the `SpecPlanner`, which adds its
|
|
11
|
+
* operations and definitions. Every other file becomes a page that shows it as it is. Created by
|
|
12
|
+
* `RepositoryScanner` for every scan and handed to `CodePlanner`, which calls `planFile` for each
|
|
13
|
+
* file `handles` accepts, in the same pass as the source files so the tree stays in path order.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const configs = new ConfigPlanner(graph, files, resolvers, specs);
|
|
17
|
+
* if (configs.handles(path)) await configs.planFile(section, source, path);
|
|
18
|
+
*/
|
|
19
|
+
export declare class ConfigPlanner {
|
|
20
|
+
private readonly graph;
|
|
21
|
+
private readonly files;
|
|
22
|
+
private readonly resolvers;
|
|
23
|
+
private readonly specs;
|
|
24
|
+
/**
|
|
25
|
+
* @brief Keeps the graph to add to, the renderer of plain files and the planner of specs.
|
|
26
|
+
*
|
|
27
|
+
* @param files - Renders a plain file to its page.
|
|
28
|
+
* @param resolvers - Resolves the links of each page.
|
|
29
|
+
* @param specs - Plans OpenAPI documents and JSON Schemas.
|
|
30
|
+
*/
|
|
31
|
+
constructor(graph: GraphBuilder, files: FileRenderer, resolvers: ProseResolvers, specs: SpecPlanner);
|
|
32
|
+
/** Tells whether a file is a JSON, TOML or YAML file, by its extension. */
|
|
33
|
+
handles(path: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @brief Adds one JSON, TOML or YAML file below the folder of its directory: as a spec when it is one, else as a page.
|
|
36
|
+
*
|
|
37
|
+
* @param section - Node of the code section.
|
|
38
|
+
* @param source - Directory the file is in.
|
|
39
|
+
* @param path - Path of the file inside the source, accepted by `handles`.
|
|
40
|
+
*/
|
|
41
|
+
planFile(section: NodeRef, { root, prefix }: Source, path: string): Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { FileContent } from '../model';
|
|
2
|
+
import type { CodeHighlighter } from './highlight';
|
|
3
|
+
import type { LinkResolver, MarkdownRenderer } from './markdown/renderer';
|
|
4
|
+
/**
|
|
5
|
+
* @brief A file as its page shows it.
|
|
6
|
+
*
|
|
7
|
+
* @property title - Frontmatter `title` or `name`, else the first heading, else the file name.
|
|
8
|
+
* @property description - Frontmatter `description`, or `''`.
|
|
9
|
+
* @property content - What the page shows of the file: rendered markdown, highlighted text or an image.
|
|
10
|
+
*/
|
|
11
|
+
export interface RenderedFile {
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly content: FileContent;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @brief Tells whether a file is markdown or MDX, by its extension.
|
|
18
|
+
*
|
|
19
|
+
* @param path - Path of the file.
|
|
20
|
+
* @returns `true` for a `.md`, `.markdown` or `.mdx` file.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isMarkdown(path: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* @brief Reads an image file into a `data:` URI.
|
|
25
|
+
*
|
|
26
|
+
* @param absolutePath - Absolute path of the image file.
|
|
27
|
+
* @returns The `data:` URI, or `null` when the file is no image, is missing, or is larger than `MAX_IMAGE_BYTES`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function imageDataUri(absolutePath: string): Promise<string | null>;
|
|
30
|
+
/**
|
|
31
|
+
* @brief Turns a file of any type into what its page shows: rendered markdown,
|
|
32
|
+
* highlighted text or an image.
|
|
33
|
+
*
|
|
34
|
+
* Holds the markdown renderer and the code highlighter it uses. Created by `RepositoryScanner`
|
|
35
|
+
* with `new FileRenderer(markdown, highlighter)`, and used by the planners of the docs, skills,
|
|
36
|
+
* code, glossary, decisions, JSON Schema and tasks sections.
|
|
37
|
+
*/
|
|
38
|
+
export declare class FileRenderer {
|
|
39
|
+
private readonly markdownRenderer;
|
|
40
|
+
private readonly highlighter;
|
|
41
|
+
/**
|
|
42
|
+
* Keeps the renderer and the highlighter for every file it renders.
|
|
43
|
+
*
|
|
44
|
+
* @param markdownRenderer - Renders markdown to HTML and collects its headings.
|
|
45
|
+
* @param highlighter - Highlights text files by their language.
|
|
46
|
+
*/
|
|
47
|
+
constructor(markdownRenderer: MarkdownRenderer, highlighter: CodeHighlighter);
|
|
48
|
+
/**
|
|
49
|
+
* @brief Reads a file and renders it by its type.
|
|
50
|
+
*
|
|
51
|
+
* @param absolutePath - Absolute path of the file.
|
|
52
|
+
* @param resolver - Rewrites the links of a markdown file.
|
|
53
|
+
* @returns The title, description and content of the file.
|
|
54
|
+
*/
|
|
55
|
+
render(absolutePath: string, resolver?: LinkResolver): Promise<RenderedFile>;
|
|
56
|
+
/**
|
|
57
|
+
* @brief Renders markdown that is already read. `fallbackTitle` is used when the text names no title.
|
|
58
|
+
*
|
|
59
|
+
* @param source - Markdown source, with its frontmatter if it has any.
|
|
60
|
+
* @param fallbackTitle - Title used when neither the frontmatter nor the text names one.
|
|
61
|
+
* @param resolver - Rewrites the links of the markdown.
|
|
62
|
+
* @param mdx - Whether the source is MDX, whose `import` and `export` lines are removed first.
|
|
63
|
+
* @returns The title, description and content of the file.
|
|
64
|
+
*/
|
|
65
|
+
markdown(source: string, fallbackTitle: string, resolver?: LinkResolver, mdx?: boolean): Promise<RenderedFile>;
|
|
66
|
+
/**
|
|
67
|
+
* @brief Reads a file as text, highlighted by its extension when it is small enough, or omitted when it is large or binary.
|
|
68
|
+
*
|
|
69
|
+
* @param absolutePath - Absolute path of the file.
|
|
70
|
+
* @returns The highlighted text, or an `omitted` content with its reason and size.
|
|
71
|
+
*/
|
|
72
|
+
text(absolutePath: string): Promise<FileContent>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief One decision as the decision log writes it.
|
|
3
|
+
*
|
|
4
|
+
* @property id - Number or id in front of the title, such as `3` or `ADR-0003`. `''` when the title has none.
|
|
5
|
+
* @property title - Title of the decision, without its id or date.
|
|
6
|
+
* @property status - As written, such as `accepted`. `''` when the decision states none.
|
|
7
|
+
* @property date - As written. `''` when the decision states none.
|
|
8
|
+
* @property body - Markdown of the decision without its heading, status line and date line.
|
|
9
|
+
*/
|
|
10
|
+
export interface ParsedDecision {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly status: string;
|
|
14
|
+
readonly date: string;
|
|
15
|
+
readonly body: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @brief A decision log split into its intro and its decisions.
|
|
19
|
+
*
|
|
20
|
+
* @property intro - Markdown of everything in front of the first decision, with the title.
|
|
21
|
+
* @property decisions - The decisions in file order.
|
|
22
|
+
*/
|
|
23
|
+
export interface ParsedDecisions {
|
|
24
|
+
readonly intro: string;
|
|
25
|
+
readonly decisions: readonly ParsedDecision[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @brief Reads the decisions of a decision log.
|
|
29
|
+
*
|
|
30
|
+
* Each heading of the highest level below the title starts one decision. The heading may carry a
|
|
31
|
+
* number or a date in front of the title. `Status:` and `Date:` lines at the top of a decision
|
|
32
|
+
* become its status and date.
|
|
33
|
+
*
|
|
34
|
+
* @param markdown - The decision log without frontmatter.
|
|
35
|
+
* @returns The decisions in file order and the text in front of them.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseDecisions(markdown: string): ParsedDecisions;
|