Skip to content

Add support for dynamic updates in interpreter list - #17043

Merged
Kartik Raj (karrtikr) merged 19 commits into
microsoft:mainfrom
karrtikr:improveinterpreterdisplay
Sep 21, 2021
Merged

Add support for dynamic updates in interpreter list#17043
Kartik Raj (karrtikr) merged 19 commits into
microsoft:mainfrom
karrtikr:improveinterpreterdisplay

Conversation

@karrtikr

@karrtikr Kartik Raj (karrtikr) commented Aug 20, 2021

Copy link
Copy Markdown

Closes https://github.com/microsoft/vscode-python-internalbacklog/issues/380

Quickpick loads with the sorted list of known environments. If an env gets added to the known list, its added to the end of items list. A lot of effort here is done so that the visible items do not change when the list is loading.

@karrtikr
Kartik Raj (karrtikr) marked this pull request as ready for review September 16, 2021 23:12
const invalidIndexes = areEnvsValid.map((isValid, index) => (isValid ? -1 : index)).filter((i) => i !== -1);
invalidIndexes.forEach((index) => {
const env = this.envs.splice(index, 1)[0];
this.fire({ old: env, update: undefined });

@karrtikr Kartik Raj (karrtikr) Sep 16, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to ensure we fire events for any envs removed from collection.


public get refreshPromise(): Promise<void> {
return Promise.all(Array.from(this.refreshPromises.values())).then();
public get refreshPromise(): Promise<void> | undefined {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need to set quickpick as busy if a refresh is going on, so returning undefined is helpful.

await updateEnvUsingRegistry(resolvedEnv);
}
// Display name is not set here as we need version, arch etc. to build it.
resolvedEnv.display = getEnvDisplayString(resolvedEnv);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow to show partial display names with the partial info we have.

*/
@cache(30_000, true, 10_000)
// eslint-disable-next-line class-methods-use-this
private async getInfoCached(command: string): Promise<CondaInfo> {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed it was not cached and was being run twice.

iconPath: getIcon(REFRESH_BUTTON_ICON),
tooltip: InterpreterQuickPickList.refreshInterpreterList(),
},
callback: () => this.interpreterService.triggerRefresh(),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All we need to do is trigger the refresh, the list is automatically updated one by one via change events in the onChanged handler.


private async setRecommendedItem(items: QuickPickType[], resource: Resource) {
const interpreterSuggestions = await this.interpreterSelector.getSuggestions(resource);
if (!this.interpreterService.refreshPromise && interpreterSuggestions.length > 0) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice we only set a recommended item only after refresh has finished, otherwise recommended item can change while the list is loading. Let me know if you disagree..

@karrtikr

Copy link
Copy Markdown
Author

Ping Karthik Nadig (@karthiknadig)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!!!

@karrtikr
Kartik Raj (karrtikr) merged commit ec62819 into microsoft:main Sep 21, 2021
@karrtikr
Kartik Raj (karrtikr) deleted the improveinterpreterdisplay branch September 21, 2021 23:19
@karrtikr Kartik Raj (karrtikr) added the on-testplan Added to test plan label Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on-testplan Added to test plan

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants