# Add a Tree View to a VS Code Extension

Yes. An agent reads your extension's manifest and activation code, adds a tree view with a TreeDataProvider, commands and refresh, tests both hosts and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-tree-view/vscode-extension/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads what the extension contributes before adding a view. In an extension like aaron-bond/better-comments, `package.json` declares `engines.vscode` at `^1.101.0`, activates on `onStartupFinished`, ships both a Node entry (`main` at `./out/extension`) and a web entry (`browser` at `./out/web/extension.js`), and under `contributes` has only `configuration`: the three `better-comments.*` settings with the five default tags (`!`, `?`, `//`, `todo`, `*`) and their colours. There is no `views`, `viewsContainers`, `commands` or `menus` section. `src/extension.ts` wires one `Parser` to the active editor through `onDidChangeActiveTextEditor` and `onDidChangeTextDocument` with a 100 ms debounce, and `src/core/` is the pure part: `findTags(text, state, tags)` returns `TagMatch` records with a `tagIndex`, `start` and `end` offset, and `src/core/index.ts` says in its header that nothing in `src/core` may import `vscode`, a rule that `test/unit/boundary.test.ts` enforces. The agent keeps to that split.

The view it adds lists every tagged comment in the current document, grouped by tag, so a reader can jump to each `todo` or `!` without scrolling. It writes a `CommentTreeProvider` in `src/` that implements `vscode.TreeDataProvider` for two node kinds, a tag group and a comment line, with `getChildren` reading the matches the parser already found and `getTreeItem` building each item with the comment's text as `label`, its line number as `description`, the tag's configured colour mapped to a `ThemeIcon`, and a `command` that reveals the range in the editor. The provider owns an `onDidChangeTreeData` emitter and `Parser.FindComments` gains a return of the matches it found, so the existing debounce drives the view with no second scan of the document. In `package.json` the agent adds a `views` entry under the built-in `explorer` container, so the view appears without a new activity-bar icon, a `commands` entry for a refresh command and a go-to command, a `menus.view/title` binding that puts refresh in the view's header, and a `viewsWelcome` message for a file whose language the extension does not support, which the parser already knows through `supportedLanguage`.

Because the extension also runs as a web extension, the tree code is written against the `vscode` API only, with no `fs` or `path`, and the agent checks that `build/web-extension.webpack.config.js`, which targets `webworker` and marks `vscode` external, still bundles it with `npm run compile-web`. The grouping and ordering logic lives in `src/core/` as a pure function over `TagMatch` records, so it gets a unit test under `test/unit/` run by `npm run test:unit` through mocha, while the wiring gets a host test beside the existing `test/host/integration/wiring.test.ts` that opens a fixture file, reads the view's children through the provider and asserts the groups match the tags found.

To check it, the agent runs the project's own CI steps in its sandbox: `npm ci --ignore-scripts`, `npm run lint`, `npm run compile`, `npm run compile-web`, then `xvfb-run -a npm run test:host`, which `.github/workflows/ci.yml` runs on VS Code 1.101.0 and stable. It packages with `npx vsce package` as the workflow does, installs the `.vsix` into a VS Code in its sandbox, opens a TypeScript file with a few tagged comments and takes a screenshot of the Explorer with the new view expanded, then edits a comment and screenshots the view updating. Those two images go into the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a tree view to this VS Code extension that lists the tagged comments in the active document, grouped by tag. Read package.json for the engines version, activation events, both entry points and every contributes section, then the activation code and the module that finds comments, and respect any boundary the code enforces between pure logic and the vscode API. Implement a TreeDataProvider with a tag group node and a comment node, a command that reveals the comment's range, a refresh command in the view's title, and a welcome message for unsupported languages, and register the view under the Explorer container so no new activity bar icon is needed. Drive the view from the extension's existing update path rather than scanning the document twice. Put the grouping logic where the pure code lives with a unit test, add a host test for the wiring, run the project's lint, compile, web bundle and test commands, package the extension, install it in VS Code, take screenshots of the view before and after editing a comment, and open a pull request with the commands, their output and the screenshots.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request adds the provider and its registration, the `views`, `commands`, `menus` and `viewsWelcome` entries in `package.json`, the pure grouping function with its unit test, and the host test. Its description shows the lint, compile and web-bundle output, the test summary from the host run, the `vsce package` result, and the two screenshots of the view in the Explorer, so a reviewer can see what a user will see without installing the branch.

