Skip to content

Dev - #14

Merged
BleckWolf25 merged 6 commits into
mainfrom
dev
Jul 9, 2026
Merged

Dev#14
BleckWolf25 merged 6 commits into
mainfrom
dev

Conversation

@BleckWolf25

@BleckWolf25 BleckWolf25 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary by Sourcery

Bundle the extension with esbuild, ship runtime WASM dependencies via a dedicated deps/ directory, and adjust activation/CI/release flows to improve reliability of initialization and packaging.

New Features:

  • Add a dedicated deps/ directory and copy-deps script to ship runtime dependencies (tree-sitter languages, web-tree-sitter, sql.js, jspdf) inside the VSIX.
  • Introduce an esbuild-based build pipeline that outputs a CommonJS extension entrypoint used as the new main file.
  • Ensure commands and providers are registered synchronously while extension initialization runs in the background via an initialization helper.

Enhancements:

  • Update the extension version and dev dependency versions, including Svelte, Vite, ESLint, chart.js, and related tooling.
  • Change tree-sitter runtime initialization to lazy-load the web-tree-sitter CJS module and provide clearer error messaging when the dependency is missing.
  • Adjust WASM helper paths to read artifacts from the deps/ directory instead of node_modules.
  • Guard workspace scanning against missing files to avoid errors when documents no longer exist.
  • Allow web-tree-sitter builds in the pnpm workspace configuration.
  • Refresh CI and release workflows to use newer action versions and align with the new build/package process.

Build:

  • Replace the TypeScript-only compile step with an esbuild-based bundling step that keeps runtime dependencies external and targets Node 24.
  • Add a vsce packaging script and integrate dependency copying into the vscode:prepublish script to prepare artifacts for Marketplace publishing.

CI:

  • Update CI and release GitHub Actions workflows to newer versions of checkout, setup-node, pnpm, and gh-release actions and keep them compatible with pnpm and the new build pipeline.

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors extension activation to lazy-initialize heavy runtime components, introduces an esbuild-based bundling and deps-copy pipeline to make pnpm-based runtime dependencies work with vsce packaging, updates CI/release workflows and devDependencies, and adjusts tree-sitter integration to load from packaged deps instead of node_modules with additional safety checks.

Sequence diagram for lazy initialization during extension activation and command execution

sequenceDiagram
    actor VSCode
    participant Extension
    participant EventProcessor
    participant TreeSitterManager
    participant DatabaseManager

    VSCode->>Extension: activate(context)
    Extension->>Extension: vscode.commands.registerCommand(codepulse.openDashboard)
    Extension->>Extension: vscode.commands.registerCommand(codepulse.exportJson)
    Extension->>Extension: vscode.commands.registerCommand(codepulse.exportCsv)
    Extension->>Extension: vscode.commands.registerCommand(codepulse.purgeLogs)
    Extension->>Extension: vscode.languages.registerCodeLensProvider()
    Extension->>Extension: vscode.languages.registerHoverProvider()
    Extension->>EventProcessor: new EventProcessor()
    Extension->>EventProcessor: context.subscriptions.push(dispose)
    Extension->>Extension: ensureInitialized(context)
    Extension->>TreeSitterManager: TreeSitterManager.getInstance()
    Extension->>TreeSitterManager: initialize(context)
    Extension->>DatabaseManager: DatabaseManager.getInstance()
    Extension->>DatabaseManager: initialize(storageDir)
    Extension->>EventProcessor: eventProcessor.activate()
    Extension->>Extension: showDashboard(context)

    VSCode->>Extension: vscode.commands.executeCommand(codepulse.openDashboard)
    Extension->>Extension: ensureInitialized(context)
    Extension->>TreeSitterManager: initialize(context) [if not initialized]
    Extension->>DatabaseManager: initialize(storageDir) [if not initialized]
    Extension->>Extension: showDashboard(context)

    VSCode->>Extension: deactivate()
    Extension->>EventProcessor: eventProcessor.deactivate()
Loading

File-Level Changes

