refactor(positron): use @posit-dev/positron for Positron types - #4334
refactor(positron): use @posit-dev/positron for Positron types#4334dotNomad wants to merge 4 commits into
Conversation
Replace the hand-maintained positron.d.ts with the published @posit-dev/positron package, which became usable in 0.2.7 after the unshipped vscode-dts reference directives were removed upstream (posit-dev/positron-api-pkg#4). Acquire the API via the package's tryAcquirePositronApi(), which feature-detects Positron and returns undefined outside it, removing the local global declaration and the try/catch around acquisition. The published types are stricter: getPreferredRuntime may resolve to undefined, and the injected global is typed as possibly-undefined, which surfaced an unchecked call in the Positron extension host test. Contract tests no longer alias the positron module, so the package's real acquisition logic runs against a mock host that injects acquirePositronApi on globalThis. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…nfig The comment explained why @posit-dev/positron is not aliased, which only reads as informative while the removed alias is recent. How the mock works is documented in src/mocks/positron.ts, where it belongs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Keep only the non-obvious part, why return types are not compared. The rest restated the assertion below it and duplicated the mocks/positron.ts header. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Claude finished @dotNomad's task in 1m 42s —— View job Code Review
Verdict: Approve This is a clean, well-structured refactor that replaces hand-maintained Positron type declarations with the official What I reviewed
Minor observations (no changes needed)
Good work keeping the test isolation patterns consistent and ensuring backward compatibility with older Positron builds through the tilde expansion logic. |
Intent
Resolves #3647.
Publisher hand-maintained a partial copy of the Positron API types.
@posit-dev/positroncould not be adopted until now because its publishedpositron.d.tsreferencedvscode-dts/files that were not shipped in the package (posit-dev/positron-api-pkg#4). Version 0.2.7 removes those reference directives, so the package now compiles against our pinned@types/vscode1.105.0 withoutskipLibCheck.Type of Change
Approach
src/utils/vscode.tsacquires the API through the package'stryAcquirePositronApi()instead of calling the injectedacquirePositronApiglobal directly. That helper does the feature detection and returnsundefinedoutside Positron, so the localdeclare globalblock and the try/catch around acquisition both go away;nullremains the "already probed" cache sentinel.The published types are stricter than the hand-written ones in two places:
getPreferredRuntimereturnsLanguageRuntimeMetadata | undefined, and the injected global is typed as possibly-undefined. The latter surfaced an unchecked call insrc/test/positron/extension.test.ts, now guarded byinPositron().The contract tests drop their
positronmodule alias. The mock's job narrows to impersonating the Positron host by injectingacquirePositronApionglobalThis, which means the package's real acquisition logic now runs during contract tests rather than being aliased away.positron.conformance.tschecks the mock against the published package instead of the deleted local declaration.User Impact
None. Type definitions and API acquisition only, no behavior change.
Automated Tests
Covered by the existing contract tests (
interpreter-discovery), the conformance check, and the Positron-only integration suite insrc/test/positron/, which exercises the new acquisition path inside a real Positron build.