@open-cr-agent/code-graph 0.11.0 → 0.13.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/dist/extractor.d.ts +1 -0
- package/dist/extractor.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/parse.d.ts +1 -0
- package/dist/parse.js +34 -3
- package/dist/syntax.d.ts +2 -0
- package/dist/syntax.js +13 -0
- package/package.json +2 -2
package/dist/extractor.d.ts
CHANGED
package/dist/extractor.js
CHANGED
|
@@ -4,7 +4,7 @@ import { languageOf } from "./languages.js";
|
|
|
4
4
|
import { parseSymbols } from "./parse.js";
|
|
5
5
|
import { VERSION } from "./version.js";
|
|
6
6
|
// Larger files are generated or data more often than code a change calls.
|
|
7
|
-
const MAX_FILE_CHARS = 1_000_000;
|
|
7
|
+
export const MAX_FILE_CHARS = 1_000_000;
|
|
8
8
|
export function treeSitterSymbols(options = {}) {
|
|
9
9
|
const memo = new Map();
|
|
10
10
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { directoryCache, gitBlobId, type SymbolCache } from "./cache.js";
|
|
|
2
2
|
export { type TreeSitterOptions, treeSitterSymbols } from "./extractor.js";
|
|
3
3
|
export { type CodeGraph, type GraphUpdate, graphReferences, parseGraph, type ReadBlob, serializeGraph, type TreeEntry, type UpdateOptions, updateGraph, } from "./graph.js";
|
|
4
4
|
export { type ScipOptions, scipReferences } from "./scip.js";
|
|
5
|
+
export { treeSitterSyntax } from "./syntax.js";
|
package/dist/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { directoryCache, gitBlobId } from "./cache.js";
|
|
|
2
2
|
export { treeSitterSymbols } from "./extractor.js";
|
|
3
3
|
export { graphReferences, parseGraph, serializeGraph, updateGraph, } from "./graph.js";
|
|
4
4
|
export { scipReferences } from "./scip.js";
|
|
5
|
+
export { treeSitterSyntax } from "./syntax.js";
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { FileSymbols } from "@open-cr-agent/core";
|
|
2
2
|
import type { LanguageSpec } from "./languages.js";
|
|
3
3
|
export declare function parseSymbols(spec: LanguageSpec, content: string, budgetMs?: number): Promise<FileSymbols | undefined>;
|
|
4
|
+
export declare function parseErrors(spec: LanguageSpec, content: string, budgetMs?: number): Promise<number | undefined>;
|
package/dist/parse.js
CHANGED
|
@@ -49,8 +49,9 @@ function load(spec) {
|
|
|
49
49
|
}
|
|
50
50
|
return loaded;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
// A parse cancelled by its budget leaves the parser holding it, and the next
|
|
53
|
+
// parse would resume it on another file's text: reset it.
|
|
54
|
+
function parseWithin(parser, content, budgetMs) {
|
|
54
55
|
const deadline = performance.now() + budgetMs;
|
|
55
56
|
let late = false;
|
|
56
57
|
const progressCallback = () => {
|
|
@@ -58,12 +59,19 @@ export async function parseSymbols(spec, content, budgetMs = PARSE_BUDGET_MS) {
|
|
|
58
59
|
return late;
|
|
59
60
|
};
|
|
60
61
|
const tree = parser.parse(content, null, { progressCallback });
|
|
62
|
+
if (!tree)
|
|
63
|
+
parser.reset();
|
|
64
|
+
return { tree, progressCallback, late: () => late };
|
|
65
|
+
}
|
|
66
|
+
export async function parseSymbols(spec, content, budgetMs = PARSE_BUDGET_MS) {
|
|
67
|
+
const { parser, definitions, uses } = await load(spec);
|
|
68
|
+
const { tree, progressCallback, late } = parseWithin(parser, content, budgetMs);
|
|
61
69
|
if (!tree)
|
|
62
70
|
return undefined;
|
|
63
71
|
try {
|
|
64
72
|
const matches = definitions.matches(tree.rootNode, { progressCallback });
|
|
65
73
|
const captures = uses.captures(tree.rootNode, { progressCallback });
|
|
66
|
-
if (late)
|
|
74
|
+
if (late())
|
|
67
75
|
return undefined;
|
|
68
76
|
const found = collectDefinitions(matches);
|
|
69
77
|
const nameStarts = new Set(found.map((d) => d.nameStart));
|
|
@@ -84,6 +92,29 @@ export async function parseSymbols(spec, content, budgetMs = PARSE_BUDGET_MS) {
|
|
|
84
92
|
tree.delete();
|
|
85
93
|
}
|
|
86
94
|
}
|
|
95
|
+
// How many error and missing nodes the parser had to insert; undefined when
|
|
96
|
+
// the parse ran out of time.
|
|
97
|
+
export async function parseErrors(spec, content, budgetMs = PARSE_BUDGET_MS) {
|
|
98
|
+
const { parser } = await load(spec);
|
|
99
|
+
const { tree } = parseWithin(parser, content, budgetMs);
|
|
100
|
+
if (!tree)
|
|
101
|
+
return undefined;
|
|
102
|
+
try {
|
|
103
|
+
let errors = 0;
|
|
104
|
+
const pending = [tree.rootNode];
|
|
105
|
+
for (let node = pending.pop(); node; node = pending.pop()) {
|
|
106
|
+
if (node.isError || node.isMissing)
|
|
107
|
+
errors += 1;
|
|
108
|
+
for (const child of node.children)
|
|
109
|
+
if (child?.hasError || child?.isMissing)
|
|
110
|
+
pending.push(child);
|
|
111
|
+
}
|
|
112
|
+
return errors;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
tree.delete();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
87
118
|
function collectDefinitions(matches) {
|
|
88
119
|
const byNode = new Map();
|
|
89
120
|
for (const { captures } of matches) {
|
package/dist/syntax.d.ts
ADDED
package/dist/syntax.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MAX_FILE_CHARS } from "./extractor.js";
|
|
2
|
+
import { languageOf } from "./languages.js";
|
|
3
|
+
import { parseErrors } from "./parse.js";
|
|
4
|
+
export function treeSitterSyntax() {
|
|
5
|
+
return {
|
|
6
|
+
errors(path, content) {
|
|
7
|
+
const spec = languageOf(path);
|
|
8
|
+
if (!spec || content.length > MAX_FILE_CHARS)
|
|
9
|
+
return Promise.resolve(undefined);
|
|
10
|
+
return parseErrors(spec, content);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-cr-agent/code-graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Tree-sitter symbols for Open-CR-Agent's impact analysis, cached by git blob id",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-review",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@bufbuild/protobuf": "2.17.0",
|
|
36
|
-
"@open-cr-agent/core": "0.
|
|
36
|
+
"@open-cr-agent/core": "0.13.0",
|
|
37
37
|
"@scip-code/scip": "0.10.0",
|
|
38
38
|
"@vscode/tree-sitter-wasm": "0.3.1",
|
|
39
39
|
"zod": "^4.6.6"
|