Change Details Files
Refactor extension activation to lazy-initialize runtime (TreeSitter, database, event processor) while registering commands/providers synchronously.
  • Introduce ensureInitialized helper with shared initPromise to perform storage directory resolution, TreeSitter initialization, and database setup once.
  • Change activate to be synchronous, registering commands and language providers immediately to avoid missing commands on startup.
  • Wrap dashboard and export commands in async handlers that await initialization and show an error message if dashboard initialization fails.
  • Start EventProcessor only after initialization completes and add a dispose hook for clean deactivation while logging initialization failures.
src/extension.ts
Adjust TreeSitterManager to lazy-load web-tree-sitter from a CJS entrypoint and use deps/ instead of node_modules, with user-facing error handling.
  • Replace direct ESM imports of web-tree-sitter with a declared require and a cached treeSitterModule typed as TreeSitterNamespace.
  • On initialization, require 'web-tree-sitter/web-tree-sitter.cjs', show a VS Code error message if the dependency is missing, and rethrow the error.
  • Use treeSitterModule.Parser.init and treeSitterModule.Language.load when setting up parsers.
  • Change parser map type to TreeSitterNamespace.Parser to align with the new import pattern.
src/parser/parser.ts
Update WASM helper and event processor to work with runtime deps shipped in deps/ and improve resilience when scanning workspace files.
  • Change copyWasmBinaries to copy artifacts from context.extensionUri/deps instead of node_modules.
  • Change getTreeSitterWasmPath to point to deps/web-tree-sitter/web-tree-sitter.wasm.
  • Add an fs.existsSync check before opening each file during workspace scans to skip missing/removed files quietly.
src/parser/wasmHelper.ts
src/parser/eventProcessor.ts
Introduce esbuild-based bundling and a deps-copy script to make pnpm symlinked runtime dependencies compatible with vsce packaging.
  • Add esbuild.config.mjs that bundles src/extension.ts to out/extension.cjs, marks vscode external, and uses a depsRewrite plugin to rewrite runtime dependency imports to ../deps/ while treating them as external.
  • Add scripts/copy-deps.mjs to copy runtime dependency directories from node_modules into a deps/ directory, dereferencing pnpm symlinks so vsce includes real files.
  • Update npm scripts to use esbuild for compile/watch, add a package script using vsce, and extend vscode:prepublish to run compile, pnpm install --shamefully-hoist, and copy-deps.
esbuild.config.mjs
scripts/copy-deps.mjs
package.json
Update CI and release workflows and tooling versions to align with new build pipeline and latest actions.
  • Bump extension version from 1.0.0 to 3.0.1 and change main entry from out/extension.js to out/extension.cjs.
  • Update devDependencies versions (svelte, chart.js, eslint, typescript-eslint, vite, @sveltejs/vite-plugin-svelte, esbuild, etc.).
  • Wrap pnpm overrides inside a pnpm field and move dependencies block out accordingly.
  • Enable web-tree-sitter builds in pnpm-workspace.yaml.
  • Update GitHub actions for CI and release to newer major versions (checkout@v7, setup-node@v6, pnpm/action-setup@v6, softprops/action-gh-release@v3) and keep the build/lint/package steps the same.
  • Regenerate .gitignore, .vscodeignore, pnpm-lock.yaml to reflect new build/deps setup.
package.json
.github/workflows/ci.yml
.github/workflows/release.yml
pnpm-workspace.yaml
.gitignore
.vscodeignore
pnpm-lock.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Comment thread .github/workflows/ci.yml Fixed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The change to read WASM binaries from deps/ (in wasmHelper.ts) means dev runs without copy-deps.mjs will fail; consider falling back to node_modules when deps/ is missing so the extension can run directly from the workspace.
  • In the new command implementations (exportJson, exportCsv, purgeLogs), ensureInitialized is awaited but errors are not surfaced to the user; mirroring the try/catch and showErrorMessage behavior used in openDashboard would make failures more user-friendly and avoid silent command failures.
  • The TreeSitter initialization error message constructed in parser.ts is helpful but currently throws the original error after showing a generic message; consider including the original error details in the user-facing message to aid debugging when runtime dependencies are missing or mispackaged.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The change to read WASM binaries from `deps/` (in `wasmHelper.ts`) means dev runs without `copy-deps.mjs` will fail; consider falling back to `node_modules` when `deps/` is missing so the extension can run directly from the workspace.
