Skip to content

Commit c189a62

Browse files
JoshwinThomasIBMJoshwinThomasIBM
authored andcommitted
code formatted
1 parent d10dfeb commit c189a62

File tree

2 files changed

+88
-88
lines changed

2 files changed

+88
-88
lines changed

src/extension.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -185,49 +185,49 @@ export function deactivate(): Promise<void[]> {
185185
*/
186186
export function registerFileWatcher(projectProvider: ProjectProvider): void {
187187
const watcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("{**/pom.xml,**/build.gradle,**/settings.gradle,**/src/main/liberty/config/server.xml}");
188-
// Async handler for the file system events (create, change, delete)
189-
const handleUri = async (uri: vscode.Uri) => {
190-
const workspaceFolders = vscode.workspace.workspaceFolders;
191-
192-
if (!workspaceFolders) {
193-
return; // No workspace folders to process
188+
// Async handler for the file system events (create, change, delete)
189+
const handleUri = async (uri: vscode.Uri) => {
190+
const workspaceFolders = vscode.workspace.workspaceFolders;
191+
192+
if (!workspaceFolders) {
193+
return; // No workspace folders to process
194+
}
195+
196+
// Loop through all workspace folders
197+
for (let folder of workspaceFolders) {
198+
const projectRoot = folder.uri.fsPath;
199+
const relativePath = path.relative(projectRoot, uri.fsPath);
200+
201+
// Ensure that the file belongs to this project (starts with the projectRoot path)
202+
if (!uri.fsPath.startsWith(projectRoot)) {
203+
continue; // Skip if the file is outside the current project folder
194204
}
195-
196-
// Loop through all workspace folders
197-
for (let folder of workspaceFolders) {
198-
const projectRoot = folder.uri.fsPath;
199-
const relativePath = path.relative(projectRoot, uri.fsPath);
200-
201-
// Ensure that the file belongs to this project (starts with the projectRoot path)
202-
if (!uri.fsPath.startsWith(projectRoot)) {
203-
continue; // Skip if the file is outside the current project folder
204-
}
205-
206-
// Check if the path includes 'target' or 'build' directly under the project root
207-
if (/(target\/|build\/)/.test(relativePath)) {
208-
209-
const fileType = path.basename(uri.fsPath);
210-
const siblingFileExists = await helperUtil.checkSiblingFilesInTargetOrBuildParent(uri.fsPath);
211-
if(!siblingFileExists){
212-
console.log(`No sibling ${fileType} found, refreshing project... for ` + uri.fsPath);
213-
// Refresh the project if no sibling file is found
214-
await projectProvider.refresh();
215-
}else{
216-
console.log(`Skipping refresh: Sibling ${fileType} found for `+uri.fsPath);
217-
return; // Do not refresh
218-
}
219-
} else {
220-
// If the file generated is **outside** the `target` directory, always refresh
221-
console.log('Refreshing project...');
205+
206+
// Check if the path includes 'target' or 'build' directly under the project root
207+
if (/(target\/|build\/)/.test(relativePath)) {
208+
209+
const fileType = path.basename(uri.fsPath);
210+
const siblingFileExists = await helperUtil.checkSiblingFilesInTargetOrBuildParent(uri.fsPath);
211+
if (!siblingFileExists) {
212+
console.log(`No sibling ${fileType} found, refreshing project... for ` + uri.fsPath);
213+
// Refresh the project if no sibling file is found
222214
await projectProvider.refresh();
215+
} else {
216+
console.log(`Skipping refresh: Sibling ${fileType} found for ` + uri.fsPath);
217+
return; // Do not refresh
223218
}
224-
}
225-
};
226-
227-
228-
watcher.onDidCreate(handleUri);
229-
watcher.onDidChange(handleUri);
230-
watcher.onDidDelete(handleUri);
219+
} else {
220+
// If the file generated is **outside** the `target` directory, always refresh
221+
console.log('Refreshing project...');
222+
await projectProvider.refresh();
223+
}
224+
}
225+
};
226+
227+
228+
watcher.onDidCreate(handleUri);
229+
watcher.onDidChange(handleUri);
230+
watcher.onDidDelete(handleUri);
231231
}
232232

233233
function startLangServer(context: ExtensionContext, requirements: RequirementsData, isLiberty: boolean) {

src/util/helperUtil.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -88,53 +88,53 @@ export function clearDataSavedInGlobalState(context: vscode.ExtensionContext) {
8888
*/
8989
export async function checkSiblingFilesInTargetOrBuildParent(filePath: string): Promise<boolean> {
9090

91-
try {
92-
let currentDir = path.dirname(filePath); // Start with the directory of the provided file
93-
94-
// Traverse upwards through the directories
95-
while (currentDir !== path.parse(currentDir).root) {
96-
let targetDir: string | undefined;
97-
let siblingFilePath: string | undefined;
98-
99-
// Determine the file type to look for (either pom.xml or build.gradle)
100-
if (filePath.endsWith('pom.xml')) {
101-
targetDir = 'target'; // For Maven projects, look for target directory
102-
siblingFilePath = path.join(currentDir, targetDir, 'pom.xml');
103-
} else if (filePath.endsWith('build.gradle') || filePath.endsWith('settings.gradle')) {
104-
targetDir = 'build'; // For Gradle projects, look for build directory
105-
siblingFilePath = path.join(currentDir, targetDir, 'build.gradle');
106-
} else {
107-
console.log("Invalid file type. Only 'pom.xml' or 'build.gradle' are supported.");
108-
return false;
109-
}
110-
111-
// Ensure that targetDir and siblingFilePath are assigned before proceeding
112-
if (!targetDir || !siblingFilePath) {
113-
console.error("Error: targetDir or siblingFilePath not properly assigned.");
114-
return false;
115-
}
116-
117-
// Check if the target/build directory exists
118-
const currentTargetDir = path.join(currentDir, targetDir);
119-
if (fs.existsSync(currentTargetDir) && fs.statSync(currentTargetDir).isDirectory()) {
120-
121-
// Check if the expected sibling file (pom.xml or build.gradle) exists
122-
if (fs.existsSync(siblingFilePath) && fs.statSync(siblingFilePath).isFile()) {
123-
console.log(`Found sibling ${filePath.endsWith('pom.xml') ? 'pom.xml' : 'build.gradle'} in directory: ${currentTargetDir}`);
124-
return true; // Found the sibling file, return true to indicate file should be ignored
125-
}
126-
}
127-
128-
// Move up to the parent directory
129-
currentDir = path.dirname(currentDir);
130-
}
131-
132-
// If no sibling file was found and we reached the root, return false to allow refresh
133-
console.log("Reached project root, no sibling file found. Allowing refresh.");
134-
return false;
135-
} catch (err) {
136-
console.error('Error during directory traversal:', err);
137-
return false;
138-
}
91+
try {
92+
let currentDir = path.dirname(filePath); // Start with the directory of the provided file
93+
94+
// Traverse upwards through the directories
95+
while (currentDir !== path.parse(currentDir).root) {
96+
let targetDir: string | undefined;
97+
let siblingFilePath: string | undefined;
98+
99+
// Determine the file type to look for (either pom.xml or build.gradle)
100+
if (filePath.endsWith('pom.xml')) {
101+
targetDir = 'target'; // For Maven projects, look for target directory
102+
siblingFilePath = path.join(currentDir, targetDir, 'pom.xml');
103+
} else if (filePath.endsWith('build.gradle') || filePath.endsWith('settings.gradle')) {
104+
targetDir = 'build'; // For Gradle projects, look for build directory
105+
siblingFilePath = path.join(currentDir, targetDir, 'build.gradle');
106+
} else {
107+
console.log("Invalid file type. Only 'pom.xml' or 'build.gradle' are supported.");
108+
return false;
109+
}
110+
111+
// Ensure that targetDir and siblingFilePath are assigned before proceeding
112+
if (!targetDir || !siblingFilePath) {
113+
console.error("Error: targetDir or siblingFilePath not properly assigned.");
114+
return false;
115+
}
116+
117+
// Check if the target/build directory exists
118+
const currentTargetDir = path.join(currentDir, targetDir);
119+
if (fs.existsSync(currentTargetDir) && fs.statSync(currentTargetDir).isDirectory()) {
120+
121+
// Check if the expected sibling file (pom.xml or build.gradle) exists
122+
if (fs.existsSync(siblingFilePath) && fs.statSync(siblingFilePath).isFile()) {
123+
console.log(`Found sibling ${filePath.endsWith('pom.xml') ? 'pom.xml' : 'build.gradle'} in directory: ${currentTargetDir}`);
124+
return true; // Found the sibling file, return true to indicate file should be ignored
125+
}
126+
}
127+
128+
// Move up to the parent directory
129+
currentDir = path.dirname(currentDir);
130+
}
131+
132+
// If no sibling file was found and we reached the root, return false to allow refresh
133+
console.log("Reached project root, no sibling file found. Allowing refresh.");
134+
return false;
135+
} catch (err) {
136+
console.error('Error during directory traversal:', err);
137+
return false;
138+
}
139139
}
140140

0 commit comments

Comments
 (0)