Skip to content

Commit d1ddb18

Browse files
committed
Refactor code for consistency and readability in extension.ts
- Added braces for clarity in conditional statements. - Removed unnecessary blank lines to improve code cleanliness. - Ensured consistent formatting across various functions for better maintainability.
1 parent fe2def2 commit d1ddb18

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

vscode-rescriptdep/src/extension.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function activate(context: vscode.ExtensionContext) {
3030
// Helper function to get current module name from active editor
3131
function getCurrentModuleNameFromActiveEditor(): string | undefined {
3232
const editor = vscode.window.activeTextEditor;
33-
if (!editor) return undefined;
33+
if (!editor) { return undefined; }
3434

3535
const document = editor.document;
3636
const fileName = document.fileName;
@@ -106,7 +106,6 @@ async function findProjectRootForFile(filePath: string, workspaceRoot: string):
106106
return workspaceRoot;
107107
}
108108

109-
110109
// Return undefined if no config file found up to the workspace root
111110
return undefined;
112111
}
@@ -182,7 +181,7 @@ async function generateDependencyGraph(context: vscode.ExtensionContext, focusOn
182181
if (focusOnModule) {
183182
// --- Logic when focusing on a specific module ---
184183
progress.report({ message: 'Getting module information...' });
185-
if (token.isCancellationRequested) return;
184+
if (token.isCancellationRequested) { return; }
186185

187186
// Get module name (from editor or input)
188187
moduleName = getCurrentModuleNameFromActiveEditor();
@@ -192,7 +191,7 @@ async function generateDependencyGraph(context: vscode.ExtensionContext, focusOn
192191
placeHolder: 'ModuleName'
193192
});
194193
}
195-
if (!moduleName) return; // User cancelled
194+
if (!moduleName) { return; } // User cancelled
196195

197196
// Find the source file for the target module
198197
progress.report({ message: `Finding source file for ${moduleName}...` });
@@ -234,7 +233,7 @@ async function generateDependencyGraph(context: vscode.ExtensionContext, focusOn
234233
progress.report({ message: 'Finding ReScript config file...' });
235234
const initialConfigFileUri = await findConfigFile(workspaceRoot);
236235

237-
if (token.isCancellationRequested) return;
236+
if (token.isCancellationRequested) { return; }
238237

239238
// If no config file is found anywhere, exit (should be caught by activationEvents)
240239
if (!initialConfigFileUri) {
@@ -261,12 +260,12 @@ async function generateDependencyGraph(context: vscode.ExtensionContext, focusOn
261260

262261
// Find CLI path
263262
progress.report({ message: 'Finding CLI path...' });
264-
if (token.isCancellationRequested) return;
263+
if (token.isCancellationRequested) { return; }
265264
const cliPath = await findRescriptDepCLI(context);
266265

267266
// Run the CLI command with the determined bsDir and moduleName (if applicable)
268267
progress.report({ message: 'Running rescriptdep CLI...' });
269-
if (token.isCancellationRequested) return;
268+
if (token.isCancellationRequested) { return; }
270269

271270
// Define CLI arguments
272271
const args: string[] = ['--format=json'];
@@ -284,7 +283,7 @@ async function generateDependencyGraph(context: vscode.ExtensionContext, focusOn
284283

285284
// Display webview
286285
progress.report({ message: 'Generating visualization...' });
287-
if (token.isCancellationRequested) return;
286+
if (token.isCancellationRequested) { return; }
288287

289288
if (jsonContent) {
290289
showGraphWebview(context, jsonContent, focusOnModule, moduleName);
@@ -1222,7 +1221,7 @@ function showGraphWebview(context: vscode.ExtensionContext, jsonContent: string,
12221221
// Get JSON format data
12231222
const jsonContent = await runRescriptDep(cliPath, args, context);
12241223

1225-
if (token.isCancellationRequested) return;
1224+
if (token.isCancellationRequested) { return; }
12261225

12271226
if (jsonContent && currentPanel) { // Check panel existence again
12281227
// Parse data to update title correctly
@@ -1276,7 +1275,7 @@ function getWebviewUri(webview: vscode.Webview, extensionUri: vscode.Uri, ...pat
12761275
// Helper function to try to find the module in the project when file path is unavailable
12771276
async function findModuleInProject(moduleName: string): Promise<{ path: string, line: number } | null> {
12781277
const workspaceFolders = vscode.workspace.workspaceFolders;
1279-
if (!workspaceFolders) return null;
1278+
if (!workspaceFolders) { return null; }
12801279

12811280
// File extensions and directory list
12821281
const extensions = ['.res', '.resi', '.re', '.rei', '.ml', '.mli']; // Common ReScript/OCaml extensions
@@ -1307,7 +1306,7 @@ async function findModuleInProject(moduleName: string): Promise<{ path: string,
13071306

13081307
for (const ext of preferredOrder) {
13091308
bestMatch = files.find(f => f.fsPath.endsWith(`${moduleName}${ext}`));
1310-
if (bestMatch) break;
1309+
if (bestMatch) { break; }
13111310
}
13121311
// Fallback to the first file found if no preferred extension matches
13131312
const targetFile = bestMatch || files[0];

0 commit comments

Comments
 (0)