Skip to content

Use @cursorless/tree-sitter-wasms dependency #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ vsc-extension-quickstart.md
**/tslint.json
**/*.map
**/*.ts
examples/**
examples/**
.github/**
copy-assets.sh
.nvmrc
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to the "vscode-parse-tree" extension will be documented in this file.

## 0.33.0 (22 Apr 2025)

### Enhancements

- Stop building wasm and instead use dependency `@cursorless/tree-sitter-wasms` [#103](https://github.com/cursorless-dev/vscode-parse-tree/pull/103) ([AndreasArvidsson](https://github.com/AndreasArvidsson))

## 0.32.0 (25 Oct 2024)

### Enhancements
Expand Down
48 changes: 0 additions & 48 deletions Makefile

This file was deleted.

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ registerLanguage(languageId, wasmPath);

It's straightforward to add any [language with a tree-sitter grammar](https://tree-sitter.github.io/tree-sitter/).

1. Add a dependency on the npm package for that language: `yarn add -D tree-sitter-yourlang`.
1. Add a dependency on the npm package for that language in [tree-sitter-wasms](https://github.com/cursorless-dev/tree-sitter-wasms)
2. Add a language to the dictionary at the top of `./src/extension.ts`
3. Add a reference to `onLanguage:yourlang` to the [activationEvents section of package.json](package.json). `yourlang` must be a [VSCode language identifier](https://code.visualstudio.com/docs/languages/identifiers).
4. Add your language to the top of the [Makefile](Makefile)
5. Run `yarn compile`, then hit `F5` in VSCode, with this project open, to test your changes.
6. Submit a PR!
4. Run `yarn compile`, then hit `F5` in VSCode, with this project open, to test your changes.
5. Submit a PR!

### Developing on WSL2

Expand Down
1 change: 1 addition & 0 deletions copy-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cp -r node_modules/@cursorless/tree-sitter-wasms/out parsers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tempted to just include node_modules/@cursorless/tree-sitter-wasms/out directory in the extension bundle and read them in place to avoid this step but I don't feel strongly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah true, but doesn't matter really and we are gonna scrap this ext anyhow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a crack at this but it apparently isn't recommended and you do get an error

The following include patterns in the "files" property in package.json do not match any files packaged in the extension:
  - node_modules/@cursorless/tree-sitter-wasms/out
Remove any include pattern which is not needed.

I think copying assets is fine.

49 changes: 5 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "parse-tree",
"displayName": "Parse tree",
"description": "Access document syntax using tree-sitter",
"version": "0.34.0",
"version": "0.35.0",
"publisher": "pokey",
"repository": {
"type": "git",
Expand Down Expand Up @@ -75,7 +75,8 @@
"contributes": {},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./ && make parsers",
"compile": "tsc -p ./ && npm run copy-assets",
"copy-assets": "sh copy-assets.sh",
"watch": "tsc -watch -p ./",
"test": "npm run compile && node ./out/test",
"benchmark": "npm run compile && node ./out/benchmark",
Expand All @@ -85,59 +86,19 @@
"publish": "vsce publish patch"
},
"devDependencies": {
"@cursorless/tree-sitter-wasms": "0.2.5",
"@electron/rebuild": "^3.3.0",
"@elm-tooling/tree-sitter-elm": "github:elm-tooling/tree-sitter-elm#0aecfbf69f0c9bcdfada0f6f2c5398235c23949f",
"@types/mocha": "^2.2.42",
"@types/node": "^8.10.25",
"@types/vscode": "~1.58.0",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@vscode/test-electron": "^2.1.3",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"tree-sitter-agda": "github:pokey/tree-sitter-agda#e5fba6cabe8c7fc7993ced2b86704f3841215284",
"tree-sitter-bash": "github:tree-sitter/tree-sitter-bash#2fbd860f802802ca76a6661ce025b3a3bca2d3ed",
"tree-sitter-c": "github:tree-sitter/tree-sitter-c#deca017a554045b4c203e7ddff39ae64ff05e071",
"tree-sitter-c-sharp": "^0.19.0",
"tree-sitter-cli": "^0.22.6",
"tree-sitter-clojure": "github:sogaiu/tree-sitter-clojure#f4236d4da8aa92bc105d9c118746474c608e6af7",
"tree-sitter-cpp": "github:tree-sitter/tree-sitter-cpp#9d412ba7e597fe158f209da33e60f31b1f0df967",
"tree-sitter-css": "^0.19.0",
"tree-sitter-dart": "github:UserNobody14/tree-sitter-dart#9ac03bb2154316624fb4c41fe0f372a5f1597b43",
"tree-sitter-elixir": "github:elixir-lang/tree-sitter-elixir#b20eaa75565243c50be5e35e253d8beb58f45d56",
"tree-sitter-gleam": "github:gleam-lang/tree-sitter-gleam#2012f294baacf30e7a62414754021284377366c6",
"tree-sitter-go": "github:tree-sitter/tree-sitter-go#bbaa67a180cfe0c943e50c55130918be8efb20bd",
"tree-sitter-haskell": "github:tree-sitter/tree-sitter-haskell#a50070d5bb5bd5c1281740a6102ecf1f4b0c4f19",
"tree-sitter-hcl": "github:MichaHoffmann/tree-sitter-hcl#e135399cb31b95fac0760b094556d1d5ce84acf0",
"tree-sitter-html": "github:tree-sitter/tree-sitter-html#e4d834eb4918df01dcad5c27d1b15d56e3bd94cd",
"tree-sitter-java": "github:tree-sitter/tree-sitter-java#ac14b4b1884102839455d32543ab6d53ae089ab7",
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#391a8fcc48a11f63bf18ec9885f6f069e760949a",
"tree-sitter-json": "github:tree-sitter/tree-sitter-json#94f5c527b2965465956c2000ed6134dd24daf2a7",
"tree-sitter-julia": "github:tree-sitter/tree-sitter-julia#e2f449e2bcc95f1d07ceb62d67f986005f73a6be",
"tree-sitter-kotlin": "github:fwcd/tree-sitter-kotlin#76f53c48d29e8588934fb55b0240d7bdfe00bfe5",
"tree-sitter-latex": "github:latex-lsp/tree-sitter-latex#1666e9780de42a31b1376d32fbe8332e8dd5850f",
"tree-sitter-lua": "github:MunifTanjim/tree-sitter-lua#9668709211b2e683f27f414454a8b51bf0a6bda1",
"tree-sitter-markdown": "github:tree-sitter-grammars/tree-sitter-markdown#7fe453beacecf02c86f7736439f238f5bb8b5c9b",
"tree-sitter-nix": "github:nix-community/tree-sitter-nix#66e3e9ce9180ae08fc57372061006ef83f0abde7",
"tree-sitter-perl": "github:ganezdragon/tree-sitter-perl#3d3a95ee6645d7bcd993e77b252ffd33fd297c8e",
"tree-sitter-php": "github:tree-sitter/tree-sitter-php#4f124bc6075e1c3333e80190c1c170933ed72c95",
"tree-sitter-python": "github:tree-sitter/tree-sitter-python#71778c2a472ed00a64abf4219544edbf8e4b86d7",
"tree-sitter-query": "github:nvim-treesitter/tree-sitter-query#5217c6805c09f8fc00ed13d17d5fcb791437aee6",
"tree-sitter-ruby": "github:tree-sitter/tree-sitter-ruby#dc2d7d6b50f9975bc3c35bbec0ba11b2617b736b",
"tree-sitter-rust": "github:tree-sitter/tree-sitter-rust#36ae187ed6dd3803a8a89dbb54f3124c8ee74662",
"tree-sitter-scala": "github:tree-sitter/tree-sitter-scala#master",
"tree-sitter-scss": "github:serenadeai/tree-sitter-scss#c478c6868648eff49eb04a4df90d703dc45b312a",
"tree-sitter-sparql": "^0.1.0",
"tree-sitter-swift": "github:alex-pinkus/tree-sitter-swift#7e4ccc97a25315022a70b730085deccd5680a39b",
"tree-sitter-talon": "github:pokey/tree-sitter-talon#f69923ea2490530babe105f0a36434e4a23e127e",
"tree-sitter-typescript": "github:tree-sitter/tree-sitter-typescript#4ad3010c91d700026d036b5230e2d99ba94ae8a4",
"tree-sitter-xml": "github:ObserverOfTime/tree-sitter-xml#648183d86f6f8ffb240ea11b4c6873f6f45d8b67",
"tree-sitter-yaml": "github:tree-sitter-grammars/tree-sitter-yaml#7b03feefd36b5f155465ca736c6304aca983b267",
"eslint": "^8.53.0",
"typescript": "^4.5.5"
},
"dependencies": {
"jsonc-parser": "^2.1.0",
"tar": ">=4.4.2",
"web-tree-sitter": "^0.24.6"
}
}
7 changes: 6 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import * as Parser from "web-tree-sitter";
import * as path from "path";
import * as fs from "fs";
import { LanguageStillLoadingError, UnsupportedLanguageError } from "./errors";

interface Language {
Expand All @@ -16,7 +17,7 @@ const languages: {
c: { module: "tree-sitter-c" },
clojure: { module: "tree-sitter-clojure" },
cpp: { module: "tree-sitter-cpp" },
csharp: { module: "tree-sitter-c-sharp" },
csharp: { module: "tree-sitter-c_sharp" },
css: { module: "tree-sitter-css" },
dart: { module: "tree-sitter-dart" },
elm: { module: "tree-sitter-elm" },
Expand Down Expand Up @@ -91,6 +92,10 @@ export async function activate(context: vscode.ExtensionContext) {
);
}

if (!fs.existsSync(absolute)) {
throw Error(`Parser for ${languageId} not found at ${absolute}`);
}

const wasm = path.relative(process.cwd(), absolute);
await initParser;
const lang = await Parser.Language.load(wasm);
Expand Down
Loading