|
1 |
| -import { FileSystemWatcher, RelativePattern, Uri, workspace } from "vscode"; |
| 1 | +import { |
| 2 | + FileSystemWatcher, |
| 3 | + RelativePattern, |
| 4 | + Uri, |
| 5 | + workspace, |
| 6 | +} from "vscode"; |
2 | 7 | import { arrayEquals, debounce } from "../../utils";
|
3 | 8 | import { dbtProjectContainer } from "../dbtProjectContainer";
|
4 |
| -import { OnProjectConfigChanged, ProjectConfigChangedEvent } from "../event/projectConfigChangedEvent"; |
| 9 | +import { |
| 10 | + OnProjectConfigChanged, |
| 11 | + ProjectConfigChangedEvent, |
| 12 | +} from "../event/projectConfigChangedEvent"; |
5 | 13 | import { SourceFileChangedEvent } from "../event/sourceFileChangedEvent";
|
6 | 14 |
|
7 | 15 | export class SourceFileWatchers implements OnProjectConfigChanged {
|
8 | 16 | private currentSourcePaths?: string[];
|
9 | 17 | private sourceFolderWatchers: FileSystemWatcher[] = [];
|
10 | 18 |
|
11 |
| - public onProjectConfigChanged(event: ProjectConfigChangedEvent) { |
| 19 | + onProjectConfigChanged(event: ProjectConfigChangedEvent) { |
12 | 20 | const { sourcePaths, projectRoot } = event;
|
13 | 21 | if (
|
14 | 22 | this.currentSourcePaths === undefined ||
|
15 | 23 | !arrayEquals(this.currentSourcePaths, sourcePaths)
|
16 | 24 | ) {
|
17 |
| - sourcePaths.forEach(sourcePath => { |
| 25 | + sourcePaths.forEach((sourcePath) => { |
18 | 26 | const parsedSourcePath = Uri.parse(sourcePath);
|
19 |
| - const globPattern = Uri.joinPath(parsedSourcePath, '**/*.sql').path.substring(1); |
| 27 | + const globPattern = Uri.joinPath( |
| 28 | + parsedSourcePath, |
| 29 | + "**/*.sql" |
| 30 | + ).path.substring(1); |
20 | 31 | const sourceFolderWatcher = workspace.createFileSystemWatcher(
|
21 | 32 | new RelativePattern(projectRoot, globPattern)
|
22 | 33 | );
|
23 | 34 | const event = new SourceFileChangedEvent(projectRoot);
|
24 |
| - sourceFolderWatcher.onDidChange(() => debounce(() => dbtProjectContainer.raiseSourceFileChangedEvent(event), 2000)()); |
| 35 | + |
| 36 | + const debouncedSourceFileChangedEvent = debounce( |
| 37 | + () => dbtProjectContainer.raiseSourceFileChangedEvent(event), |
| 38 | + 2000 |
| 39 | + ); |
| 40 | + |
| 41 | + sourceFolderWatcher.onDidChange(() => |
| 42 | + debouncedSourceFileChangedEvent() |
| 43 | + ); |
25 | 44 | this.sourceFolderWatchers.push(sourceFolderWatcher);
|
26 | 45 | });
|
27 | 46 | this.currentSourcePaths = sourcePaths;
|
28 | 47 | }
|
29 |
| - }; |
| 48 | + } |
30 | 49 | }
|
0 commit comments