Skip to content

Commit a173e82

Browse files
author
Arvid Paeglit
committed
refactored file watcher: activate it only once filters are loaded from Deepcode server
1 parent a969294 commit a173e82

5 files changed

Lines changed: 18 additions & 28 deletions

File tree

src/deepcode/constants/filesConstants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ export const FILE_CURRENT_STATUS = {
1717
same: "same",
1818
created: "created"
1919
};
20-
21-
export const SUPPORTED_WATCH_FILES = ['*.jsx', '*.es6', '*.vue', '*.hpp', '*.html', '*.htm', '*.tsx', '*.cxx', '*.es', '*.ts', '*.c', '*.cc', '*.hxx', '*.py', '*.java', '*.h', '*.cpp', '*.js', '.pylintrc', 'tslint.json', '.eslintrc.yml', '.pmdrc.xml', '.ruleset.xml', '.eslintrc.js', '.eslintrc.json', 'ruleset.xml', 'pylintrc'];

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import DeepCode from "../../../interfaces/DeepCodeInterfaces";
44
import { IQueueAnalysisCheckResult } from "@deepcode/tsc";
55
import { window, ProgressLocation, Progress } from "vscode";
66
import { deepCodeMessages } from "../../messages/deepCodeMessages";
7-
import { processServerFilesFilterList } from "../../utils/filesUtils";
87
import { checkIfBundleIsEmpty } from "../../utils/bundlesUtils";
98
import { startFilesUpload } from "../../utils/packageUtils";
109
import { BUNDLE_EVENTS } from "../../constants/events";
@@ -122,14 +121,13 @@ class BundlesModule extends LoginModule
122121

123122
// procesing filter list of files, acceptable for server
124123
public async createFilesFilterList(): Promise<void> {
125-
const { extensions, configFiles } = await http.getFilters(this.baseURL, this.token);
126-
const processedFilters = processServerFilesFilterList({ extensions, configFiles });
127-
this.serverFilesFilterList = { ...processedFilters };
124+
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
128125
}
129126

130127
public async performBundlesActions(path: string): Promise<void> {
131128
if (!Object.keys(this.serverFilesFilterList).length) {
132129
await this.createFilesFilterList();
130+
this.filesWatcher.activate(this);
133131

134132
if (!Object.keys(this.serverFilesFilterList).length) {
135133
return;

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import BundlesModule from "./BundlesModule";
66
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
77

88
public activateAll(): void {
9-
this.filesWatcher.activate(this);
9+
// this.filesWatcher.activate(this);
1010
this.workspacesWatcher.activate(this);
1111
this.editorsWatcher.activate(this);
1212
this.settingsWatcher.activate(this);

src/deepcode/lib/watchers/DeepCodeFilesWatcher.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,21 @@ import * as vscode from "vscode";
22
import { compareFileChanges, acceptFileToBundle, isFileChangingBundle } from "../../utils/filesUtils";
33
import {
44
FILE_CURRENT_STATUS,
5-
GIT_FILENAME,
6-
SUPPORTED_WATCH_FILES
5+
GIT_FILENAME
76
} from "../../constants/filesConstants";
87
import { errorsLogs } from "../../messages/errorsServerLogMessages";
98
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
109

1110
class DeepCodeFilesWatcher implements DeepCode.DeepCodeWatcherInterface {
1211
private changedFilesList: Array<string> = [];
13-
private watcher: vscode.FileSystemWatcher;
12+
private watcher: vscode.FileSystemWatcher | null = null;
1413
private FILES_TO_SAVE_LIST_FIRST_ELEMENT: number = 1;
1514
private filesForUpdatingServerBundle: {
1615
[key: string]: Array<{
1716
[key: string]: string;
1817
}>
1918
} = {};
2019

21-
constructor() {
22-
const globPattern: vscode.GlobPattern = `**/\{${SUPPORTED_WATCH_FILES.join(',')}\}`;
23-
this.watcher = vscode.workspace.createFileSystemWatcher(globPattern);
24-
}
25-
2620
private emptyChangedFilesLists(): void {
2721
// clear files lists
2822
this.changedFilesList.length = 0;
@@ -185,6 +179,19 @@ class DeepCodeFilesWatcher implements DeepCode.DeepCodeWatcherInterface {
185179
}
186180

187181
public activate(extension: DeepCode.ExtensionInterface): void {
182+
if (!Object.keys(extension.serverFilesFilterList).length) {
183+
console.error('Empty watch list');
184+
return;
185+
}
186+
187+
const watchFiles = [
188+
...(extension.serverFilesFilterList.extensions || []).map(e => `*${e}`),
189+
...(extension.serverFilesFilterList.configFiles || [])
190+
];
191+
192+
const globPattern: vscode.GlobPattern = `**/\{${watchFiles.join(',')}\}`;
193+
this.watcher = vscode.workspace.createFileSystemWatcher(globPattern);
194+
188195
const { created, modified, deleted } = FILE_CURRENT_STATUS;
189196
this.watcher.onDidChange((documentUri: vscode.Uri) => {
190197
this.filesChangesHandler(documentUri.fsPath, extension, modified);

src/deepcode/utils/filesUtils.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,6 @@ export const compareFileChanges = async (
125125
return response;
126126
};
127127

128-
export const processServerFilesFilterList = (
129-
filterList: DeepCode.AllowedServerFilterListInterface
130-
): DeepCode.AllowedServerFilterListInterface => {
131-
const { configFiles } = filterList;
132-
if (configFiles) {
133-
const processedConfigFiles = configFiles.map((item: string) =>
134-
item.slice(1)
135-
);
136-
return { ...filterList, configFiles: processedConfigFiles };
137-
}
138-
return filterList;
139-
};
140-
141128
export const processPayloadSize = (
142129
payload: Array<DeepCode.PayloadMissingFileInterface>
143130
): {

0 commit comments

Comments
 (0)