Skip to content
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

fix frequent refresh of available profiles #138096

Merged
merged 9 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/vs/workbench/contrib/terminal/browser/terminalProfileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ export class TerminalProfileService implements ITerminalProfileService {
private _availableProfiles: ITerminalProfile[] | undefined;
private _contributedProfiles: IExtensionTerminalProfile[] = [];
private _defaultProfileName?: string;
private _platformConfigJustRefreshed = false;
private readonly _profileProviders: Map</*ext id*/string, Map</*provider id*/string, ITerminalProfileProvider>> = new Map();

private readonly _onDidChangeAvailableProfiles = new Emitter<ITerminalProfile[]>();
get onDidChangeAvailableProfiles(): Event<ITerminalProfile[]> { return this._onDidChangeAvailableProfiles.event; }

get profilesReady(): Promise<void> { return this._profilesReadyBarrier.wait().then(() => { }); }
get availableProfiles(): ITerminalProfile[] {
this.refreshAvailableProfiles();
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
if (!this._platformConfigJustRefreshed) {
this.refreshAvailableProfiles();
}
return this._availableProfiles || [];
}
get contributedProfiles(): IExtensionTerminalProfile[] {
Expand All @@ -60,21 +63,33 @@ export class TerminalProfileService implements ITerminalProfileService {
// that contributes a profile
this._extensionService.onDidChangeExtensions(() => this.refreshAvailableProfiles());

this._configurationService.onDidChangeConfiguration(async e => {
const platformKey = await this.getPlatformKey();
if (e.affectsConfiguration(TerminalSettingPrefix.DefaultProfile + platformKey) ||
e.affectsConfiguration(TerminalSettingPrefix.Profiles + platformKey) ||
e.affectsConfiguration(TerminalSettingId.UseWslProfiles)) {
this.refreshAvailableProfiles();
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
}
});
this._webExtensionContributedProfileContextKey = TerminalContextKeys.webExtensionContributedProfile.bindTo(this._contextKeyService);
this._updateWebContextKey();
// Wait up to 5 seconds for profiles to be ready so it's assured that we know the actual
// default terminal before launching the first terminal. This isn't expected to ever take
// this long.
this._profilesReadyBarrier = new AutoOpenBarrier(5000);
this.refreshAvailableProfiles();
this._setupConfigListener();
}

private async _setupConfigListener(): Promise<void> {
const platformKey = await this.getPlatformKey();
meganrogge marked this conversation as resolved.
Show resolved Hide resolved

this._configurationService.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration(TerminalSettingPrefix.DefaultProfile + platformKey) ||
e.affectsConfiguration(TerminalSettingPrefix.Profiles + platformKey) ||
e.affectsConfiguration(TerminalSettingId.UseWslProfiles)) {
if (e.source !== ConfigurationTarget.DEFAULT) {
// when _refreshPlatformConfig is called within refreshAvailableProfiles
// on did change configuration is fired. this can lead to an infinite recursion
this.refreshAvailableProfiles();
this._platformConfigJustRefreshed = false;
} else {
this._platformConfigJustRefreshed = true;
}
}
});
}

_serviceBrand: undefined;
Expand Down Expand Up @@ -107,7 +122,7 @@ export class TerminalProfileService implements ITerminalProfileService {
this._onDidChangeAvailableProfiles.fire(this._availableProfiles);
this._profilesReadyBarrier.open();
this._updateWebContextKey();
await this._refreshPlatformConfig(profiles);
await this._refreshPlatformConfig(this._availableProfiles);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IExtensionTerminalProfile, ITerminalProfile } from 'vs/platform/termina
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { isLinux, isWindows, OperatingSystem } from 'vs/base/common/platform';
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
Expand Down Expand Up @@ -213,7 +213,7 @@ suite('TerminalProfileService', () => {
}
}
});
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: () => true } as any);
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: () => true, source: ConfigurationTarget.USER } as any);
await terminalProfileService.refreshAndAwaitAvailableProfiles();
deepStrictEqual(terminalProfileService.availableProfiles, [powershellProfile]);
deepStrictEqual(terminalProfileService.contributedProfiles, []);
Expand All @@ -229,7 +229,7 @@ suite('TerminalProfileService', () => {
}
}
});
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: () => true } as any);
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: () => true, source: ConfigurationTarget.USER } as any);
await terminalProfileService.refreshAndAwaitAvailableProfiles();
deepStrictEqual(terminalProfileService.availableProfiles, [powershellProfile]);
deepStrictEqual(terminalProfileService.contributedProfiles, []);
Expand All @@ -245,7 +245,7 @@ suite('TerminalProfileService', () => {
}
}
});
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: () => true } as any);
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: () => true, source: ConfigurationTarget.USER } as any);
await terminalProfileService.refreshAndAwaitAvailableProfiles();
deepStrictEqual(terminalProfileService.availableProfiles, [powershellProfile]);
deepStrictEqual(terminalProfileService.contributedProfiles, []);
Expand Down Expand Up @@ -283,7 +283,6 @@ suite('TerminalProfileService', () => {
}
}
});
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: () => true } as any);
await terminalProfileService.hasRefreshedProfiles;
deepStrictEqual(calls, [
[powershellProfile]
Expand Down