-
Notifications
You must be signed in to change notification settings - Fork 61
Warn when companion extensions are too old for inline-script envs #1777
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
Merged
Stella Huang (StellaHuang95)
merged 1 commit into
microsoft:main
from
StellaHuang95:stellahuang/inline-script-extension-version-warning
Sep 11, 2026
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { compare as pep440Compare } from '@renovatebot/pep440'; | ||
| import { PYLANCE_EXTENSION_ID, PYTHON_EXTENSION_ID } from '../../common/constants'; | ||
| import { getComparableExtensionVersion } from '../../common/extVersion'; | ||
| import { Common, InlineScriptStrings } from '../../common/localize'; | ||
| import { traceInfo, traceVerbose } from '../../common/logging'; | ||
| import { getGlobalPersistentState } from '../../common/persistentState'; | ||
| import { showWarningMessage } from '../../common/window.apis'; | ||
| import { openExtension } from '../../common/workbenchCommands'; | ||
| import { getConfiguration } from '../../common/workspace.apis'; | ||
|
|
||
| export const INLINE_SCRIPT_UPDATE_EXTENSIONS_DONT_SHOW_KEY = 'python-envs:inline-script:UPDATE_EXTENSIONS_DONT_SHOW'; | ||
|
|
||
| interface CompanionExtension { | ||
| readonly id: string; | ||
| /** Newest version on each channel that still LACKS the required change; anything newer is fine. */ | ||
| readonly lastUnsupportedStable: string; | ||
| readonly lastUnsupportedPreRelease: string; | ||
| /** Patch component at or above which a version is a pre-release build. */ | ||
| readonly preReleasePatchFloor: number; | ||
| } | ||
|
|
||
| /** | ||
| * Python needs per-file interpreter resolution (`exactResource`, PR #26129, merged 2026-08-31); | ||
| * Pylance needs the `python/didChangeFilePythonPath` notification (PR #9302, merged 2026-09-01). | ||
| */ | ||
| const PYTHON_COMPANION: CompanionExtension = { | ||
| id: PYTHON_EXTENSION_ID, | ||
| lastUnsupportedStable: '2026.4.0', | ||
| lastUnsupportedPreRelease: '2026.7.2026082601', | ||
| preReleasePatchFloor: 1_000_000, | ||
| }; | ||
|
|
||
| const PYLANCE_COMPANION: CompanionExtension = { | ||
| id: PYLANCE_EXTENSION_ID, | ||
| lastUnsupportedStable: '2026.3.1', | ||
| lastUnsupportedPreRelease: '2026.3.101', | ||
| preReleasePatchFloor: 100, | ||
| }; | ||
|
|
||
| let promptShownThisSession = false; | ||
|
|
||
| export function resetInlineScriptExtensionPromptForTests(): void { | ||
| promptShownThisSession = false; | ||
| } | ||
|
|
||
| function isPylanceInUse(): boolean { | ||
| const languageServer = getConfiguration('python').get<string>('languageServer', 'Default'); | ||
| return languageServer === 'Default' || languageServer === 'Pylance'; | ||
| } | ||
|
|
||
| function isPreReleaseBuild(version: string, preReleasePatchFloor: number): boolean { | ||
| const patch = Number((version.split('.')[2] ?? '').replace(/\D.*$/, '')); | ||
| return Number.isFinite(patch) && patch >= preReleasePatchFloor; | ||
| } | ||
|
|
||
| function isOutdated(extension: CompanionExtension): boolean { | ||
| const resolved = getComparableExtensionVersion(extension.id); | ||
| if (resolved.kind !== 'version') { | ||
| traceVerbose(`inline-script companion check: ${extension.id} -> ${resolved.kind}`); | ||
| return false; | ||
| } | ||
| const lastUnsupported = isPreReleaseBuild(resolved.version, extension.preReleasePatchFloor) | ||
| ? extension.lastUnsupportedPreRelease | ||
| : extension.lastUnsupportedStable; | ||
| const outdated = pep440Compare(resolved.version, lastUnsupported) <= 0; | ||
| if (outdated) { | ||
| traceVerbose(`inline-script companion check: ${extension.id} ${resolved.version} <= ${lastUnsupported}`); | ||
| } | ||
| return outdated; | ||
| } | ||
|
|
||
| export function getOutdatedInlineScriptExtensions(): CompanionExtension[] { | ||
| const candidates = isPylanceInUse() ? [PYTHON_COMPANION, PYLANCE_COMPANION] : [PYTHON_COMPANION]; | ||
| return candidates.filter(isOutdated); | ||
| } | ||
|
|
||
| function getOutdatedMessage(outdated: readonly CompanionExtension[]): string { | ||
| const hasPython = outdated.some((extension) => extension.id === PYTHON_EXTENSION_ID); | ||
| const hasPylance = outdated.some((extension) => extension.id === PYLANCE_EXTENSION_ID); | ||
| if (hasPython && hasPylance) { | ||
| return InlineScriptStrings.updatePythonAndPylanceExtensions; | ||
| } | ||
| return hasPython ? InlineScriptStrings.updatePythonExtension : InlineScriptStrings.updatePylanceExtension; | ||
| } | ||
|
|
||
| export async function promptUpdateExtensionsForInlineScripts(): Promise<void> { | ||
| if (promptShownThisSession) { | ||
| return; | ||
| } | ||
|
|
||
| const outdated = getOutdatedInlineScriptExtensions(); | ||
| if (outdated.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // Latched here, not on entry, so an up-to-date run does not consume the session's one prompt. | ||
| promptShownThisSession = true; | ||
|
|
||
| const state = await getGlobalPersistentState(); | ||
| if (await state.get<boolean>(INLINE_SCRIPT_UPDATE_EXTENSIONS_DONT_SHOW_KEY)) { | ||
| traceInfo('Skipping inline-script companion extension prompt: user selected "Don\'t Show Again".'); | ||
| return; | ||
| } | ||
|
|
||
| const names = outdated.map((extension) => extension.id).join(', '); | ||
| traceInfo(`Inline-script companion extensions out of date: ${names}`); | ||
|
|
||
| const result = await showWarningMessage( | ||
| getOutdatedMessage(outdated), | ||
| InlineScriptStrings.updateExtension, | ||
| Common.dontShowAgain, | ||
| ); | ||
|
|
||
| if (result === InlineScriptStrings.updateExtension) { | ||
| await openExtension(outdated[0].id); | ||
| } else if (result === Common.dontShowAgain) { | ||
| await state.set(INLINE_SCRIPT_UPDATE_EXTENSIONS_DONT_SHOW_KEY, true); | ||
| traceInfo('User selected "Don\'t Show Again" for the inline-script companion extension prompt.'); | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { | |
| import { asRelativePath, findFiles, getOpenTextDocuments } from '../../common/workspace.apis'; | ||
| import { EnvironmentManagers } from '../../internal.api'; | ||
| import { registerInlineScriptCodeLens } from './codeLens'; | ||
| import { promptUpdateExtensionsForInlineScripts } from './extensionVersionCheck'; | ||
|
|
||
| /** | ||
| * Hidden command invoked by the inline-script CodeLens to set up the environment for one script. | ||
|
|
@@ -115,7 +116,9 @@ function setupInlineScriptEnvironmentHandler( | |
| const environment = await setUpInlineScriptEnvironment(uri, em, routing); | ||
| if (!environment) { | ||
| notifyInlineScriptSetupOutcome(uri, routing); | ||
| return; | ||
| } | ||
| await promptUpdateExtensionsForInlineScripts(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the advisory prompt rejects after environment creation, this handler reports setup as failed. Isolate prompt failures from the setup |
||
| } catch (error) { | ||
| traceError(`Failed to set up the inline-script environment for ${uri.fsPath}:`, error); | ||
| showErrorMessage( | ||
|
|
@@ -259,6 +262,12 @@ export async function setUpInlineScriptEnvironmentsInWorkspace( | |
| `Inline-script bulk setup: created or reused ${succeeded} of ${picks.length} environment(s)` + | ||
| `${cancelled ? ' (canceled)' : ''}.`, | ||
| ); | ||
| if (succeeded > 0) { | ||
| // Not awaited so the run summary below is not held behind this notification. | ||
| void promptUpdateExtensionsForInlineScripts().catch((error) => | ||
| traceError('Failed to check companion extension versions for inline scripts:', error), | ||
| ); | ||
| } | ||
| if (cancelled) { | ||
| showWarningMessage( | ||
| l10n.t( | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When both extensions are outdated, the combined prompt names both but
outdated[0]opens only Python, and the session latch prevents another prompt. Provide separate actions or make every named update reachable.