@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 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 in 20 lines.
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 their symbols (functions, classes, methods, fields) and returns them as structured data. Rummy stores the formatted symbol tree in file entry attributes, giving the model a compact map of the codebase without reading every file.
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 standard Rummy plugin contract. No manual setup needed.
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.register(hooks);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@possumtech/rummy.repo",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Rummy plugin for symbol extraction via antlrmap and ctags",
5
5
  "keywords": [
6
6
  "rummy",
package/src/rummy.repo.js CHANGED
@@ -1,59 +1,49 @@
1
- import { readFileSync } from "node:fs";
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
- static register(hooks) {
22
- hooks.file.symbols.addFilter(async (symbolMap, { paths, projectPath }) => {
23
- const result = symbolMap instanceof Map ? symbolMap : new Map();
24
- const antlrmap = new Antlrmap();
25
- const ctagsQueue = [];
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
- for (const relPath of paths) {
28
- if (result.has(relPath)) continue;
29
- const ext = extname(relPath);
17
+ for (const path of paths) {
18
+ const ext = extname(path);
19
+ if (!ext) continue;
30
20
 
31
- if (antlrmapSupported.has(ext)) {
32
- try {
33
- const content = readFileSync(join(projectPath, relPath), "utf8");
34
- const symbols = await antlrmap.mapSource(content, ext);
35
- if (symbols?.length > 0) {
36
- result.set(relPath, symbols);
37
- continue;
38
- }
39
- } catch {
40
- // Fall through to ctags
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
- if (ctagsQueue.length > 0) {
47
- const extractor = new CtagsExtractor(projectPath);
48
- const ctagsResults = extractor.extract(ctagsQueue);
49
- for (const [path, symbols] of ctagsResults) {
50
- if (symbols.length > 0) result.set(path, symbols);
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
  }