Skip to content

Commit 3c585c0

Browse files
committed
exclude sub project files from file and editor watchers
1 parent 1b72b59 commit 3c585c0

File tree

24 files changed

+222
-52
lines changed

24 files changed

+222
-52
lines changed

extension/src/data/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export abstract class BaseData<
2929
protected readonly internalCommands: InternalCommands
3030
protected collectedFiles: string[] = []
3131

32+
private readonly relSubProjects: string[]
3233
private readonly staticFiles: string[]
3334

3435
private readonly updated: EventEmitter<T> = this.dispose.track(
@@ -39,6 +40,7 @@ export abstract class BaseData<
3940
dvcRoot: string,
4041
internalCommands: InternalCommands,
4142
updateProcesses: { name: string; process: () => Promise<unknown> }[],
43+
subProjects: string[],
4244
staticFiles: string[] = []
4345
) {
4446
super()
@@ -49,6 +51,9 @@ export abstract class BaseData<
4951
)
5052
this.internalCommands = internalCommands
5153
this.onDidUpdate = this.updated.event
54+
this.relSubProjects = subProjects.map(subProject =>
55+
relative(this.dvcRoot, subProject)
56+
)
5257
this.staticFiles = staticFiles
5358

5459
this.watchFiles()
@@ -81,6 +86,9 @@ export abstract class BaseData<
8186
path => {
8287
const relPath = relative(this.dvcRoot, path)
8388
if (
89+
!this.relSubProjects.some(subProject =>
90+
relPath.startsWith(subProject)
91+
) &&
8492
this.getWatchedFiles().some(
8593
watchedRelPath =>
8694
path.endsWith(watchedRelPath) ||

extension/src/experiments/context.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { Event, EventEmitter, window } from 'vscode'
22
import { Disposable, Disposer } from '@hediet/std/disposable'
33
import { ContextKey, setContextValue } from '../vscode/context'
44
import { standardizePossiblePath } from '../fileSystem/path'
5+
import { isFileInSubProject } from '../fileSystem'
56

67
const setContextOnDidChangeParamsFiles = (
78
setActiveEditorContext: (paramsFileActive: boolean) => void,
89
onDidChangeColumns: Event<void>,
9-
getParamsFiles: () => Set<string>
10+
getParamsFiles: () => Set<string>,
11+
subProjects: string[]
1012
): Disposable =>
1113
onDidChangeColumns(() => {
1214
const path = standardizePossiblePath(
@@ -16,7 +18,10 @@ const setContextOnDidChangeParamsFiles = (
1618
return
1719
}
1820

19-
if (!getParamsFiles().has(path) && !path.endsWith('dvc.yaml')) {
21+
if (
22+
(!getParamsFiles().has(path) && !path.endsWith('dvc.yaml')) ||
23+
isFileInSubProject(path, subProjects)
24+
) {
2025
return
2126
}
2227
setActiveEditorContext(true)
@@ -25,7 +30,8 @@ const setContextOnDidChangeParamsFiles = (
2530
const setContextOnDidChangeActiveEditor = (
2631
setActiveEditorContext: (paramsFileActive: boolean) => void,
2732
dvcRoot: string,
28-
getParamsFiles: () => Set<string>
33+
getParamsFiles: () => Set<string>,
34+
subProjects: string[]
2935
): Disposable =>
3036
window.onDidChangeActiveTextEditor(event => {
3137
const path = standardizePossiblePath(event?.document.fileName)
@@ -34,7 +40,7 @@ const setContextOnDidChangeActiveEditor = (
3440
return
3541
}
3642

37-
if (!path.includes(dvcRoot)) {
43+
if (!path.includes(dvcRoot) || isFileInSubProject(path, subProjects)) {
3844
return
3945
}
4046

@@ -49,7 +55,8 @@ export const setContextForEditorTitleIcons = (
4955
disposer: (() => void) & Disposer,
5056
getParamsFiles: () => Set<string>,
5157
experimentsFileFocused: EventEmitter<string | undefined>,
52-
onDidChangeColumns: Event<void>
58+
onDidChangeColumns: Event<void>,
59+
subProjects: string[]
5360
): void => {
5461
const setActiveEditorContext = (experimentsFileActive: boolean) => {
5562
void setContextValue(
@@ -64,15 +71,17 @@ export const setContextForEditorTitleIcons = (
6471
setContextOnDidChangeParamsFiles(
6572
setActiveEditorContext,
6673
onDidChangeColumns,
67-
getParamsFiles
74+
getParamsFiles,
75+
subProjects
6876
)
6977
)
7078

7179
disposer.track(
7280
setContextOnDidChangeActiveEditor(
7381
setActiveEditorContext,
7482
dvcRoot,
75-
getParamsFiles
83+
getParamsFiles,
84+
subProjects
7685
)
7786
)
7887
}

extension/src/experiments/data/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
2020
constructor(
2121
dvcRoot: string,
2222
internalCommands: InternalCommands,
23-
experiments: ExperimentsModel
23+
experiments: ExperimentsModel,
24+
subProjects: string[]
2425
) {
2526
super(
2627
dvcRoot,
2728
internalCommands,
2829
[{ name: 'update', process: () => this.update() }],
30+
subProjects,
2931
['dvc.lock', 'dvc.yaml', 'params.yaml', DOT_DVC]
3032
)
3133

extension/src/experiments/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class Experiments extends BaseRepository<TableData> {
111111
selectBranches: (
112112
branchesSelected: string[]
113113
) => Promise<string[] | undefined>,
114+
subProjects: string[],
114115
data?: ExperimentsData
115116
) {
116117
super(dvcRoot, resourceLocator.beaker)
@@ -143,7 +144,13 @@ export class Experiments extends BaseRepository<TableData> {
143144
)
144145

145146
this.data = this.dispose.track(
146-
data || new ExperimentsData(dvcRoot, internalCommands, this.experiments)
147+
data ||
148+
new ExperimentsData(
149+
dvcRoot,
150+
internalCommands,
151+
this.experiments,
152+
subProjects
153+
)
147154
)
148155

149156
this.dispose.track(this.data.onDidUpdate(data => this.setState(data)))
@@ -158,7 +165,7 @@ export class Experiments extends BaseRepository<TableData> {
158165

159166
this.webviewMessages = this.createWebviewMessageHandler()
160167
this.setupInitialData()
161-
this.watchActiveEditor()
168+
this.watchActiveEditor(subProjects)
162169
}
163170

164171
public update() {
@@ -600,13 +607,14 @@ export class Experiments extends BaseRepository<TableData> {
600607
)
601608
}
602609

603-
private watchActiveEditor() {
610+
private watchActiveEditor(subProjects: string[]) {
604611
setContextForEditorTitleIcons(
605612
this.dvcRoot,
606613
this.dispose,
607614
() => this.columns.getParamsFiles(),
608615
this.experimentsFileFocused,
609-
this.onDidChangeColumns
616+
this.onDidChangeColumns,
617+
subProjects
610618
)
611619
}
612620

extension/src/experiments/workspace.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
273273

274274
public createRepository(
275275
dvcRoot: string,
276+
subProjects: string[],
276277
pipeline: WorkspacePipeline,
277278
resourceLocator: ResourceLocator
278279
) {
@@ -283,7 +284,8 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
283284
pipeline.getRepository(dvcRoot),
284285
resourceLocator,
285286
this.workspaceState,
286-
(branchesSelected: string[]) => this.selectBranches(branchesSelected)
287+
(branchesSelected: string[]) => this.selectBranches(branchesSelected),
288+
subProjects
287289
)
288290
)
289291

extension/src/extension.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,26 @@ class Extension extends Disposable {
277277
public async initialize() {
278278
this.resetMembers()
279279

280+
const subProjects = this.getSubProjects()
281+
const dvcRoots = this.getRoots()
282+
280283
await Promise.all([
281-
this.repositories.create(this.getRoots()),
282-
this.repositoriesTree.initialize(this.getRoots()),
283-
this.pipelines.create(this.getRoots())
284+
this.repositories.create(dvcRoots, subProjects),
285+
this.repositoriesTree.initialize(dvcRoots),
286+
this.pipelines.create(dvcRoots, subProjects)
284287
])
285288
this.experiments.create(
286-
this.getRoots(),
289+
dvcRoots,
290+
subProjects,
287291
this.pipelines,
288292
this.resourceLocator
289293
)
290-
this.plots.create(this.getRoots(), this.resourceLocator, this.experiments)
294+
this.plots.create(
295+
dvcRoots,
296+
subProjects,
297+
this.resourceLocator,
298+
this.experiments
299+
)
291300

292301
return Promise.all([
293302
this.experiments.isReady(),
@@ -308,6 +317,10 @@ class Extension extends Disposable {
308317
private getRoots() {
309318
return this.setup.getRoots()
310319
}
320+
321+
private getSubProjects() {
322+
return this.setup.getSubProjects()
323+
}
311324
}
312325

313326
let extension: undefined | Extension

extension/src/fileSystem/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ export const isSameOrChild = (root: string, path: string) => {
126126
return !rel.startsWith('..')
127127
}
128128

129+
export const isFileInSubProject = (
130+
file: string,
131+
subProjects: string[]
132+
): boolean => subProjects.some(dvcRoot => file.startsWith(dvcRoot))
133+
129134
export type Out =
130135
| string
131136
| Record<string, { checkpoint?: boolean; cache?: boolean }>

extension/src/pipeline/context.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { EventEmitter, window } from 'vscode'
33
import { Disposable, Disposer } from '@hediet/std/disposable'
44
import { ContextKey, setContextValue } from '../vscode/context'
55
import { standardizePossiblePath } from '../fileSystem/path'
6+
import { isFileInSubProject } from '../fileSystem'
67

78
const setContextOnDidChangeActiveEditor = (
89
setActiveEditorContext: (path: string) => void,
9-
dvcRoot: string
10+
dvcRoot: string,
11+
subProjects: string[]
1012
): Disposable =>
1113
window.onDidChangeActiveTextEditor(event => {
1214
const path = standardizePossiblePath(event?.document.fileName)
@@ -15,7 +17,7 @@ const setContextOnDidChangeActiveEditor = (
1517
return
1618
}
1719

18-
if (!path.includes(dvcRoot)) {
20+
if (!path.includes(dvcRoot) || isFileInSubProject(path, subProjects)) {
1921
return
2022
}
2123

@@ -25,7 +27,8 @@ const setContextOnDidChangeActiveEditor = (
2527
export const setContextForEditorTitleIcons = (
2628
dvcRoot: string,
2729
disposer: (() => void) & Disposer,
28-
pipelineFileFocused: EventEmitter<string | undefined>
30+
pipelineFileFocused: EventEmitter<string | undefined>,
31+
subProjects: string[]
2932
): void => {
3033
const setActiveEditorContext = (path: string) => {
3134
const pipeline = path.endsWith('dvc.yaml') ? dirname(path) : undefined
@@ -34,11 +37,18 @@ export const setContextForEditorTitleIcons = (
3437
}
3538

3639
const activePath = window.activeTextEditor?.document?.fileName
37-
if (activePath?.startsWith(dvcRoot)) {
40+
if (
41+
activePath?.startsWith(dvcRoot) &&
42+
!isFileInSubProject(activePath, subProjects)
43+
) {
3844
setActiveEditorContext(activePath)
3945
}
4046

4147
disposer.track(
42-
setContextOnDidChangeActiveEditor(setActiveEditorContext, dvcRoot)
48+
setContextOnDidChangeActiveEditor(
49+
setActiveEditorContext,
50+
dvcRoot,
51+
subProjects
52+
)
4353
)
4454
}

extension/src/pipeline/data.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,28 @@ import { dirname } from 'path'
22
import { AvailableCommands, InternalCommands } from '../commands/internal'
33
import { BaseData } from '../data'
44
import { findFiles } from '../fileSystem/workspace'
5+
import { isFileInSubProject } from '../fileSystem'
56

67
export class PipelineData extends BaseData<{
78
dag: string
89
stages: { [pipeline: string]: string | undefined }
910
}> {
10-
constructor(dvcRoot: string, internalCommands: InternalCommands) {
11+
private readonly subProjects: string[]
12+
13+
constructor(
14+
dvcRoot: string,
15+
internalCommands: InternalCommands,
16+
subProjects: string[]
17+
) {
1118
super(
1219
dvcRoot,
1320
internalCommands,
1421
[{ name: 'update', process: () => this.update() }],
22+
subProjects,
1523
['dvc.yaml']
1624
)
25+
26+
this.subProjects = subProjects
1727
}
1828

1929
public managedUpdate() {
@@ -28,7 +38,10 @@ export class PipelineData extends BaseData<{
2838

2939
const dvcYamlsDirs = new Set<string>()
3040
for (const file of fileList) {
31-
if (file.startsWith(this.dvcRoot)) {
41+
if (
42+
file.startsWith(this.dvcRoot) &&
43+
!isFileInSubProject(file, this.subProjects)
44+
) {
3245
dvcYamlsDirs.add(dirname(file))
3346
}
3447
}

extension/src/pipeline/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ export class Pipeline extends DeferredDisposable {
5353
constructor(
5454
dvcRoot: string,
5555
internalCommands: InternalCommands,
56+
subProjects: string[],
5657
data?: PipelineData
5758
) {
5859
super()
5960
this.dvcRoot = dvcRoot
6061
this.data = this.dispose.track(
61-
data || new PipelineData(dvcRoot, internalCommands)
62+
data || new PipelineData(dvcRoot, internalCommands, subProjects)
6263
)
6364
this.model = this.dispose.track(new PipelineModel())
6465
this.updated = this.dispose.track(new EventEmitter<void>())
@@ -67,7 +68,7 @@ export class Pipeline extends DeferredDisposable {
6768
this.onDidFocusProject = this.projectFocused.event
6869

6970
void this.initialize()
70-
this.watchActiveEditor()
71+
this.watchActiveEditor(subProjects)
7172
}
7273

7374
public hasPipeline() {
@@ -218,11 +219,12 @@ export class Pipeline extends DeferredDisposable {
218219
return this.focusedPipeline
219220
}
220221

221-
private watchActiveEditor() {
222+
private watchActiveEditor(subProjects: string[]) {
222223
setContextForEditorTitleIcons(
223224
this.dvcRoot,
224225
this.dispose,
225-
this.pipelineFileFocused
226+
this.pipelineFileFocused,
227+
subProjects
226228
)
227229

228230
this.dispose.track(

0 commit comments

Comments
 (0)