Repository navigation
feat(vscode): add rstack.rstackCli.packagePath setting #104
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
Open
fi3ework
wants to merge
5
commits into
main
Choose a base branch
from
feat-rstack-cli-package-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5f48da
feat(vscode): add rstack.rstackCli.packagePath setting
fi3ework 8b5cb17
fix(vscode): pass the rstack resolve hook as a node --import argument
fi3ework 83c056e
refactor(vscode): carry the rstack resolution source to the resolve hook
fi3ework b5efbe9
refactor(vscode): trim the rstack package path plumbing
fi3ework 7d97e99
fix(vscode): retire the Rstest invalid-setting crash once rstack reso…
fi3ework File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 26.11.1 |
5 changes: 5 additions & 0 deletions
5
packages/vscode/e2e/fixtures/rstack-cli-package-path/.vscode/settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| // The setting under test (#103): the only way the extension can find the | ||
| // `rstack` installed under `infra/`. | ||
| "rstack.rstackCli.packagePath": "infra/node_modules/rstack" | ||
| } |
13 changes: 13 additions & 0 deletions
13
packages/vscode/e2e/fixtures/rstack-cli-package-path/infra/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "name": "rstack-editor-fixture-rstack-cli-package-path-infra", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "The tooling install of the rstack-cli-package-path fixture, outside the folder root's walk-up.", | ||
| "dependencies": { | ||
| "rstack": "0.8.4" | ||
| }, | ||
| "devDependencies": { | ||
| "jiti": "^2.7.0" | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
packages/vscode/e2e/fixtures/rstack-cli-package-path/infra/pnpm-workspace.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # E2E fixture install config; rationale in packages/vscode/e2e/setupFixtures.mjs. | ||
| minimumReleaseAgeExclude: | ||
| - rstack | ||
| - '@rslint/*' | ||
| - '@rstest/core' | ||
| - '@rsbuild/core' | ||
| - '@rslib/core' | ||
| - '@rstackjs/*' | ||
| - rsbuild-plugin-dts | ||
| - '@rspack/*' |
7 changes: 7 additions & 0 deletions
7
packages/vscode/e2e/fixtures/rstack-cli-package-path/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "rstack-editor-fixture-rstack-cli-package-path", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "E2E fixture (#103): a root `rstack.config.ts` whose `rstack` is installed only under `infra/`." | ||
| } |
23 changes: 23 additions & 0 deletions
23
packages/vscode/e2e/fixtures/rstack-cli-package-path/rstack.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Rstack configuration guide: https://rstack.rs/config | ||
| // | ||
| // The #103 layout: this config sits at the workspace folder root, but | ||
| // `rstack` is installed only under `infra/`, where no `node_modules` walk-up | ||
| // from the root can see it. `.vscode/settings.json` points | ||
| // `rstack.rstackCli.packagePath` at that installation, which must light all | ||
| // three stacks. The E2E harness copies the fixture out of this repository first, | ||
| // so the repository's own `node_modules/rstack` cannot satisfy the walk-up. | ||
| import { define } from 'rstack'; | ||
|
|
||
| define.lint([ | ||
| { | ||
| files: ['src/**/*.ts'], | ||
| rules: { | ||
| 'no-debugger': 'error', | ||
| }, | ||
| }, | ||
| ]); | ||
|
|
||
| define.test({ | ||
| name: 'rstack-editor-fixture-rstack-cli-package-path', | ||
| include: ['tests/**/*.test.ts'], | ||
| }); |
6 changes: 6 additions & 0 deletions
6
packages/vscode/e2e/fixtures/rstack-cli-package-path/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // A lintable issue for the `no-debugger` rule configured through | ||
| // `define.lint()` in `rstack.config.ts`. | ||
| export function trace(value: unknown): unknown { | ||
| debugger; | ||
| return value; | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/vscode/e2e/fixtures/rstack-cli-package-path/src/needs-format.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| const answer={value:'42'}; |
7 changes: 7 additions & 0 deletions
7
packages/vscode/e2e/fixtures/rstack-cli-package-path/tests/basic.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { expect, test } from '@rstest/core'; | ||
|
|
||
| // Discovered through `define.test()` in `rstack.config.ts`, not through an | ||
| // `rstest.config.*` file. | ||
| test('trims a string', () => { | ||
| expect(' rstack '.trim()).toBe('rstack'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { createRun } from '../runSuite'; | ||
|
|
||
| export const run = createRun(__dirname); |
159 changes: 159 additions & 0 deletions
159
packages/vscode/e2e/suite-rstack-cli-package-path/rstack-cli-package-path.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // The #103 layout end to end: `rstack.config.ts` at the folder root, `rstack` | ||
| // installed only under `infra/`, and `rstack.rstackCli.packagePath` pointing at | ||
| // it (`.vscode/settings.json`). `e2e/runTest.ts` runs this from a copy outside | ||
| // the repository, so no `node_modules` walk-up can find any `rstack`: every | ||
| // stack that works here found it through the setting. | ||
| import assert from 'node:assert/strict'; | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import * as vscode from 'vscode'; | ||
| import { findPackageJsonUncached } from '../../src/shared/packageResolve'; | ||
| import { RSTACK_PACKAGE_PATH_SETTING } from '../../src/shared/rstackPackage'; | ||
| import type { RstackExtensionExports } from '../../src/types'; | ||
| import { | ||
| diagnosticRuleIdIncludes, | ||
| waitForRslintDiagnostics, | ||
| } from '../lint/utils/diagnostics'; | ||
| import { | ||
| createCollectingMockRun, | ||
| currentRstestExports, | ||
| getTestItemByLabels, | ||
| waitFor, | ||
| } from '../rstest/suite/helpers'; | ||
| import { applyEdits, eventually } from '../suite/helpers'; | ||
|
|
||
| const folder = (): vscode.WorkspaceFolder => { | ||
| const [workspaceFolder] = vscode.workspace.workspaceFolders ?? []; | ||
| assert.ok(workspaceFolder, 'the fixture workspace folder is unavailable'); | ||
| return workspaceFolder; | ||
| }; | ||
|
|
||
| /** Where `infra/node_modules/rstack` really lives (the installed fixture). */ | ||
| const infraStore = (): string => | ||
| fs.realpathSync(path.join(folder().uri.fsPath, 'infra', 'node_modules')); | ||
|
|
||
| let api: RstackExtensionExports; | ||
|
|
||
| suite('rstack.rstackCli.packagePath', () => { | ||
| suiteSetup(async () => { | ||
| const extension = | ||
| vscode.extensions.getExtension<RstackExtensionExports>('rstack.rstack'); | ||
| assert.ok(extension, 'rstack.rstack is not installed in the test host'); | ||
| api = await extension.activate(); | ||
| // No `rstack` is reachable by walk-up from the sandbox copy; the precondition | ||
| // that makes every assertion below about the setting. | ||
| assert.equal( | ||
| findPackageJsonUncached('rstack', folder().uri.fsPath), | ||
| undefined, | ||
| 'a walk-up from the folder root reaches an rstack installation', | ||
| ); | ||
| }); | ||
|
|
||
| test('formats through the configured rstack', async () => { | ||
| const exports = await api.whenStackActive('fmt'); | ||
| const folderStates = exports.folderStates as () => Record<string, string>; | ||
| await eventually(() => { | ||
| assert.equal(folderStates()[folder().uri.fsPath], 'running'); | ||
| }, 'the rs fmt server to start'); | ||
|
|
||
| const uri = vscode.Uri.joinPath(folder().uri, 'src', 'needs-format.ts'); | ||
| const document = await vscode.workspace.openTextDocument(uri); | ||
| // Retry: until the server's client registers its provider, VS Code's | ||
| // built-in TypeScript formatter answers with different text. | ||
| await eventually(async () => { | ||
| const edits = await vscode.commands.executeCommand<vscode.TextEdit[]>( | ||
| 'vscode.executeFormatDocumentProvider', | ||
| uri, | ||
| { tabSize: 2, insertSpaces: true }, | ||
| ); | ||
| assert.ok(edits && edits.length > 0, 'expected formatting edits'); | ||
| // Prettier's quote normalization: VS Code's built-in formatter cannot | ||
| // produce it, so a fallback cannot satisfy this. | ||
| assert.equal( | ||
| applyEdits(document, edits), | ||
| 'const answer = { value: "42" };\n', | ||
| ); | ||
| }, 'rs fmt to format the document'); | ||
| }); | ||
|
|
||
| test('lints through the configured rstack and its @rslint/core', async () => { | ||
| const document = await vscode.workspace.openTextDocument( | ||
| vscode.Uri.joinPath(folder().uri, 'src', 'index.ts'), | ||
| ); | ||
| await vscode.window.showTextDocument(document); | ||
| await waitForRslintDiagnostics(document, (diagnostics) => | ||
| diagnostics.some((diagnostic) => | ||
| diagnosticRuleIdIncludes(diagnostic, 'no-debugger'), | ||
| ), | ||
| ); | ||
|
|
||
| const lint = api.getStackExports('rslint'); | ||
| assert.ok(lint, 'the Rslint stack should be active'); | ||
| const runtimes = ( | ||
| lint.getRuntimeStates as () => ReadonlyMap<string, unknown> | ||
| )(); | ||
| // The runtime key carries the core and shim paths: both come from the | ||
| // configured installation's store. | ||
| assert.ok( | ||
| [...runtimes.keys()].some((key) => key.includes(infraStore())), | ||
| `expected a runtime on ${infraStore()}, got: ${[...runtimes.keys()].join(' | ')}`, | ||
| ); | ||
| }); | ||
|
|
||
| test('discovers and runs bridged tests through the configured rstack', async () => { | ||
| const { rstestInstance, item } = await waitFor( | ||
| () => { | ||
| const rstestInstance = currentRstestExports(); | ||
| return { | ||
| rstestInstance, | ||
| item: getTestItemByLabels(rstestInstance.testController.items, [ | ||
| 'tests', | ||
| 'basic.test.ts', | ||
| ]), | ||
| }; | ||
| }, | ||
| { timeoutMs: 60_000 }, | ||
| ); | ||
|
|
||
| const sourceUri = vscode.Uri.joinPath( | ||
| folder().uri, | ||
| 'rstack.config.ts', | ||
| ).toString(); | ||
| const rstestPath = rstestInstance.getResolvedRstestPath(sourceUri); | ||
| assert.ok( | ||
| rstestPath?.startsWith(infraStore()), | ||
| `expected rstack's own @rstest/core under ${infraStore()}, got: ${rstestPath}`, | ||
| ); | ||
|
|
||
| const collecting = createCollectingMockRun(); | ||
| void rstestInstance.startTestRun( | ||
| new vscode.TestRunRequest([item], undefined, rstestInstance.runProfile), | ||
| new vscode.CancellationTokenSource().token, | ||
| false, | ||
| collecting.createMockRun, | ||
| ); | ||
| await collecting.ended; | ||
| assert.equal(collecting.failedMessages.length, 0, collecting.output); | ||
| assert.deepEqual( | ||
| collecting.passedItems.map((passed) => passed.label).sort(), | ||
| ['basic.test.ts', 'trims a string'], | ||
| ); | ||
| }); | ||
|
|
||
| test('falls back to not installed once the setting is cleared', async () => { | ||
| // The setting is a restart trigger; the rebuilt fmt stack walks up again | ||
| // and finds nothing. | ||
| await vscode.workspace | ||
| .getConfiguration(undefined, folder().uri) | ||
| .update( | ||
| RSTACK_PACKAGE_PATH_SETTING, | ||
| undefined, | ||
| vscode.ConfigurationTarget.WorkspaceFolder, | ||
| ); | ||
| await eventually(async () => { | ||
| const exports = await api.whenStackActive('fmt'); | ||
| const folderStates = exports.folderStates as () => Record<string, string>; | ||
| assert.equal(folderStates()[folder().uri.fsPath], 'disabled'); | ||
| }, 'the fmt stack to report rstack as not installed'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.