Skip to content

Commit 8487c3b

Browse files
authored
Ensure DVC tracked tree is rebuilt when a dvc yaml error has been fixed (#3300)
1 parent e4b9165 commit 8487c3b

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

extension/src/repository/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ export class Repository extends DeferredDisposable {
9696
this.treeDataChanged.fire()
9797
this.sourceControlManagement.setState(sourceControlManagementState)
9898
this.scmDecorationProvider.setState(scmDecorationState)
99-
if (errorDecorationState) {
100-
this.errorDecorationProvider.setState(errorDecorationState)
101-
}
99+
this.errorDecorationProvider.setState(errorDecorationState)
102100
}
103101
}

extension/src/repository/model/decorationProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { EventEmitter, FileDecoration, Uri } from 'vscode'
22
import { DecoratableTreeItemScheme, getDecoratableUri } from '../../tree'
33
import { ErrorDecorationProvider } from '../../tree/errorDecorationProvider'
4+
import { uniqueValues } from '../../util/array'
45

56
export class DecorationProvider extends ErrorDecorationProvider {
67
private errors = new Set<string>()
@@ -15,10 +16,10 @@ export class DecorationProvider extends ErrorDecorationProvider {
1516
}
1617
}
1718

18-
public setState(errors: Set<string>) {
19+
public setState(errors: Set<string> = new Set()) {
1920
const urisToUpdate: Uri[] = []
2021

21-
for (const label of errors) {
22+
for (const label of uniqueValues([...errors, ...this.errors])) {
2223
urisToUpdate.push(getDecoratableUri(label, this.scheme))
2324
}
2425
this.errors = errors

extension/src/repository/model/index.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,34 @@ describe('RepositoryModel', () => {
231231
untracked: []
232232
})
233233
})
234+
235+
it('should clear an error when there is no data in the tree and the error is fixed', () => {
236+
const emptyRepoData = {
237+
dataStatus: {},
238+
hasGitChanges: true,
239+
untracked: new Set<string>()
240+
}
241+
242+
const msg = "'./dvc.yaml' validation failed.\n\nwith some other text"
243+
244+
const error = {
245+
msg,
246+
type: 'caught error'
247+
}
248+
249+
const emptyRepoError = { ...emptyRepoData, dataStatus: { error } }
250+
const model = new RepositoryModel(dvcDemoPath)
251+
252+
model.transformAndSet(emptyRepoData)
253+
expect(model.getChildren(dvcDemoPath)).toStrictEqual([])
254+
255+
model.transformAndSet(emptyRepoError)
256+
expect(model.getChildren(dvcDemoPath)).toStrictEqual([
257+
{ error: { label: './dvc.yaml validation failed.', msg } }
258+
])
259+
260+
model.transformAndSet(emptyRepoData)
261+
expect(model.getChildren(dvcDemoPath)).toStrictEqual([])
262+
})
234263
})
235264
})

extension/src/repository/model/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ export class RepositoryModel extends Disposable {
8787
}
8888

8989
private collectTree(tracked: Set<string>): void {
90-
if (!sameContents([...tracked], [...this.getTracked()])) {
90+
const errorNeedsCleared = this.tree.get(this.dvcRoot)?.[0]?.error
91+
if (
92+
errorNeedsCleared ||
93+
!sameContents([...tracked], [...this.getTracked()])
94+
) {
9195
this.tracked = tracked
9296
this.tree = collectTree(this.dvcRoot, this.tracked)
9397
}

0 commit comments

Comments
 (0)