Skip to content

Commit f3b3541

Browse files
committed
Refactor to avoid result match statements
The match statement works well, but makes the code a little hard to read. Refactoring in favor of longer conditional statements makes the code more readable
1 parent b00a712 commit f3b3541

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/commands/checkModel.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,25 @@ export async function checkModel(
4343
): Promise<void> {
4444
const uriResult = fileUri ? ok(fileUri) : getActiveEditorFileUri();
4545

46-
const specFilesResult = await uriResult.match(
47-
async (uri): Promise<Result<SpecFiles, ModelCheckingError>> => {
48-
const files = await getSpecFiles(uri);
49-
if (!files) {
50-
return err(new ModelCheckingError('Could not load spec files.'));
51-
}
52-
return ok(files);
53-
},
54-
// Use last checked spec if no active TLA+ files are found.
55-
async (error: unknown): Promise<Result<SpecFiles, ModelCheckingError>> => lastCheckFiles ?
56-
ok(lastCheckFiles) :
57-
err(new ModelCheckingError(
58-
'No active TLA+ file or previous spec found. Switch to the .tla or .cfg file to check.'
59-
))
60-
);
46+
let specFiles;
6147

62-
if (specFilesResult.isErr()) {
63-
vscode.window.showErrorMessage(specFilesResult.error.message);
64-
return;
48+
if (uriResult.isErr()) {
49+
// Use last checked spec if no active TLA+ files are found.
50+
if (!lastCheckFiles) {
51+
vscode.window.showErrorMessage(
52+
'No active TLA+ file or previous spec found. Switch to the .tla or .cfg file to check.');
53+
return;
54+
}
55+
specFiles = lastCheckFiles;
56+
} else {
57+
specFiles = await getSpecFiles(uriResult.value);
58+
if (!specFiles) {
59+
vscode.window.showErrorMessage('Could not load spec files.');
60+
return;
61+
}
6562
}
6663

67-
doCheckModel(specFilesResult.value, true, extContext, diagnostic, true);
64+
doCheckModel(specFiles, true, extContext, diagnostic, true);
6865
}
6966

7067
export async function runLastCheckAgain(

0 commit comments

Comments
 (0)