@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.
Files changed (133) hide show
  1. package/LICENSE +95 -0
  2. package/README.md +76 -2
  3. package/dist/THIRD_PARTY_LICENSES.txt +1904 -0
  4. package/dist/api/bundle-builder.d.ts +94 -0
  5. package/dist/api/bundle-cache.d.ts +73 -0
  6. package/dist/api/bundle-loader.d.ts +65 -0
  7. package/dist/api/create-docs.d.ts +91 -0
  8. package/dist/api/embedding.d.ts +41 -0
  9. package/dist/api/errors.d.ts +35 -0
  10. package/dist/api/list.d.ts +106 -0
  11. package/dist/api/options.d.ts +74 -0
  12. package/dist/api/refs.d.ts +136 -0
  13. package/dist/api/scan.d.ts +56 -0
  14. package/dist/api/search.d.ts +132 -0
  15. package/dist/api/services.d.ts +15 -0
  16. package/dist/api/show.d.ts +100 -0
  17. package/dist/api/site-reader.d.ts +19 -0
  18. package/dist/api/site-writer.d.ts +43 -0
  19. package/dist/api/source.d.ts +57 -0
  20. package/dist/api/target.d.ts +12 -0
  21. package/dist/api/template.d.ts +5 -0
  22. package/dist/assets/tree-sitter-c-sharp.wasm +0 -0
  23. package/dist/assets/tree-sitter-c.wasm +0 -0
  24. package/dist/assets/tree-sitter-cpp.wasm +0 -0
  25. package/dist/assets/tree-sitter-go.wasm +0 -0
  26. package/dist/assets/tree-sitter-java.wasm +0 -0
  27. package/dist/assets/tree-sitter-javascript.wasm +0 -0
  28. package/dist/assets/tree-sitter-kotlin.wasm +0 -0
  29. package/dist/assets/tree-sitter-php.wasm +0 -0
  30. package/dist/assets/tree-sitter-python.wasm +0 -0
  31. package/dist/assets/tree-sitter-ruby.wasm +0 -0
  32. package/dist/assets/tree-sitter-rust.wasm +0 -0
  33. package/dist/assets/tree-sitter-scala.wasm +0 -0
  34. package/dist/assets/tree-sitter-tsx.wasm +0 -0
  35. package/dist/assets/tree-sitter-typescript.wasm +0 -0
  36. package/dist/assets/vectors.bin +0 -0
  37. package/dist/assets/vocab.txt +33731 -0
  38. package/dist/cli.js +9317 -0
  39. package/dist/embeddings/abbreviations.d.ts +7 -0
  40. package/dist/embeddings/index-builder.d.ts +12 -0
  41. package/dist/embeddings/index.d.ts +10 -0
  42. package/dist/embeddings/model.d.ts +126 -0
  43. package/dist/embeddings/searcher.d.ts +84 -0
  44. package/dist/embeddings/vectors.d.ts +77 -0
  45. package/dist/embeddings/words.d.ts +46 -0
  46. package/dist/index.d.ts +9 -0
  47. package/dist/index.js +8747 -0
  48. package/dist/model/index.d.ts +788 -0
  49. package/dist/model/registry.d.ts +687 -0
  50. package/dist/query/graph.d.ts +123 -0
  51. package/dist/query/index.d.ts +4 -0
  52. package/dist/query/name-search.d.ts +65 -0
  53. package/dist/query/semantic.d.ts +38 -0
  54. package/dist/query/text.d.ts +22 -0
  55. package/dist/retrieval/describe.d.ts +33 -0
  56. package/dist/retrieval/filter.d.ts +36 -0
  57. package/dist/retrieval/index.d.ts +7 -0
  58. package/dist/retrieval/markdown.d.ts +17 -0
  59. package/dist/retrieval/report.d.ts +291 -0
  60. package/dist/retrieval/resolve.d.ts +31 -0
  61. package/dist/retrieval/retriever.d.ts +105 -0
  62. package/dist/retrieval/summary.d.ts +27 -0
  63. package/dist/scanner/code/doc/clean.d.ts +36 -0
  64. package/dist/scanner/code/doc/index.d.ts +12 -0
  65. package/dist/scanner/code/doc/markdown.d.ts +8 -0
  66. package/dist/scanner/code/doc/python.d.ts +8 -0
  67. package/dist/scanner/code/doc/tagged.d.ts +19 -0
  68. package/dist/scanner/code/doc/types.d.ts +33 -0
  69. package/dist/scanner/code/doc/xml.d.ts +8 -0
  70. package/dist/scanner/code/example.d.ts +57 -0
  71. package/dist/scanner/code/extract.d.ts +113 -0
  72. package/dist/scanner/code/grammar.d.ts +44 -0
  73. package/dist/scanner/code/language.d.ts +183 -0
  74. package/dist/scanner/code/languages/c-family.d.ts +5 -0
  75. package/dist/scanner/code/languages/csharp.d.ts +3 -0
  76. package/dist/scanner/code/languages/ecmascript.d.ts +7 -0
  77. package/dist/scanner/code/languages/go.d.ts +3 -0
  78. package/dist/scanner/code/languages/index.d.ts +33 -0
  79. package/dist/scanner/code/languages/java.d.ts +3 -0
  80. package/dist/scanner/code/languages/kotlin.d.ts +3 -0
  81. package/dist/scanner/code/languages/php.d.ts +3 -0
  82. package/dist/scanner/code/languages/python.d.ts +3 -0
  83. package/dist/scanner/code/languages/ruby.d.ts +3 -0
  84. package/dist/scanner/code/languages/rust.d.ts +3 -0
  85. package/dist/scanner/code/languages/scala.d.ts +3 -0
  86. package/dist/scanner/code/languages/shared.d.ts +36 -0
  87. package/dist/scanner/code/planner.d.ts +107 -0
  88. package/dist/scanner/code/symbols.d.ts +134 -0
  89. package/dist/scanner/code/types.d.ts +126 -0
  90. package/dist/scanner/config.d.ts +42 -0
  91. package/dist/scanner/content.d.ts +73 -0
  92. package/dist/scanner/decisions/parse.d.ts +37 -0
  93. package/dist/scanner/decisions/planner.d.ts +42 -0
  94. package/dist/scanner/docs.d.ts +69 -0
  95. package/dist/scanner/files.d.ts +85 -0
  96. package/dist/scanner/glossary/parse.d.ts +40 -0
  97. package/dist/scanner/glossary/planner.d.ts +49 -0
  98. package/dist/scanner/glossary/terms.d.ts +116 -0
  99. package/dist/scanner/graph/builder.d.ts +114 -0
  100. package/dist/scanner/highlight.d.ts +54 -0
  101. package/dist/scanner/ignore.d.ts +25 -0
  102. package/dist/scanner/index.d.ts +43 -0
  103. package/dist/scanner/markdown/frontmatter.d.ts +24 -0
  104. package/dist/scanner/markdown/links.d.ts +60 -0
  105. package/dist/scanner/markdown/outline.d.ts +35 -0
  106. package/dist/scanner/markdown/renderer.d.ts +63 -0
  107. package/dist/scanner/openapi/planner.d.ts +96 -0
  108. package/dist/scanner/packages.d.ts +28 -0
  109. package/dist/scanner/reporter.d.ts +10 -0
  110. package/dist/scanner/scanner.d.ts +66 -0
  111. package/dist/scanner/schema/definitions.d.ts +79 -0
  112. package/dist/scanner/schema/describe.d.ts +105 -0
  113. package/dist/scanner/schema/planner.d.ts +49 -0
  114. package/dist/scanner/schema/registry.d.ts +68 -0
  115. package/dist/scanner/skills/classify.d.ts +21 -0
  116. package/dist/scanner/skills/layout.d.ts +46 -0
  117. package/dist/scanner/skills/planner.d.ts +61 -0
  118. package/dist/scanner/specs.d.ts +56 -0
  119. package/dist/scanner/sql/catalog.d.ts +98 -0
  120. package/dist/scanner/sql/cursor.d.ts +112 -0
  121. package/dist/scanner/sql/database.d.ts +51 -0
  122. package/dist/scanner/sql/parse.d.ts +122 -0
  123. package/dist/scanner/sql/planner.d.ts +69 -0
  124. package/dist/scanner/sql/query.d.ts +73 -0
  125. package/dist/scanner/sql/registry.d.ts +63 -0
  126. package/dist/scanner/sql/source.d.ts +10 -0
  127. package/dist/scanner/sql/statements.d.ts +42 -0
  128. package/dist/scanner/sql/tokens.d.ts +51 -0
  129. package/dist/scanner/tasks/layout.d.ts +52 -0
  130. package/dist/scanner/tasks/planner.d.ts +130 -0
  131. package/dist/scanner/tasks/schema.d.ts +88 -0
  132. package/dist/scanner/text.d.ts +14 -0
  133. package/package.json +104 -4
