@repometry/tree-sitter 0.1.0 → 0.2.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repometry/tree-sitter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The tree-sitter language plugin engine for Repometry",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"prepack": "npm run build"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@repometry/core": "0.
|
|
41
|
+
"@repometry/core": "0.3.0",
|
|
42
42
|
"web-tree-sitter": "0.27.2"
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -45,6 +45,7 @@ export interface Grammar {
|
|
|
45
45
|
readonly lineBreaks?: RegExp;
|
|
46
46
|
readonly columns: 'bytes' | 'codepoints';
|
|
47
47
|
readonly name: (node: Node) => string | undefined;
|
|
48
|
+
readonly countDeclarations?: (root: Node) => number;
|
|
48
49
|
readonly rules: Readonly<Record<string, NodeRule>>;
|
|
49
50
|
readonly parens: ReadonlySet<string>;
|
|
50
51
|
readonly comments: ReadonlySet<string>;
|
|
@@ -9,6 +9,9 @@ import { firstSyntaxIssue } from './syntax-issue.js';
|
|
|
9
9
|
import { scanClones } from './tokens.js';
|
|
10
10
|
const parsers = new Map();
|
|
11
11
|
let initialized;
|
|
12
|
+
const structureMeasures = new Set([
|
|
13
|
+
'functions', 'cyclomaticComplexity', 'cognitiveComplexity', 'classes', 'structuralRules',
|
|
14
|
+
]);
|
|
12
15
|
/** The public manifest backed by one grammar. */
|
|
13
16
|
export function treeSitter(grammar) {
|
|
14
17
|
const byExtension = new Map(grammar.language.extensions.map(extension => [extension, grammar]));
|
|
@@ -63,7 +66,10 @@ function extract(path, grammar, source, tree) {
|
|
|
63
66
|
' at ' + source.location(header ? header.startIndex : 0, grammar.columns));
|
|
64
67
|
}
|
|
65
68
|
const facts = scanClones(path, tree, source, grammar);
|
|
66
|
-
|
|
69
|
+
const structure = grammar.language.measures?.some(measure => structureMeasures.has(measure)) !== false
|
|
70
|
+
? new Structure(grammar, source, facts.codeLines).measure(root) : { lines: source.count };
|
|
71
|
+
const declarations = grammar.countDeclarations?.(root);
|
|
72
|
+
return { path, ...structure, ...facts, ...(declarations === undefined ? {} : { declarations }) };
|
|
67
73
|
}
|
|
68
74
|
function firstHeader(root, grammar) {
|
|
69
75
|
let node = root.firstNamedChild;
|