Skip to content

Commit

Permalink
python: do not refresh interpreters on quickpick open (#4462)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a pull request.
If this is your first pull request you can find information about
contributing here:
  * https://github.com/posit-dev/positron/blob/main/CONTRIBUTING.md

We recommend synchronizing your branch with the latest changes in the
main branch by either pulling or rebasing.
-->

<!--
  Describe briefly what problem this pull request resolves, or what
  new feature it introduces. Include screenshots of any new or altered
  UI. Link to any GitHub issues but avoid "magic" keywords that will 
  automatically close the issue. If there are any details about your 
approach that are unintuitive or you want to draw attention to, please
  describe them here.
-->

related to #3944 

Keeps the lists of interpreters the same, rather than refreshing only
the first time the Select Interpreter QuickPick is opened which makes it
seem like the Positron dropdown is out of sync.

This nudges people towards refreshing manually when they have created a
new environment, which I believe to be the desired behavior since
Positron will not have to continually watch for new envs (which can be
expensive, some discussion
#2003). I've opened #4269 to
track better UI to make refreshing interpreters more obvious.

### QA Notes

<!--
  Add additional information for QA on how to validate the change,
  paying special attention to the level of risk, adjacent areas that
  could be affected by the change, and any important contextual
  information not present in the linked issues.
-->

Scenario 1:

1. Open Positron
2. Create new pyenv environment via something like `pyenv virtualenv
3.9.4 test-startup`
3. Check: no new env discovered in Positron dropdown, no new env
discovered in `Python: Select Interpreter`
4. Refresh envs using button in `Python: Select Interpreter`
5. See env populate in both locations

Scenario 2:

1. Open Positron
2. Create new pyenv environment via something like `pyenv virtualenv
3.9.4 test-startup`
3. Close Positron
4. Open Positron
5. See env populate in both locations
  • Loading branch information
isabelizimm authored Aug 30, 2024
1 parent 616d8fa commit d43bd84
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
4 changes: 3 additions & 1 deletion extensions/positron-python/src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export async function activateComponents(
}
const promises: Promise<ActivationResult>[] = [
// More component activations will go here
pythonEnvironments.activate(components.pythonEnvs, ext),
// --- Start Positron ---
pythonEnvironments.activateAndRefreshEnvs(components.pythonEnvs),
// --- End Positron
];
return Promise.all([legacyActivationResult, ...promises]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,19 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
// always trigger a refresh.
if (this.interpreterService.getInterpreters().length === 0) {
this.refreshCallback(quickPick, { showBackButton: params?.showBackButton });
} else {
this.refreshCallback(quickPick, {
ifNotTriggerredAlready: true,
showBackButton: params?.showBackButton,
});
}
// --- Start Positron ---
// Do not trigger a refresh when QuickPick is opened, to keep behavior the same
// between the Quick Pick and the Positron Interpreter Selector

// else {
// this.refreshCallback(quickPick, {
// ifNotTriggerredAlready: true,
// showBackButton: params?.showBackButton,
// });
// }

// --- End Positron ---
},
onChangeItem: {
event: this.interpreterService.onDidChangeInterpreters,
Expand Down
20 changes: 20 additions & 0 deletions extensions/positron-python/src/client/pythonEnvironments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ export async function initialize(ext: ExtensionState): Promise<IDiscoveryAPI> {
return api;
}

// --- Start Positron ---
/**
* Make use of the component (e.g. register with VS Code).
*/
export async function activateAndRefreshEnvs(api: IDiscoveryAPI): Promise<ActivationResult> {
/**
* Force a background refresh of the environments for each extension activation
*
* Based off activate(), but not including the logic around triggering only if
* it has not previously been triggered
*/

api.triggerRefresh().ignoreErrors();

return {
fullyReady: Promise.resolve(),
};
}
// --- End Positron ---

/**
* Make use of the component (e.g. register with VS Code).
*/
Expand Down

0 comments on commit d43bd84

Please sign in to comment.