@cgasgarth/opencode-for-rust 1.0.6 → 1.0.10-next.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.
package/dist/index.js CHANGED
@@ -12331,23 +12331,48 @@ function tool(input) {
12331
12331
  }
12332
12332
  tool.schema = exports_external;
12333
12333
  // src/lib/extractor.ts
12334
- import Parser from "tree-sitter";
12335
- import Rust from "tree-sitter-rust";
12334
+ import { Parser, Language, Query } from "web-tree-sitter";
12335
+ import * as path from "path";
12336
12336
  import * as fs from "fs/promises";
12337
+ var __dirname = "/home/runner/work/opencode-for-rust/opencode-for-rust/src/lib";
12338
+ var WASM_PATH = path.resolve(__dirname, "tree-sitter-rust.wasm");
12337
12339
 
12338
12340
  class RustTypeExtractor {
12339
12341
  config;
12340
- parser;
12342
+ parser = null;
12343
+ language = null;
12341
12344
  constructor(config2) {
12342
12345
  this.config = config2;
12346
+ }
12347
+ async init() {
12348
+ if (this.parser)
12349
+ return;
12350
+ await Parser.init();
12343
12351
  this.parser = new Parser;
12344
- this.parser.setLanguage(Rust);
12352
+ try {
12353
+ this.language = await Language.load(WASM_PATH);
12354
+ this.parser.setLanguage(this.language);
12355
+ } catch (e) {
12356
+ if (this.config.debug) {
12357
+ console.error("Failed to load WASM language:", e);
12358
+ }
12359
+ throw e;
12360
+ }
12345
12361
  }
12346
12362
  async extract(filePath, content) {
12363
+ if (!this.parser) {
12364
+ await this.init();
12365
+ }
12366
+ if (!this.parser || !this.language) {
12367
+ return [];
12368
+ }
12347
12369
  const _fileContent = content || await fs.readFile(filePath, "utf-8");
12348
12370
  const tree = this.parser.parse(_fileContent);
12371
+ if (!tree) {
12372
+ return [];
12373
+ }
12349
12374
  const types = [];
12350
- const query = new Parser.Query(Rust, `
12375
+ const query = new Query(this.language, `
12351
12376
  (struct_item
12352
12377
  name: (type_identifier) @name
12353
12378
  ) @struct
@@ -12451,7 +12476,7 @@ class RustTypeExtractor {
12451
12476
 
12452
12477
  // src/lib/lookup.ts
12453
12478
  var {Glob } = globalThis.Bun;
12454
- import * as path from "path";
12479
+ import * as path2 from "path";
12455
12480
  class RustTypeLookup {
12456
12481
  directory;
12457
12482
  config;
@@ -12477,7 +12502,7 @@ class RustTypeLookup {
12477
12502
  for await (const filePath of glob.scan(this.directory)) {
12478
12503
  if (this.shouldExclude(filePath))
12479
12504
  continue;
12480
- const absolutePath = path.join(this.directory, filePath);
12505
+ const absolutePath = path2.join(this.directory, filePath);
12481
12506
  try {
12482
12507
  const types = await this.extractor.extract(absolutePath);
12483
12508
  for (const type of types) {
@@ -2,7 +2,9 @@ import { ExtractedType, TypeInjectionConfig } from './types';
2
2
  export declare class RustTypeExtractor {
3
3
  private config;
4
4
  private parser;
5
+ private language;
5
6
  constructor(config: TypeInjectionConfig);
7
+ init(): Promise<void>;
6
8
  extract(filePath: string, content?: string): Promise<ExtractedType[]>;
7
9
  private mapNodeToKind;
8
10
  private isExported;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cgasgarth/opencode-for-rust",
3
- "version": "1.0.6",
3
+ "version": "1.0.10-next.1",
4
4
  "description": "OpenCode plugin for Rust",
5
5
  "author": {
6
6
  "name": "Sisyphus",
@@ -27,21 +27,22 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@opencode-ai/plugin": "1.0.85",
30
- "tree-sitter": "^0.22.1",
31
- "tree-sitter-rust": "^0.24.0"
30
+ "web-tree-sitter": "^0.26.3"
32
31
  },
33
32
  "devDependencies": {
34
33
  "@eslint/js": "^9.39.1",
35
- "@types/node": "^20.11.5",
34
+ "@types/bun": "latest",
35
+ "@types/node": "^20.12.7",
36
36
  "@typescript-eslint/eslint-plugin": "8.47.0",
37
37
  "@typescript-eslint/parser": "8.47.0",
38
38
  "bun-types": "latest",
39
39
  "eslint": "^9.39.1",
40
40
  "eslint-config-prettier": "10.1.8",
41
- "eslint-plugin-prettier": "^5.1.3",
41
+ "eslint-plugin-prettier": "^5.2.1",
42
42
  "husky": "^9.1.7",
43
43
  "lint-staged": "^16.2.7",
44
- "prettier": "^3.2.4",
44
+ "prettier": "^3.3.3",
45
+ "tree-sitter-rust": "^0.24.0",
45
46
  "typescript": "^5.9.3",
46
47
  "typescript-eslint": "^8.47.0",
47
48
  "vitest": "^3.2.4"
@@ -49,7 +50,7 @@
49
50
  "scripts": {
50
51
  "test": "bun test tests/",
51
52
  "typecheck": "tsc --noEmit",
52
- "build": "bun build ./src/index.ts --outdir dist --target bun --external tree-sitter --external tree-sitter-rust && tsc --project tsconfig.build.json",
53
+ "build": "bun build ./src/index.ts --outdir dist --target bun --external web-tree-sitter && cp node_modules/tree-sitter-rust/tree-sitter-rust.wasm dist/ && tsc --project tsconfig.build.json",
53
54
  "lint": "eslint src --max-warnings 0",
54
55
  "format": "prettier --check .",
55
56
  "prepare": "husky"