@g3nomaly/analyze 0.0.0-stage → 0.1.0
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 +71 -2
- package/dist/THIRD_PARTY_LICENSES.txt +1904 -0
- package/dist/api/bundle-builder.d.ts +75 -0
- package/dist/api/bundle-cache.d.ts +70 -0
- package/dist/api/bundle-loader.d.ts +58 -0
- package/dist/api/create-docs.d.ts +72 -0
- package/dist/api/embedding.d.ts +32 -0
- package/dist/api/errors.d.ts +28 -0
- package/dist/api/list.d.ts +106 -0
- package/dist/api/options.d.ts +78 -0
- package/dist/api/refs.d.ts +133 -0
- package/dist/api/scan.d.ts +44 -0
- package/dist/api/search.d.ts +126 -0
- package/dist/api/services.d.ts +7 -0
- package/dist/api/show.d.ts +104 -0
- package/dist/api/site-reader.d.ts +11 -0
- package/dist/api/site-writer.d.ts +20 -0
- package/dist/api/source.d.ts +46 -0
- package/dist/api/target.d.ts +10 -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 +8885 -0
- package/dist/embeddings/abbreviations.d.ts +7 -0
- package/dist/embeddings/index-builder.d.ts +10 -0
- package/dist/embeddings/index.d.ts +10 -0
- package/dist/embeddings/model.d.ts +113 -0
- package/dist/embeddings/searcher.d.ts +67 -0
- package/dist/embeddings/vectors.d.ts +75 -0
- package/dist/embeddings/words.d.ts +42 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8329 -0
- package/dist/model/index.d.ts +560 -0
- package/dist/model/registry.d.ts +494 -0
- package/dist/query/graph.d.ts +66 -0
- package/dist/query/index.d.ts +4 -0
- package/dist/query/name-search.d.ts +47 -0
- package/dist/query/semantic.d.ts +30 -0
- package/dist/query/text.d.ts +22 -0
- package/dist/retrieval/describe.d.ts +26 -0
- package/dist/retrieval/filter.d.ts +17 -0
- package/dist/retrieval/index.d.ts +7 -0
- package/dist/retrieval/markdown.d.ts +16 -0
- package/dist/retrieval/report.d.ts +214 -0
- package/dist/retrieval/resolve.d.ts +27 -0
- package/dist/retrieval/retriever.d.ts +94 -0
- package/dist/retrieval/summary.d.ts +24 -0
- package/dist/scanner/code/doc/clean.d.ts +10 -0
- package/dist/scanner/code/doc/index.d.ts +6 -0
- package/dist/scanner/code/doc/markdown.d.ts +3 -0
- package/dist/scanner/code/doc/python.d.ts +3 -0
- package/dist/scanner/code/doc/tagged.d.ts +10 -0
- package/dist/scanner/code/doc/types.d.ts +22 -0
- package/dist/scanner/code/doc/xml.d.ts +3 -0
- package/dist/scanner/code/example.d.ts +36 -0
- package/dist/scanner/code/extract.d.ts +78 -0
- package/dist/scanner/code/grammar.d.ts +29 -0
- package/dist/scanner/code/language.d.ts +149 -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 +19 -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 +17 -0
- package/dist/scanner/code/planner.d.ts +71 -0
- package/dist/scanner/code/symbols.d.ts +68 -0
- package/dist/scanner/code/types.d.ts +93 -0
- package/dist/scanner/content.d.ts +38 -0
- package/dist/scanner/decisions/parse.d.ts +28 -0
- package/dist/scanner/decisions/planner.d.ts +30 -0
- package/dist/scanner/docs.d.ts +52 -0
- package/dist/scanner/files.d.ts +60 -0
- package/dist/scanner/glossary/parse.d.ts +30 -0
- package/dist/scanner/glossary/planner.d.ts +42 -0
- package/dist/scanner/glossary/terms.d.ts +86 -0
- package/dist/scanner/graph/builder.d.ts +55 -0
- package/dist/scanner/highlight.d.ts +31 -0
- package/dist/scanner/index.d.ts +40 -0
- package/dist/scanner/markdown/frontmatter.d.ts +9 -0
- package/dist/scanner/markdown/links.d.ts +50 -0
- package/dist/scanner/markdown/outline.d.ts +27 -0
- package/dist/scanner/markdown/renderer.d.ts +44 -0
- package/dist/scanner/openapi/planner.d.ts +84 -0
- package/dist/scanner/reporter.d.ts +7 -0
- package/dist/scanner/scanner.d.ts +52 -0
- package/dist/scanner/schema/definitions.d.ts +69 -0
- package/dist/scanner/schema/describe.d.ts +79 -0
- package/dist/scanner/schema/planner.d.ts +46 -0
- package/dist/scanner/schema/registry.d.ts +61 -0
- package/dist/scanner/skills/classify.d.ts +20 -0
- package/dist/scanner/skills/layout.d.ts +28 -0
- package/dist/scanner/skills/planner.d.ts +46 -0
- package/dist/scanner/specs.d.ts +50 -0
- package/dist/scanner/sql/catalog.d.ts +84 -0
- package/dist/scanner/sql/cursor.d.ts +107 -0
- package/dist/scanner/sql/database.d.ts +48 -0
- package/dist/scanner/sql/parse.d.ts +87 -0
- package/dist/scanner/sql/planner.d.ts +65 -0
- package/dist/scanner/sql/query.d.ts +60 -0
- package/dist/scanner/sql/registry.d.ts +49 -0
- package/dist/scanner/sql/source.d.ts +9 -0
- package/dist/scanner/sql/statements.d.ts +36 -0
- package/dist/scanner/sql/tokens.d.ts +38 -0
- package/dist/scanner/tasks/layout.d.ts +40 -0
- package/dist/scanner/tasks/planner.d.ts +75 -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,149 @@
|
|
|
1
|
+
import type { SymbolKind } from '../../model';
|
|
2
|
+
import type { Node } from 'web-tree-sitter';
|
|
3
|
+
/**
|
|
4
|
+
* Doc comment dialect.
|
|
5
|
+
* - `tagged`: `@param`-style tags (JSDoc, Javadoc, Doxygen, PHPDoc, KDoc, Scaladoc).
|
|
6
|
+
* - `yard`: `tagged`, with the title of an `@example` on the tag line.
|
|
7
|
+
* - `markdown`: free markdown with headed sections (rustdoc, godoc).
|
|
8
|
+
* - `python`: docstrings in Google, NumPy or reST layout.
|
|
9
|
+
* - `xml`: C# XML documentation.
|
|
10
|
+
*/
|
|
11
|
+
export type DocStyle = 'tagged' | 'yard' | 'markdown' | 'python' | 'xml';
|
|
12
|
+
/** What a language spec can inspect when it classifies one definition. */
|
|
13
|
+
export interface DefinitionFacts {
|
|
14
|
+
readonly node: Node;
|
|
15
|
+
/** Declaration head, without the body. */
|
|
16
|
+
readonly signature: string;
|
|
17
|
+
readonly annotations: readonly string[];
|
|
18
|
+
/** Declared return type text, when the grammar exposes one. */
|
|
19
|
+
readonly returnType: string | null;
|
|
20
|
+
/** True when the parameter list starts with a receiver such as `self`. */
|
|
21
|
+
readonly hasReceiver: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** What an import hook knows about the symbol an example uses. */
|
|
24
|
+
export interface ImportContext {
|
|
25
|
+
/** Root-relative path of the file that declares the symbol. */
|
|
26
|
+
readonly filePath: string;
|
|
27
|
+
/** Outermost symbol around the one the example uses: the class of a method, or the function itself. */
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly kind: SymbolKind;
|
|
30
|
+
readonly modifiers: readonly string[];
|
|
31
|
+
/** Package or namespace the file declares with a statement, such as Java's `package a.b;`. */
|
|
32
|
+
readonly packageName: string | null;
|
|
33
|
+
}
|
|
34
|
+
/** How a language spells a call. Drives generated examples. */
|
|
35
|
+
export interface CallStyle {
|
|
36
|
+
/** Statement terminator, `';'` or `''`. */
|
|
37
|
+
readonly terminator: string;
|
|
38
|
+
readonly variableCase: 'camel' | 'snake';
|
|
39
|
+
/** Prefix of variable names, `'$'` in PHP. */
|
|
40
|
+
readonly variablePrefix?: string;
|
|
41
|
+
readonly memberAccess: string;
|
|
42
|
+
readonly staticAccess: string;
|
|
43
|
+
/** Separator between a namespace and its member. `null` means members are called unqualified. */
|
|
44
|
+
readonly namespaceAccess: string | null;
|
|
45
|
+
/** Binds the value of `expression` to `variable`. */
|
|
46
|
+
declare(variable: string, expression: string, returnType: string | null): string;
|
|
47
|
+
/**
|
|
48
|
+
* Statement that creates an instance of `type` named `variable`.
|
|
49
|
+
* `hasConstructor` is false when the scanner found no constructor in the file.
|
|
50
|
+
* Returns `null` when the language cannot build the type without one.
|
|
51
|
+
*/
|
|
52
|
+
construct(type: string, args: string, variable: string, hasConstructor: boolean): string | null;
|
|
53
|
+
/** Wraps an expression that must be awaited. */
|
|
54
|
+
await?(expression: string): string;
|
|
55
|
+
/** Rewrites one argument, for languages with named arguments. */
|
|
56
|
+
argument?(name: string, parameter: Node): string;
|
|
57
|
+
/** Line that brings the symbol into scope, or `null` when it cannot be derived. */
|
|
58
|
+
importLine?(context: ImportContext): string | null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Everything the scanner needs to support one language. Adding a language
|
|
62
|
+
* means adding one spec and listing it in `languages/index.ts`.
|
|
63
|
+
*/
|
|
64
|
+
export interface LanguageSpec {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly label: string;
|
|
67
|
+
/**
|
|
68
|
+
* Languages whose types can refer to each other, such as TypeScript and
|
|
69
|
+
* JavaScript. A type name never links across families. Defaults to `id`.
|
|
70
|
+
*/
|
|
71
|
+
readonly family?: string;
|
|
72
|
+
readonly extensions: readonly string[];
|
|
73
|
+
/**
|
|
74
|
+
* For an extension that several languages share, such as `.h`: answers
|
|
75
|
+
* whether this source is in this language. Specs are tried in registry order.
|
|
76
|
+
*/
|
|
77
|
+
readonly accepts?: (source: string) => boolean;
|
|
78
|
+
/** Path of the tree-sitter grammar `.wasm`. */
|
|
79
|
+
readonly grammarPath: string;
|
|
80
|
+
/** shiki language id. */
|
|
81
|
+
readonly highlight: string;
|
|
82
|
+
/**
|
|
83
|
+
* Tree-sitter query. Captures: `@definition.<kind>` on the definition node,
|
|
84
|
+
* `@name`, and optionally `@params`, `@body`, `@return`, `@owner`.
|
|
85
|
+
* `@owner` names the type a method belongs to when the method is declared
|
|
86
|
+
* outside it (Go receivers, Rust `impl` blocks).
|
|
87
|
+
*
|
|
88
|
+
* `@definition.field` marks a field, property or enum member. It takes
|
|
89
|
+
* `@name` and optionally `@type` and `@value`. With `@receiver` (Python's
|
|
90
|
+
* `self.x = ...`) the field belongs to the type around the enclosing method.
|
|
91
|
+
*
|
|
92
|
+
* `@package` captures the package or namespace the file declares.
|
|
93
|
+
*/
|
|
94
|
+
readonly query: string;
|
|
95
|
+
/**
|
|
96
|
+
* Where a declaration puts its type: `prefix` as in `int count`, `suffix`
|
|
97
|
+
* as in `count: int`, `none` for languages without declared types.
|
|
98
|
+
*/
|
|
99
|
+
readonly typeSyntax: 'prefix' | 'suffix' | 'none';
|
|
100
|
+
/** What the language calls its annotations, for example `Decorators`. */
|
|
101
|
+
readonly annotationLabel: string;
|
|
102
|
+
readonly docStyle: DocStyle;
|
|
103
|
+
/** `docstring` reads the first string of the body instead of leading comments. */
|
|
104
|
+
readonly docSource: 'leading-comment' | 'docstring';
|
|
105
|
+
readonly commentTypes: readonly string[];
|
|
106
|
+
/** Restricts which leading comments count as documentation. */
|
|
107
|
+
readonly isDocComment?: (text: string) => boolean;
|
|
108
|
+
/** Node types of decorators, attributes and annotations. */
|
|
109
|
+
readonly annotationTypes: readonly string[];
|
|
110
|
+
/** Parent node types that wrap a definition, such as `export_statement`. */
|
|
111
|
+
readonly wrapperTypes: readonly string[];
|
|
112
|
+
/** Node types whose descendants are local, such as closures. */
|
|
113
|
+
readonly localScopeTypes: readonly string[];
|
|
114
|
+
/** Parents whose leading comment documents their first child (a tree-sitter-ruby quirk). */
|
|
115
|
+
readonly hoistedCommentParents?: readonly string[];
|
|
116
|
+
/** Parameter node types that are receivers. */
|
|
117
|
+
readonly receiverTypes?: readonly string[];
|
|
118
|
+
/** Parameter names that are receivers. */
|
|
119
|
+
readonly receiverNames?: readonly string[];
|
|
120
|
+
/** Parameter node types that never appear in a call. */
|
|
121
|
+
readonly skippedParamTypes?: readonly string[];
|
|
122
|
+
/** When set, only these node types inside a parameter list are parameters. */
|
|
123
|
+
readonly paramTypes?: readonly string[];
|
|
124
|
+
/** Answers from a declaration head whether the type can be constructed. Abstract types are excluded already. */
|
|
125
|
+
readonly isInstantiable?: (signature: string) => boolean;
|
|
126
|
+
/** Kind given to an owner type that is not declared in the same file. */
|
|
127
|
+
readonly inferredOwnerKind?: SymbolKind;
|
|
128
|
+
/** Splits a qualified name such as `Foo::bar` into owner and member. */
|
|
129
|
+
readonly splitQualifiedName?: (name: string) => {
|
|
130
|
+
owner: string;
|
|
131
|
+
name: string;
|
|
132
|
+
} | null;
|
|
133
|
+
/** Names a constructor can have inside a class called `className`. */
|
|
134
|
+
constructorNames(className: string): readonly string[];
|
|
135
|
+
/** True when the definition is called on its type rather than on an instance. */
|
|
136
|
+
isStatic(facts: DefinitionFacts): boolean;
|
|
137
|
+
/** True when a call to the definition yields a value, so a generated example binds it to a variable. */
|
|
138
|
+
returnsValue(facts: DefinitionFacts): boolean;
|
|
139
|
+
/** Reads the return type when the `@return` capture cannot express it, such as a C pointer. */
|
|
140
|
+
readonly declaredReturnType?: (facts: DefinitionFacts) => string | null;
|
|
141
|
+
readonly call: CallStyle;
|
|
142
|
+
}
|
|
143
|
+
/** Language family of a spec: its `family`, or its `id` when it sets none. */
|
|
144
|
+
export declare function familyOf(spec: LanguageSpec): string;
|
|
145
|
+
/**
|
|
146
|
+
* Decides from a declared return type whether a call yields a value.
|
|
147
|
+
* `implicit` answers for declarations without a return type.
|
|
148
|
+
*/
|
|
149
|
+
export declare function returnsValueFrom(returnType: string | null, implicit: boolean): boolean;
|
|
@@ -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,19 @@
|
|
|
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
|
+
* 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 by
|
|
8
|
+
* `RepositoryScanner` in `scanner/scanner.ts` and consumed by `CodePlanner` in
|
|
9
|
+
* `code/planner.ts`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class LanguageRegistry {
|
|
12
|
+
private readonly byExtension;
|
|
13
|
+
/** Indexes the specs by extension. Order matters: `forFile` tries them in this order. */
|
|
14
|
+
constructor(languages?: readonly LanguageSpec[]);
|
|
15
|
+
/** True when some language claims the extension of `path`. */
|
|
16
|
+
supports(path: string): boolean;
|
|
17
|
+
/** The first language that accepts the source. Falls back to the last one that claims the extension. */
|
|
18
|
+
forFile(path: string, source: string): LanguageSpec | null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Node } from 'web-tree-sitter';
|
|
2
|
+
import type { DefinitionFacts, ImportContext } from '../language';
|
|
3
|
+
/** True when the declaration head contains the `static` keyword. */
|
|
4
|
+
export declare function hasStaticKeyword(facts: DefinitionFacts): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Walks up from a definition and reports whether it reaches one of `staticScopes`
|
|
7
|
+
* before one of `instanceScopes`. Used for Kotlin and Scala `object` members.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isInsideScope(node: Node, staticScopes: readonly string[], instanceScopes: readonly string[]): boolean;
|
|
10
|
+
/** False for a Kotlin or Scala `object` declaration head, which declares a singleton. */
|
|
11
|
+
export declare function isNotSingleton(signature: string): boolean;
|
|
12
|
+
/** `*` or `&` when a C or C++ function returns a pointer or reference, which the `type` field does not show. */
|
|
13
|
+
export declare function returnIndirection(node: Node): string;
|
|
14
|
+
/** Path of a file without its extension, for module specifiers. */
|
|
15
|
+
export declare function withoutExtension(path: string): string;
|
|
16
|
+
/** `import pkg.Name` in the given statement shape, for languages with a declared package. */
|
|
17
|
+
export declare function packageImport(context: ImportContext, format: (qualifiedName: string) => string): string | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
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 Reporter } from '../reporter';
|
|
6
|
+
import type { SqlPlanner } from '../sql/planner';
|
|
7
|
+
import type { SymbolExtractor } from './extract';
|
|
8
|
+
import type { GrammarLoader } from './grammar';
|
|
9
|
+
import type { LanguageRegistry } from './languages';
|
|
10
|
+
import type { SymbolPlanner } from './symbols';
|
|
11
|
+
/** One source file to add. */
|
|
12
|
+
export interface SourceFile {
|
|
13
|
+
/** Absolute directory `path` is relative to. */
|
|
14
|
+
readonly root: string;
|
|
15
|
+
readonly path: string;
|
|
16
|
+
/** Path as the bundle shows it: `path` behind the prefix of its source. */
|
|
17
|
+
readonly displayPath: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Adds source files and their symbols to the graph. The SQL files of a
|
|
21
|
+
* repository are no code: `DatabasePlanner` adds them. A SQL file of a skill
|
|
22
|
+
* that creates tables goes to the `SqlPlanner`.
|
|
23
|
+
*
|
|
24
|
+
* Holds the planners and loaders it delegates to: it parses a file with the
|
|
25
|
+
* grammar from `GrammarLoader`, extracts symbols with `SymbolExtractor`, and
|
|
26
|
+
* hands them to `SymbolPlanner`. Created per scan by `RepositoryScanner` in
|
|
27
|
+
* `scanner/scanner.ts`, which calls `planTree` for the code section;
|
|
28
|
+
* `SkillPlanner` in `skills/planner.ts` calls `isSource` and `planFile`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const code = new CodePlanner(graph, registry, grammars, extractor, symbols, files, sql, reporter);
|
|
32
|
+
* await code.planTree(sections.code, source);
|
|
33
|
+
*/
|
|
34
|
+
export declare class CodePlanner {
|
|
35
|
+
private readonly graph;
|
|
36
|
+
private readonly registry;
|
|
37
|
+
private readonly grammars;
|
|
38
|
+
private readonly extractor;
|
|
39
|
+
private readonly symbols;
|
|
40
|
+
private readonly files;
|
|
41
|
+
private readonly sql;
|
|
42
|
+
private readonly reporter;
|
|
43
|
+
/**
|
|
44
|
+
* Takes the graph it adds nodes to and the helpers it delegates each file to.
|
|
45
|
+
*
|
|
46
|
+
* @param reporter - Receives a warning for each file that cannot be read or parsed. Silent by default.
|
|
47
|
+
*/
|
|
48
|
+
constructor(graph: GraphBuilder, registry: LanguageRegistry, grammars: GrammarLoader, extractor: SymbolExtractor, symbols: SymbolPlanner, files: FileRenderer, sql: SqlPlanner, reporter?: Reporter);
|
|
49
|
+
/** True for a file that is source code, whether or not the scanner can read its symbols. */
|
|
50
|
+
isSource(path: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Adds every file of `source` that declares a class or a function, in
|
|
53
|
+
* folders below `section`. Files in unsupported languages are skipped.
|
|
54
|
+
*/
|
|
55
|
+
planTree(section: NodeRef, source: Source): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Adds one file below `parent` with its text embedded, whatever it
|
|
58
|
+
* declares. Used for the code that belongs to a skill. A SQL file that
|
|
59
|
+
* creates tables is added as a database instead.
|
|
60
|
+
*/
|
|
61
|
+
planFile(parent: NodeRef, file: SourceFile): Promise<NodeRef>;
|
|
62
|
+
/**
|
|
63
|
+
* Adds a `source` node for the file below `parent`, registers its display path, and plans its symbols.
|
|
64
|
+
*
|
|
65
|
+
* @param extracted - Symbols of the file, or `null` to add the file without symbols.
|
|
66
|
+
* @param embedText - Whether the node carries the file's full text.
|
|
67
|
+
*/
|
|
68
|
+
private add;
|
|
69
|
+
/** The symbols of a file, or `null` when its language is unsupported or it cannot be read. */
|
|
70
|
+
private extract;
|
|
71
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
/** What the planner needs to know about the file a symbol tree comes from. */
|
|
10
|
+
export interface FileContext {
|
|
11
|
+
readonly spec: LanguageSpec;
|
|
12
|
+
/** Display path of the file: its path below the source root, behind the source's prefix. */
|
|
13
|
+
readonly path: string;
|
|
14
|
+
/** Package or namespace the file declares. */
|
|
15
|
+
readonly packageName: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Adds the symbols of a file to the graph: one node per class or function,
|
|
19
|
+
* with a child node per parameter and field. Type names in signatures become
|
|
20
|
+
* links to the types they name.
|
|
21
|
+
*
|
|
22
|
+
* Holds the graph, the renderers, and the indexes and linkers it registers into and
|
|
23
|
+
* links through. Created per scan by `RepositoryScanner` in `scanner/scanner.ts`;
|
|
24
|
+
* `CodePlanner` in `planner.ts` calls `plan` for each file it extracts symbols from.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const symbols = new SymbolPlanner(graph, highlighter, markdown, types, callables, linker, resolvers);
|
|
28
|
+
* symbols.plan(fileRef, { spec, path: 'src/app.ts', packageName: null }, extracted.symbols);
|
|
29
|
+
*/
|
|
30
|
+
export declare class SymbolPlanner {
|
|
31
|
+
private readonly graph;
|
|
32
|
+
private readonly highlighter;
|
|
33
|
+
private readonly markdown;
|
|
34
|
+
private readonly types;
|
|
35
|
+
private readonly callables;
|
|
36
|
+
private readonly linker;
|
|
37
|
+
private readonly resolvers;
|
|
38
|
+
/** Takes the graph and renderers it writes with, and the indexes and linkers that resolve names. */
|
|
39
|
+
constructor(graph: GraphBuilder, highlighter: CodeHighlighter, markdown: MarkdownRenderer, types: TypeIndex, callables: CallableIndex, linker: TypeLinker, resolvers: ProseResolvers);
|
|
40
|
+
/** Adds `symbols` and everything inside them below the file node `fileRef`. */
|
|
41
|
+
plan(fileRef: NodeRef, file: FileContext, symbols: readonly RawSymbol[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* Adds one symbol node with its parameter and field nodes, registers it in the type or
|
|
44
|
+
* callable index, and recurses into its children.
|
|
45
|
+
*/
|
|
46
|
+
private planSymbol;
|
|
47
|
+
/**
|
|
48
|
+
* Builds the content of a symbol node: highlighted signature, rendered description,
|
|
49
|
+
* return value, tags and example. Records `extends` edges for its heritage.
|
|
50
|
+
*
|
|
51
|
+
* @param self - Node of the symbol itself, where the edges start.
|
|
52
|
+
*/
|
|
53
|
+
private symbolContent;
|
|
54
|
+
/** Builds the content of a parameter or field node: linked type, default, optional flag and rendered description. */
|
|
55
|
+
private declarationContent;
|
|
56
|
+
/**
|
|
57
|
+
* Return value of a symbol from its declared return type and `@returns` tag.
|
|
58
|
+
*
|
|
59
|
+
* @returns `null` when there is no tag and the symbol returns no typed value.
|
|
60
|
+
*/
|
|
61
|
+
private returns;
|
|
62
|
+
/** Prefers the documented example. Falls back to one generated from the signature. */
|
|
63
|
+
private example;
|
|
64
|
+
/** Renders a plain doc tag. The subject of a `throws` tag links to the types it names. */
|
|
65
|
+
private tag;
|
|
66
|
+
/** Renders a description. Inline code that names a type or function, and glossary terms, become links. */
|
|
67
|
+
private html;
|
|
68
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { EdgeKind, LinkedText, NodeRef } from '../../model';
|
|
2
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
3
|
+
/** Where a type name is used. Decides which declaration it means. */
|
|
4
|
+
export interface TypeScope {
|
|
5
|
+
/** Display path of the file the name is in. `null` for a name in prose, which has no file of its own. */
|
|
6
|
+
readonly path: string | null;
|
|
7
|
+
/** Language family of the name. `null` matches every language. */
|
|
8
|
+
readonly family: string | null;
|
|
9
|
+
/** Type parameters in scope, such as `T`. They are never linked. */
|
|
10
|
+
readonly typeParameters: ReadonlySet<string>;
|
|
11
|
+
}
|
|
12
|
+
/** Scope of a name in a document: any language, no file. */
|
|
13
|
+
export declare const PROSE_SCOPE: TypeScope;
|
|
14
|
+
/**
|
|
15
|
+
* Every class, interface, struct, enum, trait and type alias of the scan, by name.
|
|
16
|
+
*
|
|
17
|
+
* Holds every declaration of each name. Created per scan by `RepositoryScanner` in
|
|
18
|
+
* `scanner/scanner.ts`; `SymbolPlanner` in `symbols.ts` registers each type it adds,
|
|
19
|
+
* and {@link TypeLinker} resolves names against it.
|
|
20
|
+
*/
|
|
21
|
+
export declare class TypeIndex {
|
|
22
|
+
private readonly byName;
|
|
23
|
+
/**
|
|
24
|
+
* Adds a type declaration under its name.
|
|
25
|
+
*
|
|
26
|
+
* @param path - Display path of the file that declares it.
|
|
27
|
+
* @param family - Language family of that file, from `familyOf`.
|
|
28
|
+
*/
|
|
29
|
+
register(name: string, ref: NodeRef, path: string, family: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* The declaration a name refers to, or `null` when there is none or the name is ambiguous.
|
|
32
|
+
* A declaration in the same file wins, then the one whose directory is closest.
|
|
33
|
+
*/
|
|
34
|
+
resolve(name: string, scope: TypeScope): NodeRef | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Every function and method of the scan, by name and by `Owner.name`. Lets
|
|
38
|
+
* prose refer to a function the way it refers to a type.
|
|
39
|
+
*
|
|
40
|
+
* Holds every declaration of each key. Created per scan by `RepositoryScanner` in
|
|
41
|
+
* `scanner/scanner.ts`; `SymbolPlanner` in `symbols.ts` registers each function and
|
|
42
|
+
* method it adds, and {@link TypeLinker.mention} resolves inline code against it.
|
|
43
|
+
*/
|
|
44
|
+
export declare class CallableIndex {
|
|
45
|
+
private readonly byName;
|
|
46
|
+
/**
|
|
47
|
+
* Adds a function or method under its name and, when it has an owner, under `Owner.name`.
|
|
48
|
+
*
|
|
49
|
+
* @param owner - Name of the type or namespace it is declared in, or `null`.
|
|
50
|
+
* @param path - Display path of its file.
|
|
51
|
+
* @param family - Language family of its file, from `familyOf`.
|
|
52
|
+
*/
|
|
53
|
+
register(name: string, owner: string | null, ref: NodeRef, path: string, family: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* The function a piece of inline code names.
|
|
56
|
+
*
|
|
57
|
+
* @param text - Inline code, such as `choose_route()` or `Invoice.add`.
|
|
58
|
+
* @returns The function, or `null` when the text names none or more than one.
|
|
59
|
+
*/
|
|
60
|
+
resolve(text: string, scope: TypeScope): NodeRef | null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Turns type names in source text into links between nodes, and records each link as an edge.
|
|
64
|
+
*
|
|
65
|
+
* Holds the type and callable indexes it resolves names against and the graph it adds
|
|
66
|
+
* edges to. Created per scan by `RepositoryScanner` in `scanner/scanner.ts`; used by
|
|
67
|
+
* `SymbolPlanner` in `symbols.ts` for signatures and by the resolvers in
|
|
68
|
+
* `markdown/links.ts` for inline code in prose.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* const linker = new TypeLinker(new TypeIndex(), new CallableIndex(), graph);
|
|
72
|
+
* const type = linker.link('Promise<Booking>', methodRef, 'returns', scope);
|
|
73
|
+
*/
|
|
74
|
+
export declare class TypeLinker {
|
|
75
|
+
private readonly index;
|
|
76
|
+
private readonly callables;
|
|
77
|
+
private readonly graph;
|
|
78
|
+
/** Takes the indexes it resolves names against and the graph it adds edges to. */
|
|
79
|
+
constructor(index: TypeIndex, callables: CallableIndex, graph: GraphBuilder);
|
|
80
|
+
/**
|
|
81
|
+
* Links every known type name in `text`, such as `Booking` in `Promise<Booking>`.
|
|
82
|
+
* Records one `relation` edge from `from` to each type it finds.
|
|
83
|
+
*/
|
|
84
|
+
link(text: string, from: NodeRef, relation: EdgeKind, scope: TypeScope): LinkedText;
|
|
85
|
+
/**
|
|
86
|
+
* The type or function that inline code names, and an edge to it.
|
|
87
|
+
*
|
|
88
|
+
* @param text - Inline code, such as `Booking` or `choose_route()`.
|
|
89
|
+
* @param from - Node the code is written in. The edge starts here.
|
|
90
|
+
* @returns The node the code names, or `null` when it names none, more than one, or `from` itself.
|
|
91
|
+
*/
|
|
92
|
+
mention(text: string, from: NodeRef, scope: TypeScope, relation?: EdgeKind): NodeRef | null;
|
|
93
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FileContent } from '../model';
|
|
2
|
+
import type { CodeHighlighter } from './highlight';
|
|
3
|
+
import type { LinkResolver, MarkdownRenderer } from './markdown/renderer';
|
|
4
|
+
/** A file as its page shows it. */
|
|
5
|
+
export interface RenderedFile {
|
|
6
|
+
/** Frontmatter `title` or `name`, else the first heading, else the file name. */
|
|
7
|
+
readonly title: string;
|
|
8
|
+
/** Frontmatter `description`, or `''`. */
|
|
9
|
+
readonly description: string;
|
|
10
|
+
readonly content: FileContent;
|
|
11
|
+
}
|
|
12
|
+
/** Tells a markdown or MDX file by its extension. */
|
|
13
|
+
export declare function isMarkdown(path: string): boolean;
|
|
14
|
+
/** Reads an image file into a `data:` URI, or returns `null` when it is no image, is missing or is too large. */
|
|
15
|
+
export declare function imageDataUri(absolutePath: string): Promise<string | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Turns a file of any type into what its page shows: rendered markdown,
|
|
18
|
+
* highlighted text or an image. Holds the markdown renderer and the code
|
|
19
|
+
* highlighter it uses. Created by `RepositoryScanner`, and used by the
|
|
20
|
+
* planners of the docs, skills, code, glossary, decisions, JSON Schema and
|
|
21
|
+
* tasks sections.
|
|
22
|
+
*/
|
|
23
|
+
export declare class FileRenderer {
|
|
24
|
+
private readonly markdownRenderer;
|
|
25
|
+
private readonly highlighter;
|
|
26
|
+
/** Keeps the renderer and the highlighter for every file it renders. */
|
|
27
|
+
constructor(markdownRenderer: MarkdownRenderer, highlighter: CodeHighlighter);
|
|
28
|
+
/**
|
|
29
|
+
* Reads a file and renders it by its type.
|
|
30
|
+
*
|
|
31
|
+
* @param resolver - Rewrites the links of a markdown file.
|
|
32
|
+
*/
|
|
33
|
+
render(absolutePath: string, resolver?: LinkResolver): Promise<RenderedFile>;
|
|
34
|
+
/** Renders markdown that is already read. `fallbackTitle` is used when the text names no title. */
|
|
35
|
+
markdown(source: string, fallbackTitle: string, resolver?: LinkResolver, mdx?: boolean): Promise<RenderedFile>;
|
|
36
|
+
/** Reads a file as text, highlighted by its extension when it is small enough, or omitted when it is large or binary. */
|
|
37
|
+
text(absolutePath: string): Promise<FileContent>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** One decision as the decision log writes it. */
|
|
2
|
+
export interface ParsedDecision {
|
|
3
|
+
/** Number or id in front of the title, such as `3` or `ADR-0003`. `''` when the title has none. */
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly title: string;
|
|
6
|
+
/** As written, such as `accepted`. `''` when the decision states none. */
|
|
7
|
+
readonly status: string;
|
|
8
|
+
/** As written. `''` when the decision states none. */
|
|
9
|
+
readonly date: string;
|
|
10
|
+
/** Markdown of the decision without its heading, status line and date line. */
|
|
11
|
+
readonly body: string;
|
|
12
|
+
}
|
|
13
|
+
/** A decision log split into its intro and its decisions. */
|
|
14
|
+
export interface ParsedDecisions {
|
|
15
|
+
/** Markdown of everything in front of the first decision, with the title. */
|
|
16
|
+
readonly intro: string;
|
|
17
|
+
readonly decisions: readonly ParsedDecision[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads the decisions of a decision log. Each heading of the highest level
|
|
21
|
+
* below the title starts one decision. The heading may carry a number or a
|
|
22
|
+
* date in front of the title. `Status:` and `Date:` lines at the top of a
|
|
23
|
+
* decision become its status and date.
|
|
24
|
+
*
|
|
25
|
+
* @param markdown - The decision log without frontmatter.
|
|
26
|
+
* @returns The decisions in file order and the text in front of them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseDecisions(markdown: string): ParsedDecisions;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { NodeRef } from '../../model';
|
|
2
|
+
import type { FileRenderer } from '../content';
|
|
3
|
+
import type { DocFile } from '../docs';
|
|
4
|
+
import type { GraphBuilder } from '../graph/builder';
|
|
5
|
+
import type { ProseResolvers } from '../markdown/links';
|
|
6
|
+
import type { MarkdownRenderer } from '../markdown/renderer';
|
|
7
|
+
/**
|
|
8
|
+
* Adds a decision log to the graph: one node for the file and one `decision`
|
|
9
|
+
* node per decision. Used by `DocPlanner` for every `decisions.md` of the docs
|
|
10
|
+
* section. What a decision links to or names in inline code becomes an
|
|
11
|
+
* `affects` edge from the decision.
|
|
12
|
+
*
|
|
13
|
+
* Holds the graph, the file renderer, the markdown renderer and the prose
|
|
14
|
+
* resolvers. Created by `RepositoryScanner`, which hands it to `DocPlanner`.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DecisionPlanner {
|
|
17
|
+
private readonly graph;
|
|
18
|
+
private readonly files;
|
|
19
|
+
private readonly markdown;
|
|
20
|
+
private readonly resolvers;
|
|
21
|
+
/** Creates a planner. */
|
|
22
|
+
constructor(graph: GraphBuilder, files: FileRenderer, markdown: MarkdownRenderer, resolvers: ProseResolvers);
|
|
23
|
+
/**
|
|
24
|
+
* Reads one decision log and adds its nodes.
|
|
25
|
+
*
|
|
26
|
+
* @param parent - Folder or section the file is in.
|
|
27
|
+
* @returns The node of the file.
|
|
28
|
+
*/
|
|
29
|
+
plan(parent: NodeRef, { root, path, displayPath, prefix }: DocFile): Promise<NodeRef>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { NodeRef } from '../model';
|
|
2
|
+
import type { FileRenderer } from './content';
|
|
3
|
+
import type { DecisionPlanner } from './decisions/planner';
|
|
4
|
+
import { type Source } from './files';
|
|
5
|
+
import type { GlossaryPlanner } from './glossary/planner';
|
|
6
|
+
import type { GraphBuilder } from './graph/builder';
|
|
7
|
+
import type { ProseResolvers } from './markdown/links';
|
|
8
|
+
import type { SpecPlanner } from './specs';
|
|
9
|
+
/** What a file of the docs section becomes. */
|
|
10
|
+
export type DocKind = 'document' | 'json' | 'glossary' | 'decisions';
|
|
11
|
+
/** A file of the docs section, with the paths the planners need. */
|
|
12
|
+
export interface DocFile {
|
|
13
|
+
/** Absolute directory `path` is relative to. */
|
|
14
|
+
readonly root: string;
|
|
15
|
+
/** Path of the file inside `root`. */
|
|
16
|
+
readonly path: string;
|
|
17
|
+
/** Path the site shows: `path` behind the prefix of its source. */
|
|
18
|
+
readonly displayPath: string;
|
|
19
|
+
/** Prefix the bundle puts in front of paths from `root`. */
|
|
20
|
+
readonly prefix: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Tells what a file of the docs section becomes, from its extension and name.
|
|
24
|
+
*
|
|
25
|
+
* @returns The kind, or `null` for a file that does not belong in the docs section.
|
|
26
|
+
*/
|
|
27
|
+
export declare function docKind(path: string): DocKind | null;
|
|
28
|
+
/**
|
|
29
|
+
* Adds the docs section to the graph: markdown and JSON files in the folders
|
|
30
|
+
* they are in. A `glossary.md` and a `decisions.md` go to their own planners,
|
|
31
|
+
* which add one node per term and per decision. A JSON or YAML file that is
|
|
32
|
+
* an OpenAPI document or a JSON Schema goes to the `SpecPlanner`. Created by
|
|
33
|
+
* `RepositoryScanner` for every scan.
|
|
34
|
+
*/
|
|
35
|
+
export declare class DocPlanner {
|
|
36
|
+
private readonly graph;
|
|
37
|
+
private readonly files;
|
|
38
|
+
private readonly resolvers;
|
|
39
|
+
private readonly glossaries;
|
|
40
|
+
private readonly decisions;
|
|
41
|
+
private readonly specs;
|
|
42
|
+
/** Keeps the graph to add to and the renderer and planners each file goes to. */
|
|
43
|
+
constructor(graph: GraphBuilder, files: FileRenderer, resolvers: ProseResolvers, glossaries: GlossaryPlanner, decisions: DecisionPlanner, specs: SpecPlanner);
|
|
44
|
+
/**
|
|
45
|
+
* Adds every doc file of the sources.
|
|
46
|
+
*
|
|
47
|
+
* @param section - Node of the docs section.
|
|
48
|
+
*/
|
|
49
|
+
plan(section: NodeRef, sources: readonly Source[]): Promise<void>;
|
|
50
|
+
/** Adds a markdown or JSON file as a page of its own and registers its path. */
|
|
51
|
+
private planFile;
|
|
52
|
+
}
|