@g3nomaly/analyze 0.1.0 → 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/README.md +10 -5
- package/dist/api/bundle-builder.d.ts +29 -10
- package/dist/api/bundle-cache.d.ts +7 -4
- package/dist/api/bundle-loader.d.ts +10 -3
- package/dist/api/create-docs.d.ts +33 -14
- package/dist/api/embedding.d.ts +16 -7
- package/dist/api/errors.d.ts +13 -6
- package/dist/api/list.d.ts +20 -20
- package/dist/api/options.d.ts +18 -22
- package/dist/api/refs.d.ts +24 -21
- package/dist/api/scan.d.ts +24 -12
- package/dist/api/search.d.ts +27 -21
- package/dist/api/services.d.ts +9 -1
- package/dist/api/show.d.ts +15 -19
- package/dist/api/site-reader.d.ts +11 -3
- package/dist/api/site-writer.d.ts +30 -7
- package/dist/api/source.d.ts +23 -12
- package/dist/api/target.d.ts +2 -0
- package/dist/cli.js +670 -238
- package/dist/embeddings/index-builder.d.ts +3 -1
- package/dist/embeddings/model.d.ts +26 -13
- package/dist/embeddings/searcher.d.ts +24 -7
- package/dist/embeddings/vectors.d.ts +3 -1
- package/dist/embeddings/words.d.ts +7 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +647 -229
- package/dist/model/index.d.ts +416 -188
- package/dist/model/registry.d.ts +204 -11
- package/dist/query/graph.d.ts +83 -26
- package/dist/query/name-search.d.ts +39 -21
- package/dist/query/semantic.d.ts +11 -3
- package/dist/retrieval/describe.d.ts +11 -4
- package/dist/retrieval/filter.d.ts +27 -8
- package/dist/retrieval/index.d.ts +1 -1
- package/dist/retrieval/markdown.d.ts +3 -2
- package/dist/retrieval/report.d.ts +147 -70
- package/dist/retrieval/resolve.d.ts +11 -7
- package/dist/retrieval/retriever.d.ts +34 -23
- package/dist/retrieval/summary.d.ts +6 -3
- package/dist/scanner/code/doc/clean.d.ts +31 -5
- package/dist/scanner/code/doc/index.d.ts +7 -1
- package/dist/scanner/code/doc/markdown.d.ts +6 -1
- package/dist/scanner/code/doc/python.d.ts +6 -1
- package/dist/scanner/code/doc/tagged.d.ts +13 -4
- package/dist/scanner/code/doc/types.d.ts +16 -5
- package/dist/scanner/code/doc/xml.d.ts +6 -1
- package/dist/scanner/code/example.d.ts +31 -10
- package/dist/scanner/code/extract.d.ts +56 -21
- package/dist/scanner/code/grammar.d.ts +20 -5
- package/dist/scanner/code/language.d.ts +100 -66
- package/dist/scanner/code/languages/index.d.ts +21 -7
- package/dist/scanner/code/languages/shared.d.ts +23 -4
- package/dist/scanner/code/planner.d.ts +50 -14
- package/dist/scanner/code/symbols.d.ts +86 -20
- package/dist/scanner/code/types.d.ts +48 -15
- package/dist/scanner/config.d.ts +42 -0
- package/dist/scanner/content.d.ts +49 -14
- package/dist/scanner/decisions/parse.d.ts +20 -11
- package/dist/scanner/decisions/planner.d.ts +20 -8
- package/dist/scanner/docs.d.ts +36 -19
- package/dist/scanner/files.d.ts +44 -19
- package/dist/scanner/glossary/parse.d.ts +17 -7
- package/dist/scanner/glossary/planner.d.ts +15 -8
- package/dist/scanner/glossary/terms.d.ts +57 -27
- package/dist/scanner/graph/builder.d.ts +80 -21
- package/dist/scanner/highlight.d.ts +32 -9
- package/dist/scanner/ignore.d.ts +25 -0
- package/dist/scanner/index.d.ts +5 -2
- package/dist/scanner/markdown/frontmatter.d.ts +18 -3
- package/dist/scanner/markdown/links.d.ts +19 -9
- package/dist/scanner/markdown/outline.d.ts +13 -5
- package/dist/scanner/markdown/renderer.d.ts +32 -13
- package/dist/scanner/openapi/planner.d.ts +20 -8
- package/dist/scanner/packages.d.ts +28 -0
- package/dist/scanner/reporter.d.ts +5 -2
- package/dist/scanner/scanner.d.ts +21 -7
- package/dist/scanner/schema/definitions.d.ts +18 -8
- package/dist/scanner/schema/describe.d.ts +44 -18
- package/dist/scanner/schema/planner.d.ts +6 -3
- package/dist/scanner/schema/registry.d.ts +23 -16
- package/dist/scanner/skills/classify.d.ts +2 -1
- package/dist/scanner/skills/layout.d.ts +27 -9
- package/dist/scanner/skills/planner.d.ts +19 -4
- package/dist/scanner/specs.d.ts +8 -2
- package/dist/scanner/sql/catalog.d.ts +21 -7
- package/dist/scanner/sql/cursor.d.ts +9 -4
- package/dist/scanner/sql/database.d.ts +6 -3
- package/dist/scanner/sql/parse.d.ts +62 -27
- package/dist/scanner/sql/planner.d.ts +6 -2
- package/dist/scanner/sql/query.d.ts +34 -21
- package/dist/scanner/sql/registry.d.ts +24 -10
- package/dist/scanner/sql/source.d.ts +1 -0
- package/dist/scanner/sql/statements.d.ts +9 -3
- package/dist/scanner/sql/tokens.d.ts +25 -12
- package/dist/scanner/tasks/layout.d.ts +22 -10
- package/dist/scanner/tasks/planner.d.ts +64 -9
- package/package.json +2 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { SymbolKind } from '../../model';
|
|
2
2
|
import type { Node } from 'web-tree-sitter';
|
|
3
3
|
/**
|
|
4
|
-
* Doc comment dialect.
|
|
4
|
+
* @brief Doc comment dialect, which decides how the scanner reads doc comments.
|
|
5
|
+
*
|
|
5
6
|
* - `tagged`: `@param`-style tags (JSDoc, Javadoc, Doxygen, PHPDoc, KDoc, Scaladoc).
|
|
6
7
|
* - `yard`: `tagged`, with the title of an `@example` on the tag line.
|
|
7
8
|
* - `markdown`: free markdown with headed sections (rustdoc, godoc).
|
|
@@ -9,141 +10,174 @@ import type { Node } from 'web-tree-sitter';
|
|
|
9
10
|
* - `xml`: C# XML documentation.
|
|
10
11
|
*/
|
|
11
12
|
export type DocStyle = 'tagged' | 'yard' | 'markdown' | 'python' | 'xml';
|
|
12
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* What a language spec can inspect when it classifies one definition.
|
|
15
|
+
*
|
|
16
|
+
* @property node - Tree-sitter node of the definition.
|
|
17
|
+
* @property signature - Declaration head, without the body.
|
|
18
|
+
* @property annotations - Decorator, attribute and annotation texts in front of the definition.
|
|
19
|
+
* @property returnType - Declared return type text, e.g. `number`, or `null` when the grammar exposes none.
|
|
20
|
+
* @property hasReceiver - True when the parameter list starts with a receiver such as `self`.
|
|
21
|
+
*/
|
|
13
22
|
export interface DefinitionFacts {
|
|
14
23
|
readonly node: Node;
|
|
15
|
-
/** Declaration head, without the body. */
|
|
16
24
|
readonly signature: string;
|
|
17
25
|
readonly annotations: readonly string[];
|
|
18
|
-
/** Declared return type text, when the grammar exposes one. */
|
|
19
26
|
readonly returnType: string | null;
|
|
20
|
-
/** True when the parameter list starts with a receiver such as `self`. */
|
|
21
27
|
readonly hasReceiver: boolean;
|
|
22
28
|
}
|
|
23
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* What an import hook knows about the symbol an example uses.
|
|
31
|
+
*
|
|
32
|
+
* @property filePath - Root-relative path of the file that declares the symbol.
|
|
33
|
+
* @property name - Outermost symbol around the one the example uses: the class of a method, or the function itself.
|
|
34
|
+
* @property kind - Kind of that outermost symbol.
|
|
35
|
+
* @property modifiers - Keywords in front of the name, such as `export` or `default`.
|
|
36
|
+
* @property packageName - Package or namespace the file declares with a statement, e.g. `a.b` for Java's `package a.b;`, or `null`.
|
|
37
|
+
*/
|
|
24
38
|
export interface ImportContext {
|
|
25
|
-
/** Root-relative path of the file that declares the symbol. */
|
|
26
39
|
readonly filePath: string;
|
|
27
|
-
/** Outermost symbol around the one the example uses: the class of a method, or the function itself. */
|
|
28
40
|
readonly name: string;
|
|
29
41
|
readonly kind: SymbolKind;
|
|
30
42
|
readonly modifiers: readonly string[];
|
|
31
|
-
/** Package or namespace the file declares with a statement, such as Java's `package a.b;`. */
|
|
32
43
|
readonly packageName: string | null;
|
|
33
44
|
}
|
|
34
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* How a language spells a call. Drives generated examples.
|
|
47
|
+
*
|
|
48
|
+
* @property terminator - Statement terminator, `';'` or `''`.
|
|
49
|
+
* @property variableCase - Case of generated variable names.
|
|
50
|
+
* @property variablePrefix - Prefix of variable names, `'$'` in PHP.
|
|
51
|
+
* @property memberAccess - Operator between an instance and its member, e.g. `.` or `->`.
|
|
52
|
+
* @property staticAccess - Operator between a type and its static member, e.g. `::`.
|
|
53
|
+
* @property namespaceAccess - Separator between a namespace and its member, or `null` when members are called unqualified.
|
|
54
|
+
*/
|
|
35
55
|
export interface CallStyle {
|
|
36
|
-
/** Statement terminator, `';'` or `''`. */
|
|
37
56
|
readonly terminator: string;
|
|
38
57
|
readonly variableCase: 'camel' | 'snake';
|
|
39
|
-
/** Prefix of variable names, `'$'` in PHP. */
|
|
40
58
|
readonly variablePrefix?: string;
|
|
41
59
|
readonly memberAccess: string;
|
|
42
60
|
readonly staticAccess: string;
|
|
43
|
-
/** Separator between a namespace and its member. `null` means members are called unqualified. */
|
|
44
61
|
readonly namespaceAccess: string | null;
|
|
45
62
|
/** Binds the value of `expression` to `variable`. */
|
|
46
63
|
declare(variable: string, expression: string, returnType: string | null): string;
|
|
47
64
|
/**
|
|
48
|
-
* Statement that creates an instance of `type` named `variable`.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
65
|
+
* @brief Statement that creates an instance of `type` named `variable`.
|
|
66
|
+
*
|
|
67
|
+
* @param hasConstructor - False when the scanner found no constructor in the file.
|
|
68
|
+
* @returns The statement, or `null` when the language cannot build the type without a constructor.
|
|
51
69
|
*/
|
|
52
70
|
construct(type: string, args: string, variable: string, hasConstructor: boolean): string | null;
|
|
53
71
|
/** Wraps an expression that must be awaited. */
|
|
54
72
|
await?(expression: string): string;
|
|
55
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Rewrites one argument, for languages with named arguments.
|
|
75
|
+
*
|
|
76
|
+
* @param parameter - Declaration node of the parameter the argument fills.
|
|
77
|
+
*/
|
|
56
78
|
argument?(name: string, parameter: Node): string;
|
|
57
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Line that brings the symbol into scope.
|
|
81
|
+
*
|
|
82
|
+
* @param context - What the import needs to know about the symbol.
|
|
83
|
+
* @returns The import line, or `null` when it cannot be derived.
|
|
84
|
+
*/
|
|
58
85
|
importLine?(context: ImportContext): string | null;
|
|
59
86
|
}
|
|
60
87
|
/**
|
|
61
|
-
* Everything the scanner needs to support one language.
|
|
62
|
-
*
|
|
88
|
+
* @brief Everything the scanner needs to support one language.
|
|
89
|
+
*
|
|
90
|
+
* Adding a language means adding one spec and listing it in `languages/index.ts`.
|
|
91
|
+
*
|
|
92
|
+
* @property id - Unique language id, e.g. `typescript`.
|
|
93
|
+
* @property label - Display name of the language, e.g. `TypeScript`.
|
|
94
|
+
* @property family - Languages whose types can refer to each other, such as TypeScript and JavaScript. A type name never links across families. Defaults to `id`.
|
|
95
|
+
* @property extensions - File extensions the language claims, e.g. `.ts`.
|
|
96
|
+
* @property accepts - For an extension several languages share, such as `.h`: answers whether this source is in this language. Specs are tried in registry order.
|
|
97
|
+
* @property grammarPath - Path of the tree-sitter grammar `.wasm`.
|
|
98
|
+
* @property highlight - shiki language id.
|
|
99
|
+
* @property query - Tree-sitter query. Captures `@definition.<kind>` on the definition node, `@name`, and optionally `@params`, `@body`, `@return`, `@owner`, `@type`, `@value`, `@receiver`, `@package`. `@owner` names the type a method declared outside it belongs to. `@definition.field` marks a field, property or enum member. With `@receiver` (Python's `self.x = ...`) the field belongs to the type around the enclosing method.
|
|
100
|
+
* @property typeSyntax - Where a declaration puts its type: `prefix` as in `int count`, `suffix` as in `count: int`, `none` for languages without declared types.
|
|
101
|
+
* @property annotationLabel - What the language calls its annotations, for example `Decorators`.
|
|
102
|
+
* @property docStyle - Dialect of the doc comments.
|
|
103
|
+
* @property docSource - Where documentation lives: `leading-comment` above the definition, or `docstring`, the first string of the body.
|
|
104
|
+
* @property commentTypes - Node types of comments.
|
|
105
|
+
* @property isDocComment - Restricts which leading comments count as documentation.
|
|
106
|
+
* @property annotationTypes - Node types of decorators, attributes and annotations.
|
|
107
|
+
* @property wrapperTypes - Parent node types that wrap a definition, such as `export_statement`.
|
|
108
|
+
* @property localScopeTypes - Node types whose descendants are local, such as closures.
|
|
109
|
+
* @property hoistedCommentParents - Parents whose leading comment documents their first child.
|
|
110
|
+
* @property receiverTypes - Parameter node types that are receivers.
|
|
111
|
+
* @property receiverNames - Parameter names that are receivers.
|
|
112
|
+
* @property skippedParamTypes - Parameter node types that never appear in a call.
|
|
113
|
+
* @property paramTypes - When set, only these node types inside a parameter list are parameters.
|
|
114
|
+
* @property isInstantiable - Answers from a declaration head whether the type can be constructed. Abstract types are excluded already.
|
|
115
|
+
* @property inferredOwnerKind - Kind given to an owner type that is not declared in the same file.
|
|
116
|
+
* @property splitQualifiedName - Splits a qualified name such as `Foo::bar` into owner and member.
|
|
117
|
+
* @property declaredReturnType - Reads the return type when the `@return` capture cannot express it, such as a C pointer.
|
|
118
|
+
* @property call - How the language spells a call.
|
|
63
119
|
*/
|
|
64
120
|
export interface LanguageSpec {
|
|
65
121
|
readonly id: string;
|
|
66
122
|
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
123
|
readonly family?: string;
|
|
72
124
|
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
125
|
readonly accepts?: (source: string) => boolean;
|
|
78
|
-
/** Path of the tree-sitter grammar `.wasm`. */
|
|
79
126
|
readonly grammarPath: string;
|
|
80
|
-
/** shiki language id. */
|
|
81
127
|
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
128
|
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
129
|
readonly typeSyntax: 'prefix' | 'suffix' | 'none';
|
|
100
|
-
/** What the language calls its annotations, for example `Decorators`. */
|
|
101
130
|
readonly annotationLabel: string;
|
|
102
131
|
readonly docStyle: DocStyle;
|
|
103
|
-
/** `docstring` reads the first string of the body instead of leading comments. */
|
|
104
132
|
readonly docSource: 'leading-comment' | 'docstring';
|
|
105
133
|
readonly commentTypes: readonly string[];
|
|
106
|
-
/** Restricts which leading comments count as documentation. */
|
|
107
134
|
readonly isDocComment?: (text: string) => boolean;
|
|
108
|
-
/** Node types of decorators, attributes and annotations. */
|
|
109
135
|
readonly annotationTypes: readonly string[];
|
|
110
|
-
/** Parent node types that wrap a definition, such as `export_statement`. */
|
|
111
136
|
readonly wrapperTypes: readonly string[];
|
|
112
|
-
/** Node types whose descendants are local, such as closures. */
|
|
113
137
|
readonly localScopeTypes: readonly string[];
|
|
114
|
-
/** Parents whose leading comment documents their first child (a tree-sitter-ruby quirk). */
|
|
115
138
|
readonly hoistedCommentParents?: readonly string[];
|
|
116
|
-
/** Parameter node types that are receivers. */
|
|
117
139
|
readonly receiverTypes?: readonly string[];
|
|
118
|
-
/** Parameter names that are receivers. */
|
|
119
140
|
readonly receiverNames?: readonly string[];
|
|
120
|
-
/** Parameter node types that never appear in a call. */
|
|
121
141
|
readonly skippedParamTypes?: readonly string[];
|
|
122
|
-
/** When set, only these node types inside a parameter list are parameters. */
|
|
123
142
|
readonly paramTypes?: readonly string[];
|
|
124
|
-
/** Answers from a declaration head whether the type can be constructed. Abstract types are excluded already. */
|
|
125
143
|
readonly isInstantiable?: (signature: string) => boolean;
|
|
126
|
-
/** Kind given to an owner type that is not declared in the same file. */
|
|
127
144
|
readonly inferredOwnerKind?: SymbolKind;
|
|
128
|
-
/** Splits a qualified name such as `Foo::bar` into owner and member. */
|
|
129
145
|
readonly splitQualifiedName?: (name: string) => {
|
|
130
146
|
owner: string;
|
|
131
147
|
name: string;
|
|
132
148
|
} | null;
|
|
133
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Names a constructor can have inside a class called `className`.
|
|
151
|
+
*
|
|
152
|
+
* @param className - Name of the class the constructor belongs to.
|
|
153
|
+
*/
|
|
134
154
|
constructorNames(className: string): readonly string[];
|
|
135
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* True when the definition is called on its type rather than on an instance.
|
|
157
|
+
*
|
|
158
|
+
* @param facts - What the spec can inspect about the definition.
|
|
159
|
+
*/
|
|
136
160
|
isStatic(facts: DefinitionFacts): boolean;
|
|
137
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* True when a call to the definition yields a value, so a generated example binds it to a variable.
|
|
163
|
+
*
|
|
164
|
+
* @param facts - What the spec can inspect about the definition.
|
|
165
|
+
*/
|
|
138
166
|
returnsValue(facts: DefinitionFacts): boolean;
|
|
139
|
-
/** Reads the return type when the `@return` capture cannot express it, such as a C pointer. */
|
|
140
167
|
readonly declaredReturnType?: (facts: DefinitionFacts) => string | null;
|
|
141
168
|
readonly call: CallStyle;
|
|
142
169
|
}
|
|
143
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Language family of a spec.
|
|
172
|
+
*
|
|
173
|
+
* @param spec - Spec to read.
|
|
174
|
+
* @returns Its `family`, or its `id` when it sets none.
|
|
175
|
+
*/
|
|
144
176
|
export declare function familyOf(spec: LanguageSpec): string;
|
|
145
177
|
/**
|
|
146
178
|
* Decides from a declared return type whether a call yields a value.
|
|
147
|
-
*
|
|
179
|
+
*
|
|
180
|
+
* @param returnType - Declared return type text, or `null` when the declaration has none.
|
|
181
|
+
* @param implicit - Answer for declarations without a return type.
|
|
148
182
|
*/
|
|
149
183
|
export declare function returnsValueFrom(returnType: string | null, implicit: boolean): boolean;
|
|
@@ -2,18 +2,32 @@ import type { LanguageSpec } from '../language';
|
|
|
2
2
|
/** Every supported language. Add a spec here to support another one. */
|
|
3
3
|
export declare const LANGUAGES: readonly LanguageSpec[];
|
|
4
4
|
/**
|
|
5
|
-
* Maps files to language specs, by extension and, where languages share one, by content.
|
|
5
|
+
* @brief Maps files to language specs, by extension and, where languages share one, by content.
|
|
6
6
|
*
|
|
7
|
-
* Holds the specs that claim each lowercase extension, in registry order. Created
|
|
8
|
-
* `RepositoryScanner` in `scanner/scanner.ts
|
|
9
|
-
* `code/planner.ts`.
|
|
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
10
|
*/
|
|
11
11
|
export declare class LanguageRegistry {
|
|
12
12
|
private readonly byExtension;
|
|
13
|
-
/**
|
|
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
|
+
*/
|
|
14
18
|
constructor(languages?: readonly LanguageSpec[]);
|
|
15
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* True when some language claims the extension of `path`.
|
|
21
|
+
*
|
|
22
|
+
* @param path - File path; the extension is matched case-insensitively.
|
|
23
|
+
*/
|
|
16
24
|
supports(path: string): boolean;
|
|
17
|
-
/**
|
|
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
|
+
*/
|
|
18
32
|
forFile(path: string, source: string): LanguageSpec | null;
|
|
19
33
|
}
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
import type { Node } from 'web-tree-sitter';
|
|
2
2
|
import type { DefinitionFacts, ImportContext } from '../language';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* True when the declaration head contains the `static` keyword.
|
|
5
|
+
*
|
|
6
|
+
* @param facts - What the spec can inspect about the definition.
|
|
7
|
+
*/
|
|
4
8
|
export declare function hasStaticKeyword(facts: DefinitionFacts): boolean;
|
|
5
9
|
/**
|
|
6
|
-
* Walks up from a definition and reports whether it reaches one of `staticScopes`
|
|
10
|
+
* @brief Walks up from a definition and reports whether it reaches one of `staticScopes`
|
|
7
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.
|
|
8
16
|
*/
|
|
9
17
|
export declare function isInsideScope(node: Node, staticScopes: readonly string[], instanceScopes: readonly string[]): boolean;
|
|
10
18
|
/** False for a Kotlin or Scala `object` declaration head, which declares a singleton. */
|
|
11
19
|
export declare function isNotSingleton(signature: string): boolean;
|
|
12
|
-
/**
|
|
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
|
+
*/
|
|
13
26
|
export declare function returnIndirection(node: Node): string;
|
|
14
27
|
/** Path of a file without its extension, for module specifiers. */
|
|
15
28
|
export declare function withoutExtension(path: string): string;
|
|
16
|
-
/**
|
|
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
|
+
*/
|
|
17
36
|
export declare function packageImport(context: ImportContext, format: (qualifiedName: string) => string): string | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NodeRef } from '../../model';
|
|
2
|
+
import type { ConfigPlanner } from '../config';
|
|
2
3
|
import type { FileRenderer } from '../content';
|
|
3
4
|
import { type Source } from '../files';
|
|
4
5
|
import type { GraphBuilder } from '../graph/builder';
|
|
@@ -8,17 +9,22 @@ import type { SymbolExtractor } from './extract';
|
|
|
8
9
|
import type { GrammarLoader } from './grammar';
|
|
9
10
|
import type { LanguageRegistry } from './languages';
|
|
10
11
|
import type { SymbolPlanner } from './symbols';
|
|
11
|
-
/**
|
|
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
|
+
*/
|
|
12
19
|
export interface SourceFile {
|
|
13
|
-
/** Absolute directory `path` is relative to. */
|
|
14
20
|
readonly root: string;
|
|
15
21
|
readonly path: string;
|
|
16
|
-
/** Path as the bundle shows it: `path` behind the prefix of its source. */
|
|
17
22
|
readonly displayPath: string;
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
|
-
* Adds source files and their symbols to the graph.
|
|
21
|
-
*
|
|
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
|
|
22
28
|
* that creates tables goes to the `SqlPlanner`.
|
|
23
29
|
*
|
|
24
30
|
* Holds the planners and loaders it delegates to: it parses a file with the
|
|
@@ -43,29 +49,59 @@ export declare class CodePlanner {
|
|
|
43
49
|
/**
|
|
44
50
|
* Takes the graph it adds nodes to and the helpers it delegates each file to.
|
|
45
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.
|
|
46
59
|
* @param reporter - Receives a warning for each file that cannot be read or parsed. Silent by default.
|
|
47
60
|
*/
|
|
48
61
|
constructor(graph: GraphBuilder, registry: LanguageRegistry, grammars: GrammarLoader, extractor: SymbolExtractor, symbols: SymbolPlanner, files: FileRenderer, sql: SqlPlanner, reporter?: Reporter);
|
|
49
|
-
/**
|
|
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
|
+
*/
|
|
50
67
|
isSource(path: string): boolean;
|
|
51
68
|
/**
|
|
52
|
-
* Adds every file of `source` that declares a class or a function, in
|
|
53
|
-
*
|
|
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.
|
|
54
77
|
*/
|
|
55
|
-
planTree(section: NodeRef, source: Source): Promise<void>;
|
|
78
|
+
planTree(section: NodeRef, source: Source, configs?: ConfigPlanner): Promise<void>;
|
|
56
79
|
/**
|
|
57
|
-
* Adds one file below `parent` with its text embedded, whatever it
|
|
58
|
-
*
|
|
59
|
-
* creates tables is added as a database instead.
|
|
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.
|
|
60
87
|
*/
|
|
61
88
|
planFile(parent: NodeRef, file: SourceFile): Promise<NodeRef>;
|
|
62
89
|
/**
|
|
63
|
-
* Adds a `source` node for the file below `parent`, registers its display path, and plans its symbols.
|
|
90
|
+
* @brief Adds a `source` node for the file below `parent`, registers its display path, and plans its symbols.
|
|
64
91
|
*
|
|
92
|
+
* @param parent - Node the file is added below.
|
|
93
|
+
* @param file - File to add.
|
|
65
94
|
* @param extracted - Symbols of the file, or `null` to add the file without symbols.
|
|
66
95
|
* @param embedText - Whether the node carries the file's full text.
|
|
96
|
+
* @returns Node of the file.
|
|
67
97
|
*/
|
|
68
98
|
private add;
|
|
69
|
-
/**
|
|
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
|
+
*/
|
|
70
106
|
private extract;
|
|
71
107
|
}
|
|
@@ -6,22 +6,26 @@ import type { MarkdownRenderer } from '../markdown/renderer';
|
|
|
6
6
|
import type { RawSymbol } from './extract';
|
|
7
7
|
import { type LanguageSpec } from './language';
|
|
8
8
|
import type { CallableIndex, TypeIndex, TypeLinker } from './types';
|
|
9
|
-
/**
|
|
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
|
+
*/
|
|
10
16
|
export interface FileContext {
|
|
11
17
|
readonly spec: LanguageSpec;
|
|
12
|
-
/** Display path of the file: its path below the source root, behind the source's prefix. */
|
|
13
18
|
readonly path: string;
|
|
14
|
-
/** Package or namespace the file declares. */
|
|
15
19
|
readonly packageName: string | null;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
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.
|
|
20
|
-
* links to the types they name.
|
|
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.
|
|
21
24
|
*
|
|
22
|
-
*
|
|
23
|
-
* links through. Created per scan by
|
|
24
|
-
* `CodePlanner` in `planner.ts` calls `plan` for
|
|
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.
|
|
25
29
|
*
|
|
26
30
|
* @example
|
|
27
31
|
* const symbols = new SymbolPlanner(graph, highlighter, markdown, types, callables, linker, resolvers);
|
|
@@ -35,34 +39,96 @@ export declare class SymbolPlanner {
|
|
|
35
39
|
private readonly callables;
|
|
36
40
|
private readonly linker;
|
|
37
41
|
private readonly resolvers;
|
|
38
|
-
/**
|
|
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
|
+
*/
|
|
39
53
|
constructor(graph: GraphBuilder, highlighter: CodeHighlighter, markdown: MarkdownRenderer, types: TypeIndex, callables: CallableIndex, linker: TypeLinker, resolvers: ProseResolvers);
|
|
40
|
-
/**
|
|
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
|
+
*/
|
|
41
61
|
plan(fileRef: NodeRef, file: FileContext, symbols: readonly RawSymbol[]): void;
|
|
42
62
|
/**
|
|
43
|
-
* Adds one symbol node with its parameter and field nodes, registers it in the type or
|
|
63
|
+
* @brief Adds one symbol node with its parameter and field nodes, registers it in the type or
|
|
44
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.
|
|
45
68
|
*/
|
|
46
69
|
private planSymbol;
|
|
47
70
|
/**
|
|
48
|
-
* Builds the content of a symbol node: highlighted signature, rendered description,
|
|
49
|
-
* return value, tags and example.
|
|
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.
|
|
50
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.
|
|
51
80
|
* @param self - Node of the symbol itself, where the edges start.
|
|
81
|
+
* @returns Content of the symbol node.
|
|
52
82
|
*/
|
|
53
83
|
private symbolContent;
|
|
54
|
-
/**
|
|
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
|
+
*/
|
|
55
93
|
private declarationContent;
|
|
56
94
|
/**
|
|
57
|
-
*
|
|
95
|
+
* @brief Builds the return value of a symbol from its declared return type and `@returns` tag.
|
|
58
96
|
*
|
|
59
|
-
* @
|
|
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.
|
|
60
103
|
*/
|
|
61
104
|
private returns;
|
|
62
|
-
/**
|
|
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
|
+
*/
|
|
63
113
|
private example;
|
|
64
|
-
/**
|
|
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
|
+
*/
|
|
65
123
|
private tag;
|
|
66
|
-
/**
|
|
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
|
+
*/
|
|
67
133
|
private html;
|
|
68
134
|
}
|