Skip to content

Commit 5851af4

Browse files
authored
Fix plots file watchers (diff output key is not a file) (#2854)
1 parent e6e62d5 commit 5851af4

File tree

6 files changed

+24737
-5717
lines changed

6 files changed

+24737
-5717
lines changed

extension/src/data/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export abstract class BaseData<
108108
)
109109
}
110110

111-
abstract collectFiles(data: T): string[]
112-
113111
abstract managedUpdate(path?: string): Promise<unknown>
112+
113+
protected abstract collectFiles(data: T): string[]
114114
}

extension/src/experiments/data/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
4343
this.managedUpdate(QUEUED_EXPERIMENT_PATH)
4444
}
4545

46-
public collectFiles(data: ExperimentsOutput) {
47-
return collectFiles(data, this.collectedFiles)
48-
}
49-
5046
public managedUpdate(path?: string) {
5147
if (
5248
path?.includes(QUEUED_EXPERIMENT_PATH) ||
@@ -76,6 +72,10 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
7672
return this.processManager.forceRunQueued()
7773
}
7874

75+
protected collectFiles(data: ExperimentsOutput) {
76+
return collectFiles(data, this.collectedFiles)
77+
}
78+
7979
private async watchExpGitRefs(): Promise<void> {
8080
const gitRoot = await this.internalCommands.executeCommand(
8181
AvailableCommands.GIT_GET_REPOSITORY_ROOT,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { PlotsOutputOrError } from '../../cli/dvc/contract'
2+
import { isDvcError } from '../../cli/dvc/reader'
3+
import { uniqueValues } from '../../util/array'
4+
import { isImagePlot, Plot, TemplatePlot } from '../webview/contract'
5+
6+
const collectImageFile = (acc: string[], file: string): void => {
7+
if (acc.includes(file)) {
8+
return
9+
}
10+
acc.push(file)
11+
}
12+
13+
const collectFromDatapoint = (
14+
acc: string[],
15+
data: Record<string, unknown>
16+
): void => {
17+
const filename = (data as { dvc_data_version_info?: { filename?: string } })
18+
?.dvc_data_version_info?.filename
19+
20+
if (!filename || acc.includes(filename)) {
21+
return
22+
}
23+
acc.push(filename)
24+
}
25+
26+
const collectTemplateFiles = (acc: string[], plot: TemplatePlot): void => {
27+
for (const datapoints of Object.values(plot.datapoints || {})) {
28+
for (const datapoint of datapoints) {
29+
collectFromDatapoint(acc, datapoint)
30+
}
31+
}
32+
}
33+
34+
const collectKeyData = (acc: string[], key: string, plots: Plot[]): void => {
35+
for (const plot of plots) {
36+
if (isImagePlot(plot)) {
37+
collectImageFile(acc, key)
38+
continue
39+
}
40+
collectTemplateFiles(acc, plot)
41+
}
42+
}
43+
44+
export const collectFiles = (
45+
data: PlotsOutputOrError,
46+
collectedFiles: string[]
47+
): string[] => {
48+
const acc = [...collectedFiles]
49+
if (isDvcError(data)) {
50+
return acc
51+
}
52+
53+
for (const [key, plots] of Object.entries(data)) {
54+
collectKeyData(acc, key, plots)
55+
}
56+
57+
return uniqueValues(acc)
58+
}

extension/src/plots/data/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EventEmitter } from 'vscode'
2+
import { collectFiles } from './collect'
23
import { PlotsOutputOrError } from '../../cli/dvc/contract'
3-
import { isDvcError } from '../../cli/dvc/reader'
44
import { AvailableCommands, InternalCommands } from '../../commands/internal'
55
import { BaseData } from '../../data'
66
import {
@@ -59,22 +59,19 @@ export class PlotsData extends BaseData<{
5959
...args
6060
)
6161

62+
this.notifyChanged({ data, revs })
63+
6264
const files = this.collectFiles({ data })
6365

6466
this.compareFiles(files)
65-
66-
return this.notifyChanged({ data, revs })
6767
}
6868

6969
public managedUpdate() {
7070
return this.processManager.run('update')
7171
}
7272

73-
public collectFiles({ data }: { data: PlotsOutputOrError }) {
74-
if (isDvcError(data)) {
75-
return this.collectedFiles
76-
}
77-
return [...Object.keys(data), ...this.collectedFiles]
73+
protected collectFiles({ data }: { data: PlotsOutputOrError }) {
74+
return collectFiles(data, this.collectedFiles)
7875
}
7976

8077
private getArgs(revs: string[]) {

0 commit comments

Comments
 (0)