@@ -0,0 +1,105 @@
1
+ import type { NodeRef } from '../model';
2
+ import { type Graph } from '../query';
3
+ import { type ReferenceOptions } from './describe';
4
+ import { type NodeFilter } from './filter';
5
+ import type { NodeReport, NodeSummary, References } from './report';
6
+ import { type Resolution } from './resolve';
7
+ /** The search modes a caller can pick from, the default first. */
8
+ export declare const SEARCH_MODES: readonly ['both', 'name', 'meaning'];
9
+ /** How a search matches: `name` by the words of a name or a description, `meaning` by the embedding model, `both` by words first and then by meaning. */
10
+ export type SearchMode = (typeof SEARCH_MODES)[number];
11
+ /**
12
+ * @brief How one search is run.
13
+ *
14
+ * @property mode - How the search matches: `name`, `meaning` or `both`.
15
+ * @property limit - Most hits to return, both ways of matching together.
16
+ * @property filter - Narrows the nodes that count, such as to one kind.
17
+ */
18
+ export interface SearchOptions {
19
+ readonly mode: SearchMode;
20
+ readonly limit: number;
21
+ readonly filter: NodeFilter;
22
+ }
23
+ /**
24
+ * @brief One result of a search: a node summary with how it matched.
25
+ *
26
+ * @property match - `name`: every word of the query is in the name or the path of the node. `text`: at least one word is only in its description. `meaning`: the node is close to the query in the embedding model.
27
+ * @property score - From 0 to 1 for a match by meaning. `null` for a match by words.
28
+ */
29
+ export interface SearchHit extends NodeSummary {
30
+ readonly match: 'name' | 'text' | 'meaning';
31
+ readonly score: number | null;
32
+ }
33
+ /**
34
+ * @brief Answers queries on one bundle: search, list, look up, describe.
35
+ *
36
+ * Holds the graph of the bundle and, after the first search by name, the
37
+ * search index. `openRetriever` in `api/source.ts` creates one per request from
38
+ * a `Graph`; `listIn`, `searchIn`, `showIn` and `refsIn` in `api/` each call one
39
+ * method. Create one with `new Retriever(new Graph(bundle))`. Every answer is
40
+ * plain data with ids, so a caller can print it, serialize it or feed an id into
41
+ * the next call.
42
+ */
43
+ export declare class Retriever {
44
+ private readonly graph;
45
+ private nameIndex;
46
+ /**
47
+ * @brief Creates a retriever for one bundle.
48
+ *
49
+ * @param graph - Graph of the bundle, from `new Graph(bundle)`.
50
+ */
51
+ constructor(graph: Graph);
52
+ /**
53
+ * @brief Names the embedding model that searches by meaning.
54
+ *
55
+ * @returns The name, or `null` when the bundle was built without embeddings.
56
+ */
57
+ get model(): string | null;
58
+ /**
59
+ * @brief Finds pages and entries for a query. Matches by words come first, in the
60
+ * order the site lists them. Matches by meaning follow, best first.
61
+ *
62
+ * @param query - Words of a name, or a query in plain language.
63
+ * @param options - How the search runs: its mode, its limit and its filter.
64
+ * @returns The hits, each once.
65
+ */
66
+ search(query: string, options: SearchOptions): SearchHit[];
67
+ /**
68
+ * @brief Lists pages and entries in display order.
69
+ *
70
+ * @param filter - Narrows the nodes listed.
71
+ * @param limit - Most rows to return. `null` returns all of them.
72
+ * @returns One row per node.
73
+ */
74
+ list(filter: NodeFilter, limit: number | null): NodeSummary[];
75
+ /**
76
+ * @brief Finds the node a caller means by an id, a file path or a name.
77
+ *
78
+ * @param text - What the caller wrote.
79
+ * @param filter - Narrows the nodes that count, to tell two nodes with one name apart.
80
+ * @returns The node, the candidates when several fit, or `missing`.
81
+ */
82
+ resolve(text: string, filter: NodeFilter): Resolution;
83
+ /**
84
+ * @brief Describes a node in one row.
85
+ *
86
+ * @param node - A page or an entry.
87
+ * @returns Its id, kind, title, place on disk and summary.
88
+ */
89
+ summarize(node: NodeRef): NodeSummary;
90
+ /**
91
+ * @brief Builds the full report of a node.
92
+ *
93
+ * @param node - A page or an entry.
94
+ * @returns Everything its page shows, with texts as markdown.
95
+ */
96
+ describe(node: NodeRef): NodeReport;
97
+ /**
98
+ * @brief Lists the edges of a node.
99
+ *
100
+ * @param node - A page or an entry.
101
+ * @param options - Which edges to keep, by direction and kind.
102
+ * @returns What the node links to and what links to it.
103
+ */
104
+ references(node: NodeRef, options?: ReferenceOptions): References;
105
+ }
@@ -0,0 +1,27 @@
1
+ import { type NodeRef } from '../model';
2
+ import { type Graph } from '../query';
3
+ import type { NodeSummary } from './report';
4
+ /**
5
+ * @brief Builds the id of a node: its route as the address of its page spells it,
6
+ * without the leading `#/`.
7
+ *
8
+ * @param graph - Graph the node belongs to.
9
+ * @param node - The node. A parameter or a field has the id of its symbol.
10
+ * @returns The id, such as `docs/glossary.md#term:lane`.
11
+ */
12
+ export declare function nodeId(graph: Graph, node: NodeRef): string;
13
+ /**
14
+ * @brief Reduces an id, an address copied from the browser or an href of the site to an id.
15
+ *
16
+ * @param text - What the caller wrote, such as `#/code/src/app.ts#symbol:App.run` or `file:///site/docs.html#/code/src/app.ts`.
17
+ * @returns The id without the file, `#/` or slashes around it, with percent escapes decoded.
18
+ */
19
+ export declare function normalizeId(text: string): string;
20
+ /**
21
+ * @brief Describes a node in one row: what a search hit, a list row and a reference show.
22
+ *
23
+ * @param graph - Graph the node belongs to.
24
+ * @param node - The node. A parameter or a field is not listed on its own, so pass its symbol.
25
+ * @returns The row of the node.
26
+ */
27
+ export declare function summarize(graph: Graph, node: NodeRef): NodeSummary;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @brief Strips comment markers from the text of consecutive comment nodes.
3
+ *
4
+ * @param comments - Raw text of each comment node, markers included.
5
+ * @returns The text of the comments, without the lines that configure tools such as `eslint-disable`.
6
+ */
7
+ export declare function cleanComments(comments: readonly string[]): string;
8
+ /**
9
+ * @brief Strips the quotes of a Python string literal and lays out its lines like `inspect.cleandoc`.
10
+ *
11
+ * @param literal - Source text of the string literal, quotes included.
12
+ * @returns The docstring text.
13
+ */
14
+ export declare function cleanDocstring(literal: string): string;
15
+ /**
16
+ * @brief Finds the text of the first fenced code block.
17
+ *
18
+ * @param markdown - Markdown to search.
19
+ * @returns The block without its fences, or `null` when there is none.
20
+ */
21
+ export declare function firstFencedBlock(markdown: string): string | null;
22
+ /**
23
+ * @brief Applies `transform` to every line outside fenced code blocks.
24
+ *
25
+ * @param markdown - Markdown to rewrite.
26
+ * @param transform - Maps one prose line to its new text.
27
+ * @returns The markdown with the prose lines transformed. Fenced lines stay as they are.
28
+ */
29
+ export declare function mapProseLines(markdown: string, transform: (line: string) => string): string;
30
+ /**
31
+ * @brief Turns markdown headings into bold lines, so a description never outranks its symbol title.
32
+ *
33
+ * @param markdown - Markdown of a description.
34
+ * @returns The markdown with bold lines in place of its headings.
35
+ */
36
+ export declare function demoteHeadings(markdown: string): string;
@@ -0,0 +1,12 @@
1
+ import type { DocStyle } from '../language';
2
+ import { type ParsedDoc } from './types';
3
+ export { cleanComments, cleanDocstring } from './clean';
4
+ export type { ParsedDoc, ParsedTag, ParsedTagKind } from './types';
5
+ /**
6
+ * @brief Parses cleaned doc comment text in the given dialect.
7
+ *
8
+ * @param style - Dialect the comment is written in.
9
+ * @param text - Comment text without its markers, or `null` when the symbol has no comment.
10
+ * @returns The parsed doc, with its headings demoted. `EMPTY_DOC` for an empty or missing comment.
11
+ */
12
+ export declare function parseDoc(style: DocStyle, text: string | null): ParsedDoc;
@@ -0,0 +1,8 @@
1
+ import type { ParsedDoc } from './types';
2
+ /**
3
+ * @brief Parses a markdown doc comment (rustdoc, godoc). An "Examples" section becomes the example.
4
+ *
5
+ * @param text - Markdown doc comment text, cleaned of its markers.
6
+ * @returns The parsed doc.
7
+ */
8
+ export declare function parseMarkdownDoc(text: string): ParsedDoc;
@@ -0,0 +1,8 @@
1
+ import type { ParsedDoc } from './types';
2
+ /**
3
+ * @brief Parses a docstring in Google, NumPy or reST layout.
4
+ *
5
+ * @param text - Docstring content, cleaned of its quotes.
6
+ * @returns The description, the tags and the example.
7
+ */
8
+ export declare function parsePythonDoc(text: string): ParsedDoc;
@@ -0,0 +1,19 @@
1
+ import type { ParsedDoc } from './types';
2
+ /**
3
+ * @brief Dialect switches for `parseTagged`.
4
+ *
5
+ * @property titledExamples - YARD puts an example title on the `@example` line.
6
+ * @property braceLinks - YARD links to code with braces, as in `{Label.parse}` and `{#render}`.
7
+ */
8
+ export interface TaggedOptions {
9
+ readonly titledExamples?: boolean;
10
+ readonly braceLinks?: boolean;
11
+ }
12
+ /**
13
+ * @brief Parses a doc comment written with `@tag` lines.
14
+ *
15
+ * @param text - Doc comment text, cleaned of its markers.
16
+ * @param options - Dialect switches. Empty for the tagged dialect, `{ titledExamples, braceLinks }` for YARD.
17
+ * @returns The description, the tags and the example.
18
+ */
19
+ export declare function parseTagged(text: string, options?: TaggedOptions): ParsedDoc;
@@ -0,0 +1,33 @@
1
+ import type { DocTagKind } from '../../../model';
2
+ /** Tag kinds a parser emits. The planner folds the first three into parameters, return value and fields. */
3
+ export type ParsedTagKind = 'param' | 'returns' | 'field' | DocTagKind;
4
+ /**
5
+ * @brief One tag of a parsed doc comment, such as a parameter or a return value.
6
+ *
7
+ * @property kind - Kind of the tag.
8
+ * @property label - Label of an `other` tag, as the comment writes it.
9
+ * @property name - Name of the parameter, field or exception the tag is about.
10
+ * @property type - Type as the comment writes it, when it writes one.
11
+ * @property text - Markdown.
12
+ */
13
+ export interface ParsedTag {
14
+ readonly kind: ParsedTagKind;
15
+ readonly label?: string;
16
+ readonly name?: string;
17
+ readonly type?: string;
18
+ readonly text: string;
19
+ }
20
+ /**
21
+ * @brief A doc comment parsed into description, tags and example, the same for every dialect.
22
+ *
23
+ * @property description - Markdown.
24
+ * @property tags - Tags in the order the comment writes them.
25
+ * @property example - Example source code, when the comment documents one.
26
+ */
27
+ export interface ParsedDoc {
28
+ readonly description: string;
29
+ readonly tags: readonly ParsedTag[];
30
+ readonly example: string | null;
31
+ }
32
+ /** Result for a symbol with no doc comment. */
33
+ export declare const EMPTY_DOC: ParsedDoc;
@@ -0,0 +1,8 @@
1
+ import type { ParsedDoc } from './types';
2
+ /**
3
+ * @brief Parses C# XML documentation comments. Text without XML elements is the description.
4
+ *
5
+ * @param text - Doc comment text, with its XML elements.
6
+ * @returns The description, the tags and the example.
7
+ */
8
+ export declare function parseXmlDoc(text: string): ParsedDoc;
@@ -0,0 +1,57 @@
1
+ import { type SymbolKind } from '../../model';
2
+ import type { CallStyle, ImportContext } from './language';
3
+ /**
4
+ * What a generated example needs to know about the type a method belongs to.
5
+ *
6
+ * @property kind - Kind of the owning type, such as `class` or `struct`.
7
+ * @property name - Name of the owning type.
8
+ * @property args - Constructor argument expressions of the type, receivers excluded.
9
+ * @property hasConstructor - True when the scanner found a constructor for the type.
10
+ * @property instantiable - False when the type is abstract or a singleton.
11
+ */
12
+ export interface ParentTarget {
13
+ readonly kind: SymbolKind;
14
+ readonly name: string;
15
+ readonly args: readonly string[];
16
+ readonly hasConstructor: boolean;
17
+ readonly instantiable: boolean;
18
+ }
19
+ /**
20
+ * The symbol a generated example calls or constructs, with what decides how.
21
+ *
22
+ * @property kind - Kind of the symbol, such as `function`, `method`, `class` or `struct`.
23
+ * @property name - Name of the symbol.
24
+ * @property args - Argument expressions, receivers excluded.
25
+ * @property parent - Type or namespace the symbol belongs to, or `null` for a top-level symbol.
26
+ * @property isStatic - True when the symbol is called on its type rather than on an instance.
27
+ * @property isAsync - True when the call must be awaited.
28
+ * @property instantiable - For types: false when abstract or a singleton.
29
+ * @property isConstructor - True when the symbol is a constructor of `parent`.
30
+ * @property hasConstructor - For types: whether a constructor was found.
31
+ * @property returnsValue - True when the call yields a value that the example binds to a variable.
32
+ * @property returnType - Declared return type, or `null` when none is declared.
33
+ * @property importContext - What to import, or `null` when the symbol needs no import or none can be derived.
34
+ */
35
+ export interface CallTarget {
36
+ readonly kind: SymbolKind;
37
+ readonly name: string;
38
+ readonly args: readonly string[];
39
+ readonly parent: ParentTarget | null;
40
+ readonly isStatic: boolean;
41
+ readonly isAsync: boolean;
42
+ readonly instantiable: boolean;
43
+ readonly isConstructor: boolean;
44
+ readonly hasConstructor: boolean;
45
+ readonly returnsValue: boolean;
46
+ readonly returnType: string | null;
47
+ readonly importContext: ImportContext | null;
48
+ }
49
+ /**
50
+ * @brief Builds a usage example from a signature: an import where the language allows one,
51
+ * the instance a method needs, then the call.
52
+ *
53
+ * @param style - Call syntax of the target's language.
54
+ * @param target - Symbol the example uses.
55
+ * @returns Example source, or `null` for symbols that are not called.
56
+ */
57
+ export declare function buildExample(style: CallStyle, target: CallTarget): string | null;
@@ -0,0 +1,113 @@
1
+ import { type SymbolKind } from '../../model';
2
+ import type { Node, Query } from 'web-tree-sitter';
3
+ import type { LanguageSpec } from './language';
4
+ /**
5
+ * One parameter as declared.
6
+ *
7
+ * @property name - Name with its variadic marker, such as `...rest` or `*args`.
8
+ * @property type - Declared type text, or `null` when the language or declaration has none.
9
+ * @property defaultValue - Default value text, truncated, or `null` when there is none.
10
+ * @property optional - True when the parameter may be left out of a call.
11
+ * @property argument - Expression a generated call passes for this parameter.
12
+ */
13
+ export interface RawParameter {
14
+ readonly name: string;
15
+ readonly type: string | null;
16
+ defaultValue: string | null;
17
+ optional: boolean;
18
+ readonly argument: string;
19
+ }
20
+ /**
21
+ * A field, property or enum member as declared.
22
+ *
23
+ * @property name - Name of the field.
24
+ * @property type - Declared type text, or `null` when none is declared.
25
+ * @property defaultValue - Initial value text, truncated, or `null` when there is none.
26
+ * @property optional - True when the field is nullable or optional.
27
+ * @property annotations - Decorator, attribute and annotation texts on the field.
28
+ * @property comment - Cleaned doc comment text, or `null`.
29
+ */
30
+ export interface RawField {
31
+ readonly name: string;
32
+ readonly type: string | null;
33
+ readonly defaultValue: string | null;
34
+ readonly optional: boolean;
35
+ readonly annotations: readonly string[];
36
+ readonly comment: string | null;
37
+ }
38
+ /**
39
+ * @brief One definition as found in the syntax tree, before rendering.
40
+ *
41
+ * @property kind - Kind of the symbol, such as `function`, `method`, `class` or `enum`.
42
+ * @property signature - Declaration head. Empty when `inferred`.
43
+ * @property modifiers - Keywords in front of the name, such as `export` or `static`.
44
+ * @property comment - Cleaned doc comment text, or `null`.
45
+ * @property parameters - Parameters as declared, with the receiver left out.
46
+ * @property fields - Fields, properties and enum members declared on this type.
47
+ * @property returnType - Declared return type text, or `null`.
48
+ * @property typeParameters - Names the declaration introduces as type parameters, such as `T`. They never name a real type.
49
+ * @property heritage - For a type: the text after its name that lists what it extends or is composed of. `''` otherwise.
50
+ * @property instantiable - False for abstract classes and singletons.
51
+ * @property isStatic - True for a method called on its type rather than on an instance.
52
+ * @property returnsValue - True when a call to the symbol yields a value.
53
+ * @property inferred - True for an owner type that is not declared in this file.
54
+ * @property children - Members nested under this symbol.
55
+ */
56
+ export interface RawSymbol {
57
+ kind: SymbolKind;
58
+ readonly name: string;
59
+ readonly line: number;
60
+ readonly signature: string;
61
+ readonly modifiers: readonly string[];
62
+ readonly annotations: readonly string[];
63
+ readonly comment: string | null;
64
+ readonly parameters: readonly RawParameter[];
65
+ readonly fields: RawField[];
66
+ readonly returnType: string | null;
67
+ readonly typeParameters: readonly string[];
68
+ readonly heritage: string;
69
+ readonly isAsync: boolean;
70
+ readonly instantiable: boolean;
71
+ isStatic: boolean;
72
+ returnsValue: boolean;
73
+ readonly inferred: boolean;
74
+ readonly children: RawSymbol[];
75
+ }
76
+ /**
77
+ * Symbols and package name extracted from one source file.
78
+ *
79
+ * @property symbols - Top-level symbols of the file, each with its members nested under it.
80
+ * @property packageName - Package or namespace the file declares, or `null` when the language has none.
81
+ */
82
+ export interface ExtractedFile {
83
+ readonly symbols: RawSymbol[];
84
+ readonly packageName: string | null;
85
+ }
86
+ /**
87
+ * @brief Turns a parsed file into a tree of {@link RawSymbol}s, driven by a {@link LanguageSpec}.
88
+ *
89
+ * Holds no state, so one instance serves every file. Created with `new SymbolExtractor()` by
90
+ * `RepositoryScanner` in `scanner/scanner.ts` and passed to `CodePlanner` in `planner.ts`, which
91
+ * calls {@link SymbolExtractor.extract} once per parsed file.
92
+ */
93
+ export declare class SymbolExtractor {
94
+ /**
95
+ * Runs the language's tags query over the tree and builds the symbol tree from its matches.
96
+ *
97
+ * @param root - Root node of the parsed tree.
98
+ * @param query - Compiled tags query of the language.
99
+ * @param spec - Language spec that drives the extraction.
100
+ * @param source - Full text of the file the tree was parsed from; node offsets index into it.
101
+ * @returns Symbols of the file and its declared package name.
102
+ */
103
+ extract(root: Node, query: Query, spec: LanguageSpec, source: string): ExtractedFile;
104
+ /**
105
+ * @brief Merges the query matches into one definition per node (per name for fields), sorted by
106
+ * position with outer nodes first, and picks up the declared package name.
107
+ *
108
+ * @param root - Root node of the parsed tree.
109
+ * @param query - Compiled tags query of the language.
110
+ * @returns Merged definitions, and the package name or `null` when none is declared.
111
+ */
112
+ private collect;
113
+ }
@@ -0,0 +1,44 @@
1
+ import { Parser, Query } from 'web-tree-sitter';
2
+ import type { LanguageSpec } from './language';
3
+ /**
4
+ * Parser and compiled tags query for one language.
5
+ *
6
+ * @property parser - Tree-sitter parser set to the language.
7
+ * @property query - Tags query compiled against the language.
8
+ */
9
+ export interface LoadedGrammar {
10
+ readonly parser: Parser;
11
+ readonly query: Query;
12
+ }
13
+ /**
14
+ * Loads tree-sitter grammars on first use and keeps one parser and compiled query per language.
15
+ *
16
+ * Holds the tree-sitter runtime init promise and one pending {@link LoadedGrammar} per
17
+ * language id. Created with `new GrammarLoader(baseDir)` by `RepositoryScanner` in
18
+ * `scanner/scanner.ts`; `CodePlanner` in `planner.ts` calls `load` for each file it parses.
19
+ */
20
+ export declare class GrammarLoader {
21
+ private readonly baseDir;
22
+ private runtime;
23
+ private readonly grammars;
24
+ /**
25
+ * Stores the directory grammar paths resolve against. Nothing loads until the first `load`.
26
+ *
27
+ * @param baseDir - Absolute directory that relative grammar paths resolve against.
28
+ */
29
+ constructor(baseDir: string);
30
+ /**
31
+ * Returns the cached grammar of the spec's language, loading it on the first call.
32
+ *
33
+ * @param spec - Language whose grammar is needed.
34
+ * @returns Parser and query for the language, resolved once the grammar is loaded.
35
+ */
36
+ load(spec: LanguageSpec): Promise<LoadedGrammar>;
37
+ /**
38
+ * Initialises the tree-sitter runtime once, then loads the grammar `.wasm` and compiles the query.
39
+ *
40
+ * @param spec - Language to load.
41
+ * @returns Parser and query for the language.
42
+ */
43
+ private create;
44
+ }
@@ -0,0 +1,183 @@
1
+ import type { SymbolKind } from '../../model';
2
+ import type { Node } from 'web-tree-sitter';
3
+ /**
4
+ * @brief Doc comment dialect, which decides how the scanner reads doc comments.
5
+ *
6
+ * - `tagged`: `@param`-style tags (JSDoc, Javadoc, Doxygen, PHPDoc, KDoc, Scaladoc).
7
+ * - `yard`: `tagged`, with the title of an `@example` on the tag line.
8
+ * - `markdown`: free markdown with headed sections (rustdoc, godoc).
9
+ * - `python`: docstrings in Google, NumPy or reST layout.
10
+ * - `xml`: C# XML documentation.
11
+ */
12
+ export type DocStyle = 'tagged' | 'yard' | 'markdown' | 'python' | 'xml';
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
+ */
22
+ export interface DefinitionFacts {
23
+ readonly node: Node;
24
+ readonly signature: string;
25
+ readonly annotations: readonly string[];
26
+ readonly returnType: string | null;
27
+ readonly hasReceiver: boolean;
28
+ }
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
+ */
38
+ export interface ImportContext {
39
+ readonly filePath: string;
40
+ readonly name: string;
41
+ readonly kind: SymbolKind;
42
+ readonly modifiers: readonly string[];
43
+ readonly packageName: string | null;
44
+ }
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
+ */
55
+ export interface CallStyle {
56
+ readonly terminator: string;
57
+ readonly variableCase: 'camel' | 'snake';
58
+ readonly variablePrefix?: string;
59
+ readonly memberAccess: string;
60
+ readonly staticAccess: string;
61
+ readonly namespaceAccess: string | null;
62
+ /** Binds the value of `expression` to `variable`. */
63
+ declare(variable: string, expression: string, returnType: string | null): string;
64
+ /**
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.
69
+ */
70
+ construct(type: string, args: string, variable: string, hasConstructor: boolean): string | null;
71
+ /** Wraps an expression that must be awaited. */
72
+ await?(expression: string): string;
73
+ /**
74
+ * Rewrites one argument, for languages with named arguments.
75
+ *
76
+ * @param parameter - Declaration node of the parameter the argument fills.
77
+ */
78
+ argument?(name: string, parameter: Node): string;
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
+ */
85
+ importLine?(context: ImportContext): string | null;
86
+ }
87
+ /**
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.
119
+ */
120
+ export interface LanguageSpec {
121
+ readonly id: string;
122
+ readonly label: string;
123
+ readonly family?: string;
124
+ readonly extensions: readonly string[];
125
+ readonly accepts?: (source: string) => boolean;
126
+ readonly grammarPath: string;
127
+ readonly highlight: string;
128
+ readonly query: string;
129
+ readonly typeSyntax: 'prefix' | 'suffix' | 'none';
130
+ readonly annotationLabel: string;
131
+ readonly docStyle: DocStyle;
132
+ readonly docSource: 'leading-comment' | 'docstring';
133
+ readonly commentTypes: readonly string[];
134
+ readonly isDocComment?: (text: string) => boolean;
135
+ readonly annotationTypes: readonly string[];
136
+ readonly wrapperTypes: readonly string[];
137
+ readonly localScopeTypes: readonly string[];
138
+ readonly hoistedCommentParents?: readonly string[];
139
+ readonly receiverTypes?: readonly string[];
140
+ readonly receiverNames?: readonly string[];
141
+ readonly skippedParamTypes?: readonly string[];
142
+ readonly paramTypes?: readonly string[];
143
+ readonly isInstantiable?: (signature: string) => boolean;
144
+ readonly inferredOwnerKind?: SymbolKind;
145
+ readonly splitQualifiedName?: (name: string) => {
146
+ owner: string;
147
+ name: string;
148
+ } | null;
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
+ */
154
+ constructorNames(className: string): readonly string[];
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
+ */
160
+ isStatic(facts: DefinitionFacts): boolean;
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
+ */
166
+ returnsValue(facts: DefinitionFacts): boolean;
167
+ readonly declaredReturnType?: (facts: DefinitionFacts) => string | null;
168
+ readonly call: CallStyle;
169
+ }
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
+ */
176
+ export declare function familyOf(spec: LanguageSpec): string;
177
+ /**
178
+ * Decides from a declared return type whether a call yields a value.
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.
182
+ */
183
+ export declare function returnsValueFrom(returnType: string | null, implicit: boolean): boolean;