A reviewer checks the node labels and the icon mapping, which are taste, and that the boundary test still passes with the new core function. After merging, the next release shows the view in the Explorer for every file in a supported language, and a comment edit updates it on the same debounce that updates the decorations.

## Run it on every Linear issue labelled extension

A team that tracks extension work in Linear adds an automation to the Project with a `linear` trigger on `linear.issue.labeled`, the label `extension`, with the automation set to read only. Each labelled issue starts a read-only run that reads the manifest and the activation code and posts, as a comment on the issue, which container it would register the view in, which existing update path would feed it and where the tests would go. Only a change made by a member of the Rush org fires the trigger, and that comment is the whole result, because an automation's runs push nothing.

When the plan is agreed, a handler on the team's own server sends this body with the issue's URL added to `resources`, which puts the issue text in front of the agent through the team's Linear connection, and a `request_id` that is a UUID v5 of the issue id, so a second delivery of the same event returns the run already started instead of opening a second pull request.

## Why run it on Rush?

A tree view touches the manifest, the activation path, the bundler and the test harness at once, and the only honest check is to run the extension: compile both entries, run the host tests under a display, package it, install it and look. The agent does all of that in its own sandbox, installing `xvfb` and letting `@vscode/test-electron` download the two VS Code builds the workflow tests on, with every command and its output kept in the run's record, so the pull request carries screenshots and test output rather than a description of them.

It also fits the extension's own rules rather than a tutorial's: the pure core that may not import `vscode`, the web bundle that rules out Node modules, the debounce that already knows when the document changed. Several extensions with several structures get several pull requests, each with the view wired to that extension's own data.

## Frequently asked questions

### Will it add an icon to the activity bar?

Not unless you ask. The view is registered under the built-in Explorer container, which is where a document-scoped list belongs, so it appears as a collapsible section there. A `viewsContainers` entry with its own icon is a one-line change if you prefer a dedicated bar.

### Does it work in the web version of VS Code?

Yes. The provider uses only the `vscode` API and the extension's existing core, with no Node modules, and the agent runs the web bundle step to confirm it packs. The extension already ships a web entry, so the view ships with it.

### Will the view slow down editing?

No. It reads the matches the parser already finds on the existing debounce and fires its change event then, so there is no second scan of the document. The grouping is a pure function over the matches and runs in the same tick.

### How is it tested?

The grouping function has a unit test in the pure test suite, and the wiring has a host test beside the existing integration tests that opens a fixture file and reads the provider's children. Both run through the project's own test commands, which the agent runs under `xvfb` as CI does.

## More VS Code extension jobs

- [Add a Getting Started Walkthrough to a VS Code Extension](https://getrush.ai/run/add-walkthrough/vscode-extension/)
- [Make a VS Code Extension Run in the Browser as a Web Extension](https://getrush.ai/run/add-web-extension-support/vscode-extension/)
- [Turn Sentry Errors Into Fix Pull Requests for a VS Code Extension](https://getrush.ai/run/fix-sentry-errors/vscode-extension/)

## More jobs like this: Turn a Linear label into a PR

- [Add Two-Factor Authentication to an Express and Mongoose API](https://getrush.ai/run/add-two-factor-auth/mongoose/)
- [Add Type Hints to a Flask Codebase](https://getrush.ai/run/add-type-hints/flask/)
- [Add Type Hints to a Wagtail Codebase](https://getrush.ai/run/add-type-hints/wagtail/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