- In the new command implementations (`exportJson`, `exportCsv`, `purgeLogs`), `ensureInitialized` is awaited but errors are not surfaced to the user; mirroring the try/catch and `showErrorMessage` behavior used in `openDashboard` would make failures more user-friendly and avoid silent command failures.
- The TreeSitter initialization error message constructed in `parser.ts` is helpful but currently throws the original error after showing a generic message; consider including the original error details in the user-facing message to aid debugging when runtime dependencies are missing or mispackaged.

## Individual Comments

### Comment 1
<location path="src/extension.ts" line_range="228-221" />
<code_context>
+            }
         }),
-        vscode.commands.registerCommand('codepulse.exportJson', () => {
+        vscode.commands.registerCommand('codepulse.exportJson', async () => {
+            await ensureInitialized(context);
             void exportJson();
         }),
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Command handlers using `ensureInitialized` lack error handling, which can surface unhandled rejections to users.

For `codepulse.exportJson`, `codepulse.exportCsv`, and `codepulse.purgeLogs`, `await ensureInitialized(context)` is not wrapped in error handling. If initialization fails (e.g., missing dependencies or DB issues), the command will reject without clear user feedback and may surface opaque errors in the extension host. Please align these handlers with `openDashboard` by using try/catch and `showErrorMessage` to handle initialization failures consistently and avoid unhandled promise rejections.

Suggested implementation:

```typescript
        vscode.commands.registerCommand('codepulse.exportJson', async () => {
            try {
                await ensureInitialized(context);
                void exportJson();
            } catch (err) {
                const msg = err instanceof Error ? err.message : String(err);
                void vscode.window.showErrorMessage(`[CodePulse] Failed to export JSON: ${msg}`);
            }
        }),

```

```typescript
        vscode.commands.registerCommand('codepulse.exportCsv', async () => {
            try {
                await ensureInitialized(context);
                void exportCsv();
            } catch (err) {
                const msg = err instanceof Error ? err.message : String(err);
                void vscode.window.showErrorMessage(`[CodePulse] Failed to export CSV: ${msg}`);
            }
        }),

```

To fully align with the comment, you should also update the `codepulse.purgeLogs` command handler (wherever it is defined in `src/extension.ts`) to follow the same pattern:

- Wrap `await ensureInitialized(context)` and the purge operation in a `try` block.
- On error, compute `msg` using the same `err instanceof Error ? err.message : String(err)` pattern.
- Use `vscode.window.showErrorMessage` with a message like `[CodePulse] Failed to purge logs: ${msg}`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/extension.ts
showDashboard(context);
vscode.commands.registerCommand('codepulse.openDashboard', async () => {
try {
await ensureInitialized(context);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Command handlers using ensureInitialized lack error handling, which can surface unhandled rejections to users.

For codepulse.exportJson, codepulse.exportCsv, and codepulse.purgeLogs, await ensureInitialized(context) is not wrapped in error handling. If initialization fails (e.g., missing dependencies or DB issues), the command will reject without clear user feedback and may surface opaque errors in the extension host. Please align these handlers with openDashboard by using try/catch and showErrorMessage to handle initialization failures consistently and avoid unhandled promise rejections.

Suggested implementation:

        vscode.commands.registerCommand('codepulse.exportJson', async () => {
            try {
                await ensureInitialized(context);
                void exportJson();
            } catch (err) {
                const msg = err instanceof Error ? err.message : String(err);
                void vscode.window.showErrorMessage(`[CodePulse] Failed to export JSON: ${msg}`);
            }
        }),
        vscode.commands.registerCommand('codepulse.exportCsv', async () => {
            try {
                await ensureInitialized(context);
                void exportCsv();
            } catch (err) {
                const msg = err instanceof Error ? err.message : String(err);
                void vscode.window.showErrorMessage(`[CodePulse] Failed to export CSV: ${msg}`);
            }
        }),

To fully align with the comment, you should also update the codepulse.purgeLogs command handler (wherever it is defined in src/extension.ts) to follow the same pattern:

  • Wrap await ensureInitialized(context) and the purge operation in a try block.
  • On error, compute msg using the same err instanceof Error ? err.message : String(err) pattern.
  • Use vscode.window.showErrorMessage with a message like [CodePulse] Failed to purge logs: ${msg}.

@BleckWolf25
BleckWolf25 merged commit 41634e7 into main Jul 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants