Skip to content

feat(vscode): add workspaceRoot config option to enable use in a VSCode workspace that does not have package.json at the workspace root#1667

Open
anmilleriii wants to merge 2 commits into
webpro-nl:mainfrom
anmilleriii:al/workspace-root
Open

feat(vscode): add workspaceRoot config option to enable use in a VSCode workspace that does not have package.json at the workspace root#1667
anmilleriii wants to merge 2 commits into
webpro-nl:mainfrom
anmilleriii:al/workspace-root

Conversation

@anmilleriii
Copy link
Copy Markdown

@anmilleriii anmilleriii commented Apr 4, 2026

Problem

When opening a VSCode workspace of the following structure with the extension, where the workspace root does not contain a package manifest file

repository/                 # <-- repository is workspace root, but no package.json at that level
    typescript/
        package.json
        knip.json
        packages/
        app/
            package.json
        ...
    ...

Knip will fail with

2026-04-03 16:13:23.402 [info] Initializing extension
2026-04-03 16:13:23.402 [info] Starting Knip Language Server for repository
2026-04-03 16:13:23.653 [info] Managing 1 workspace(s): /Users/alm/Desktop/__/repository
2026-04-03 16:13:23.655 [info] Using bundled knip v6.1.0
2026-04-03 16:13:23.655 [info] Creating options
2026-04-03 16:13:23.656 [info] [Error - 4:13:23 PM] Error: Error: Unable to find package.json

Solution

This adds a workspaceRoot option to the VSCode settings config to specify a knip root other than the currently open VSCode workspace.

This config:

{
  "knip.workspaceRoot": "./typescript"
}

Yields

2026-04-03 17:51:02.077 [info] Initializing extension
2026-04-03 17:51:02.077 [info] Starting Knip Language Server for repository
2026-04-03 17:51:02.222 [info] Managing 1 workspace(s): /Users/alm/Desktop/__/repository (Knip root: /Users/alm/Desktop/__/repository/typescript)
2026-04-03 17:51:02.633 [info] Using local knip v6.0.4
2026-04-03 17:51:02.633 [info] Creating options
2026-04-03 17:51:02.828 [info] Building module graph...
2026-04-03 17:51:05.876 [info] Finished building module graph (3048ms)

@anmilleriii anmilleriii changed the title feat(vscode-knip): add workspaceRoot config for VSCode open in non-root workspace feat(vscode-knip): add workspaceRoot config option to customize workspace root Apr 4, 2026
@anmilleriii anmilleriii changed the title feat(vscode-knip): add workspaceRoot config option to customize workspace root feat(vscode-knip): add workspaceRoot config option to enable opening a VSCode workspace that does not have package.json at the workspace root Apr 4, 2026
@anmilleriii anmilleriii marked this pull request as ready for review April 4, 2026 00:51
@anmilleriii anmilleriii changed the title feat(vscode-knip): add workspaceRoot config option to enable opening a VSCode workspace that does not have package.json at the workspace root feat(vscode): add workspaceRoot config option to enable use in a VSCode workspace that does not have package.json at the workspace root Apr 4, 2026
@webpro webpro force-pushed the main branch 3 times, most recently from 2842c6f to 1803f9f Compare May 1, 2026 06:44
@webpro webpro force-pushed the main branch 3 times, most recently from 67650e2 to c226a72 Compare May 6, 2026 06:57
@webpro webpro force-pushed the al/workspace-root branch from f3dffed to 1a77812 Compare May 16, 2026 09:00
@webpro
Copy link
Copy Markdown
Member

webpro commented May 16, 2026

Thanks for PR! Agreed this is good to have. Took the time to dive into the VS Code extension, and this is a slightly more minimal version. Can you please confirm this works for you as well?

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/knip@1667
npm i https://pkg.pr.new/@knip/language-server@1667
npm i https://pkg.pr.new/@knip/mcp@1667

commit: 1a77812

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