|
1 | 1 | import { Event, EventEmitter, ViewColumn, commands } from 'vscode' |
| 2 | +import { Disposable, Disposer } from '@hediet/std/disposable' |
2 | 3 | import isEmpty from 'lodash.isempty' |
3 | 4 | import { SetupData as TSetupData } from './webview/contract' |
4 | 5 | import { WebviewMessages } from './webview/messages' |
@@ -35,9 +36,14 @@ import { WorkspaceExperiments } from '../experiments/workspace' |
35 | 36 | import { DvcRunner } from '../cli/dvc/runner' |
36 | 37 | import { sendTelemetryEvent, sendTelemetryEventAndThrow } from '../telemetry' |
37 | 38 | import { StopWatch } from '../util/time' |
38 | | -import { createFileSystemWatcher } from '../fileSystem/watcher' |
| 39 | +import { |
| 40 | + createFileSystemWatcher, |
| 41 | + getRelativePattern |
| 42 | +} from '../fileSystem/watcher' |
39 | 43 | import { EventName } from '../telemetry/constants' |
40 | 44 | import { WorkspaceScale } from '../telemetry/collect' |
| 45 | +import { gitPath } from '../cli/git/constants' |
| 46 | +import { DOT_DVC } from '../cli/dvc/constants' |
41 | 47 |
|
42 | 48 | export type SetupWebviewWebview = BaseWebview<TSetupData> |
43 | 49 |
|
@@ -74,6 +80,8 @@ export class Setup |
74 | 80 | private cliAccessible = false |
75 | 81 | private cliCompatible: boolean | undefined |
76 | 82 |
|
| 83 | + private dotFolderWatcher?: Disposer |
| 84 | + |
77 | 85 | constructor( |
78 | 86 | stopWatch: StopWatch, |
79 | 87 | config: Config, |
@@ -143,6 +151,7 @@ export class Setup |
143 | 151 | ) |
144 | 152 | this.watchForVenvChanges() |
145 | 153 | this.watchExecutionDetailsForChanges() |
| 154 | + this.watchDotFolderForChanges() |
146 | 155 | this.watchPathForChanges(stopWatch) |
147 | 156 | } |
148 | 157 |
|
@@ -280,13 +289,16 @@ export class Setup |
280 | 289 | private setProjectAvailability() { |
281 | 290 | const available = this.hasRoots() |
282 | 291 | setContextValue('dvc.project.available', available) |
| 292 | + if (available && this.dotFolderWatcher && !this.dotFolderWatcher.disposed) { |
| 293 | + this.dispose.untrack(this.dotFolderWatcher) |
| 294 | + this.dotFolderWatcher.dispose() |
| 295 | + } |
283 | 296 | } |
284 | 297 |
|
285 | 298 | private async initializeDvc() { |
286 | 299 | const root = getFirstWorkspaceFolder() |
287 | 300 | if (root) { |
288 | 301 | await this.dvcExecutor.init(root) |
289 | | - this.workspaceChanged.fire() |
290 | 302 | } |
291 | 303 | } |
292 | 304 |
|
@@ -324,7 +336,6 @@ export class Setup |
324 | 336 | const cwd = getFirstWorkspaceFolder() |
325 | 337 | if (cwd) { |
326 | 338 | this.gitExecutor.init(cwd) |
327 | | - this.workspaceChanged.fire() |
328 | 339 | } |
329 | 340 | } |
330 | 341 |
|
@@ -449,12 +460,46 @@ export class Setup |
449 | 460 | previousPythonBinPath !== this.config.getPythonBinPath() |
450 | 461 |
|
451 | 462 | if (!this.cliAccessible || !this.cliCompatible || trySetupWithVenv) { |
452 | | - run(this) |
| 463 | + this.workspaceChanged.fire() |
453 | 464 | } |
454 | 465 | } |
455 | 466 | ) |
456 | 467 | } |
457 | 468 |
|
| 469 | + private watchDotFolderForChanges() { |
| 470 | + const cwd = getFirstWorkspaceFolder() |
| 471 | + |
| 472 | + if (!cwd) { |
| 473 | + return |
| 474 | + } |
| 475 | + |
| 476 | + const disposer = Disposable.fn() |
| 477 | + this.dotFolderWatcher = disposer |
| 478 | + this.dispose.track(this.dotFolderWatcher) |
| 479 | + |
| 480 | + return createFileSystemWatcher( |
| 481 | + disposable => disposer.track(disposable), |
| 482 | + getRelativePattern(cwd, '**'), |
| 483 | + path => this.dotFolderListener(disposer, path) |
| 484 | + ) |
| 485 | + } |
| 486 | + |
| 487 | + private dotFolderListener(disposer: Disposer, path: string) { |
| 488 | + if ( |
| 489 | + !(path && (path.endsWith(gitPath.DOT_GIT) || path.includes(DOT_DVC))) || |
| 490 | + disposer.disposed |
| 491 | + ) { |
| 492 | + return |
| 493 | + } |
| 494 | + |
| 495 | + if (path.includes(DOT_DVC)) { |
| 496 | + this.dispose.untrack(disposer) |
| 497 | + disposer.dispose() |
| 498 | + } |
| 499 | + |
| 500 | + return this.workspaceChanged.fire() |
| 501 | + } |
| 502 | + |
458 | 503 | private async getEventProperties() { |
459 | 504 | return { |
460 | 505 | ...(this.cliAccessible ? await this.collectWorkspaceScale() : {}), |
|
0 commit comments