@possumtech/rummy.repo 0.0.1 → 0.0.3
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 +4 -18
- package/package.json +1 -1
- package/src/rummy.repo.js +32 -42
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Symbol extraction plugin for [Rummy](https://github.com/possumtech/rummy). Turns source files into structured symbol maps using [antlrmap](https://github.com/possumtech/antlrmap) (formal ANTLR4 grammars) with [Universal Ctags](https://ctags.io/) as a fallback.
|
|
4
4
|
|
|
5
|
-
Antlrmap relies on ANTLR4's Grammar Zoo, mapping the symbol extraction process from formal EBNF grammars. More academically rigorous than tree-sitter heuristics, more accurate than ctags regex patterns, and more amenable to obscure and domain-specific languages. Don't like it? This is why symbol extraction is a plugin -- swap it out
|
|
5
|
+
Antlrmap relies on ANTLR4's Grammar Zoo, mapping the symbol extraction process from formal EBNF grammars. More academically rigorous than tree-sitter heuristics, more accurate than ctags regex patterns, and more amenable to obscure and domain-specific languages. Don't like it? This is why symbol extraction is a plugin -- swap it out.
|
|
6
6
|
|
|
7
7
|
## What It Does
|
|
8
8
|
|
|
9
|
-
When files change in a Rummy project, this plugin extracts
|
|
9
|
+
When files change in a Rummy project, this plugin reacts to `entry.changed` events, extracts symbols (functions, classes, methods, fields) from the changed files, and writes a formatted symbol tree into each file entry's `attributes.symbols`. This gives the model a compact structural overview of the codebase without reading every file in full.
|
|
10
10
|
|
|
11
11
|
## Supported Languages
|
|
12
12
|
|
|
@@ -29,25 +29,11 @@ Rummy loads plugins from `~/.rummy/plugins/` on startup. No configuration requir
|
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
|
-
The plugin registers automatically via the
|
|
32
|
+
The plugin registers automatically via the Rummy plugin contract. No manual setup needed.
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
// Rummy's plugin loader calls this automatically:
|
|
36
35
|
import RepoMapPlugin from "@possumtech/rummy.repo";
|
|
37
|
-
RepoMapPlugin
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### formatSymbols
|
|
41
|
-
|
|
42
|
-
The plugin exposes a `formatSymbols` helper for rendering symbol arrays as indented text:
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
import RepoMapPlugin from "@possumtech/rummy.repo";
|
|
46
|
-
|
|
47
|
-
const text = RepoMapPlugin.formatSymbols(symbols);
|
|
48
|
-
// class MyClass L1
|
|
49
|
-
// method doThing(a, b) L5
|
|
50
|
-
// field name L3
|
|
36
|
+
new RepoMapPlugin(core);
|
|
51
37
|
```
|
|
52
38
|
|
|
53
39
|
## Development
|
package/package.json
CHANGED
package/src/rummy.repo.js
CHANGED
|
@@ -1,59 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { extname, join } from "node:path";
|
|
1
|
+
import { extname } from "node:path";
|
|
3
2
|
import Antlrmap from "@possumtech/antlrmap";
|
|
4
3
|
import CtagsExtractor from "./CtagsExtractor.js";
|
|
5
4
|
import formatSymbols from "./formatSymbols.js";
|
|
6
5
|
|
|
7
6
|
const antlrmapSupported = new Set(Object.keys(Antlrmap.extensions));
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* RepoMapPlugin: symbol extraction via antlrmap (ANTLR4 grammars)
|
|
11
|
-
* with ctags fallback.
|
|
12
|
-
*
|
|
13
|
-
* Filter: hooks.file.symbols
|
|
14
|
-
* Input: Map (empty or partially populated)
|
|
15
|
-
* Context: { paths, projectPath }
|
|
16
|
-
* - paths: string[] of relative file paths that changed
|
|
17
|
-
* - projectPath: string, absolute project root
|
|
18
|
-
* Output: Map<string, symbol[]> where symbol = { name, kind?, params?, line?, endLine? }
|
|
19
|
-
*/
|
|
20
8
|
export default class RepoMapPlugin {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
constructor(core) {
|
|
10
|
+
core.on("entry.changed", this.#onChanged.bind(this));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async #onChanged({ rummy, paths }) {
|
|
14
|
+
const antlrmap = new Antlrmap();
|
|
15
|
+
const ctagsQueue = [];
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
for (const path of paths) {
|
|
18
|
+
const ext = extname(path);
|
|
19
|
+
if (!ext) continue;
|
|
30
20
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
if (antlrmapSupported.has(ext)) {
|
|
22
|
+
const body = await rummy.getBody(path);
|
|
23
|
+
if (!body) continue;
|
|
24
|
+
try {
|
|
25
|
+
const symbols = await antlrmap.mapSource(body, ext);
|
|
26
|
+
if (symbols?.length > 0) {
|
|
27
|
+
await rummy.setAttributes(path, {
|
|
28
|
+
symbols: formatSymbols(symbols),
|
|
29
|
+
});
|
|
30
|
+
continue;
|
|
41
31
|
}
|
|
32
|
+
} catch {
|
|
33
|
+
// Fall through to ctags
|
|
42
34
|
}
|
|
43
|
-
ctagsQueue.push(relPath);
|
|
44
35
|
}
|
|
36
|
+
ctagsQueue.push(path);
|
|
37
|
+
}
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
if (ctagsQueue.length > 0) {
|
|
40
|
+
const extractor = new CtagsExtractor(rummy.project.project_root);
|
|
41
|
+
const ctagsResults = extractor.extract(ctagsQueue);
|
|
42
|
+
for (const [path, symbols] of ctagsResults) {
|
|
43
|
+
if (symbols.length > 0) {
|
|
44
|
+
await rummy.setAttributes(path, { symbols: formatSymbols(symbols) });
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
|
-
|
|
54
|
-
return result;
|
|
55
|
-
}, 50);
|
|
47
|
+
}
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
static formatSymbols = formatSymbols;
|
|
59
49
|
}
|