{"id":20688764,"url":"https://github.com/71/vscode-tree-sitter-api","last_synced_at":"2025-04-22T15:43:04.073Z","repository":{"id":156315097,"uuid":"631294218","full_name":"71/vscode-tree-sitter-api","owner":"71","description":"Exposing Tree Sitter parsers and queries to VS Code extensions (with caching \u0026 more utilities).","archived":false,"fork":false,"pushed_at":"2023-12-02T11:48:48.000Z","size":82,"stargazers_count":16,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T13:16:10.673Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/71.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-22T15:07:19.000Z","updated_at":"2025-03-27T02:11:22.000Z","dependencies_parsed_at":"2023-12-02T12:47:42.731Z","dependency_job_id":null,"html_url":"https://github.com/71/vscode-tree-sitter-api","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fvscode-tree-sitter-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fvscode-tree-sitter-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fvscode-tree-sitter-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2Fvscode-tree-sitter-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/71","download_url":"https://codeload.github.com/71/vscode-tree-sitter-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250270093,"owners_count":21402995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T23:06:53.472Z","updated_at":"2025-04-22T15:43:04.026Z","avatar_url":"https://github.com/71.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `tree-sitter`\n\nA VS Code extension that exposes the Tree Sitter API to other extensions.\n\nIt can:\n\n1. Load the Tree Sitter WebAssembly module, as well as supported languages.\n2. Cache parsed trees.\n3. Detect languages.\n\n## WIP\n\nThis is work-in-progress intended for future use within\n[Dance](https://github.com/71/dance). A few more polishing touches are needed\nbefore it will be ready to publish on the extension store. More importantly, the\nAPI is very much subject to change.\n\n## Usage\n\nSee [`extension.test.ts`](src/test/suite/extension.test.ts) for an up-to-date\nexample.\n\n```typescript\nconst document = await vscode.workspace.openTextDocument({\n  content: `\n    pub fn foo() {\n      println!(\"bar\");\n    }\n  `,\n  language: \"rust\",\n});\n\nconst TreeSitter = await vscode.extensions.getExtension\u003cAPI\u003e(\n  \"gregoire.tree-sitter\",\n).activate()!;\n\nawait TreeSitter.withDocumentTree(document, async (tree) =\u003e {\n  await TreeSitter.withQuery(\n    document,\n    `(macro_invocation) @macro`,\n    (query) =\u003e {\n      const captures = query.captures(tree.rootNode);\n      const macroCapture = captures.find(({ name }) =\u003e name === \"macro\");\n\n      assert.ok(macroCapture);\n      assert.strictEqual(macroCapture.node.type, \"macro_invocation\");\n      assert.strictEqual(macroCapture.node.text, 'println!(\"bar\")');\n    },\n  );\n});\n```\n\nNote:\n\n1. Detection of the language of `document` was done automatically.\n2. The Tree Sitter library and Rust parser were both loaded implicitly when\n   calling `documentTree()`.\n3. No object had to be manually deleted with `.delete()`, despite Tree Sitter\n   being a WebAssembly library which requires manual deallocation.\n   - It is still possible to manage your objects manually by using\n     `documentTree()` and `query()` (instead of their `with*` counterparts), but\n     you will have to make sure to call `.delete()` after using them.\n\n## Development\n\n### Dependencies\n\n[Deno](https://deno.com) and [Emscripten](https://emscripten.org) must be\ninstalled with `deno` and `emcc` both available in the `PATH`.\n\n### Setup\n\nInstall dependencies with `yarn`:\n\n```sh\n$ yarn\n```\n\nA few files must be generated for the build process to continue. Since building\nthese files can be slow and requires internet access, this must be done\nmanually:\n\n```sh\n$ ./tools.ts --build-wasm --update-text-objects\n```\n\n### Building\n\nRun `yarn run compile` to build the extension, and `yarn vsce package` to\npackage it for publishing in the store.\n\n### Testing\n\nIn VS Code, start the `watch:test` task, then launch \"Extension Tests\" in the\n\"Run and Debug\" menu.\n\n## Scope inspection\n\nThis extension provides a command named \"Inspect Scopes\" which displays the\ncurrent scope in the status bar; hovering the scope will display all its\nancestors in a tooltip. This may help write commands that operate on the\nreturned tree or that perform queries.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F71%2Fvscode-tree-sitter-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F71%2Fvscode-tree-sitter-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F71%2Fvscode-tree-sitter-api/lists"}