Skip to content

Commit 695719e

Browse files
authored
Wait for config to be ready before accessing values (#3799)
1 parent c8916ee commit 695719e

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

extension/src/config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ export class Config extends DeferredDisposable {
5757
}
5858

5959
public async setPythonBinPath() {
60-
this.pythonBinPath = await this.getConfigOrExtensionPythonBinPath()
61-
return this.deferred.resolve()
60+
const pythonBinPath = await this.getConfigOrExtensionPythonBinPath()
61+
this.pythonBinPath = pythonBinPath
62+
this.deferred.resolve()
6263
}
6364

6465
public async setPythonAndNotifyIfChanged() {
6566
const oldPath = this.pythonBinPath
66-
this.pythonBinPath = await this.getConfigOrExtensionPythonBinPath()
67+
await this.setPythonBinPath()
6768
this.notifyIfChanged(oldPath, this.pythonBinPath)
6869
}
6970

extension/src/setup/index.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ export class Setup
374374
return this.sendDataToWebview()
375375
}
376376

377-
public getDvcCliDetails(): DvcCliDetails {
377+
private async getDvcCliDetails(): Promise<DvcCliDetails> {
378+
await this.config.isReady()
378379
const dvcPath = this.config.getCliPath()
379380
const pythonBinPath = this.config.getPythonBinPath()
380381
const cwd = getFirstWorkspaceFolder()
@@ -389,18 +390,14 @@ export class Setup
389390
}
390391
}
391392

392-
private isDVCBeingUsedGlobally() {
393-
const dvcPath = this.config.getCliPath()
394-
const pythonBinPath = this.config.getPythonBinPath()
395-
396-
return dvcPath || !pythonBinPath
397-
}
398-
399393
private async sendDataToWebview() {
400394
const projectInitialized = this.hasRoots()
401395
const hasData = this.getHasData()
402396

403-
const isPythonExtensionUsed = await this.isPythonExtensionUsed()
397+
const [isPythonExtensionUsed, dvcCliDetails] = await Promise.all([
398+
this.isPythonExtensionUsed(),
399+
this.getDvcCliDetails()
400+
])
404401

405402
const needsGitInitialized =
406403
!projectInitialized && !!(await this.needsGitInit())
@@ -415,10 +412,9 @@ export class Setup
415412
this.webviewMessages.sendWebviewMessage({
416413
canGitInitialize,
417414
cliCompatible: this.getCliCompatible(),
418-
dvcCliDetails: this.getDvcCliDetails(),
415+
dvcCliDetails,
419416
hasData,
420-
isPythonExtensionUsed:
421-
!this.isDVCBeingUsedGlobally() && isPythonExtensionUsed,
417+
isPythonExtensionUsed,
422418
isStudioConnected: this.studioIsConnected,
423419
needsGitCommit,
424420
needsGitInitialized,

extension/src/test/suite/setup/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ suite('Setup Test Suite', () => {
577577
mockExecuteCommand.restore()
578578
mockRunSetup.restore()
579579
stub(config, 'isPythonExtensionUsed').returns(false)
580-
stub(config, 'getPythonBinPath').resolves(join('python'))
580+
stub(config, 'getPythonBinPath').returns(join('python'))
581581

582582
mockVersion.resetBehavior()
583583
mockVersion

0 commit comments

Comments
 (0)