Skip to content

Commit 36e24e0

Browse files
author
Kartik Raj
authored
Ensure we can change interpreters after trusting a workspace (#19353)
Fix changing of interpreters after a workspace is trusted
1 parent 11ae692 commit 36e24e0

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/client/common/configSettings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ export class PythonSettings implements IPythonSettings {
507507
}
508508
}
509509

510+
public register(): void {
511+
PythonSettings.pythonSettings = new Map();
512+
this.initialize();
513+
}
514+
510515
public initialize(): void {
511516
const onDidChange = () => {
512517
const currentConfig = this.workspace.getConfiguration('python', this.workspaceRoot);

src/client/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export interface IPythonSettings {
201201
readonly languageServerIsDefault: boolean;
202202
readonly defaultInterpreterPath: string;
203203
readonly tensorBoard: ITensorBoardSettings | undefined;
204-
initialize(): void;
204+
register(): void;
205205
}
206206

207207
export interface ITensorBoardSettings {

src/client/extensionActivation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async function activateLegacy(ext: ExtensionState): Promise<ActivationResult> {
124124

125125
const configuration = serviceManager.get<IConfigurationService>(IConfigurationService);
126126
// Settings are dependent on Experiment service, so we need to initialize it after experiments are activated.
127-
serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings().initialize();
127+
serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings().register();
128128

129129
// Language feature registrations.
130130
appRegisterTypes(serviceManager);

src/client/interpreter/interpreterService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { sendTelemetryEvent } from '../telemetry';
2929
import { EventName } from '../telemetry/constants';
3030
import { cache } from '../common/utils/decorators';
3131
import { PythonLocatorQuery, TriggerRefreshOptions } from '../pythonEnvironments/base/locator';
32+
import { sleep } from '../common/utils/async';
3233

3334
type StoredPythonEnvironment = PythonEnvironment & { store?: boolean };
3435

@@ -182,9 +183,13 @@ export class InterpreterService implements Disposable, IInterpreterService {
182183
}
183184

184185
public async _onConfigChanged(resource?: Uri): Promise<void> {
185-
this.didChangeInterpreterConfigurationEmitter.fire(resource);
186-
// Check if we actually changed our python path
186+
// Check if we actually changed our python path.
187+
// Config service also updates itself on interpreter config change,
188+
// so yielding control here to make sure it goes first and updates
189+
// itself before we can query it.
190+
await sleep(1);
187191
const pySettings = this.configService.getSettings(resource);
192+
this.didChangeInterpreterConfigurationEmitter.fire(resource);
188193
if (this._pythonPathSetting === '' || this._pythonPathSetting !== pySettings.pythonPath) {
189194
this._pythonPathSetting = pySettings.pythonPath;
190195
this.didChangeInterpreterEmitter.fire();

0 commit comments

Comments
 (0)