Skip to content

Commit 0304d3a

Browse files
committed
Try loading a spec/cfg with the MC prefix before loading the
file matching the current editor Essentially, this introduce the convention that TLC-related modules and config files are prefixed with 'MC'.
1 parent b0dc91f commit 0304d3a

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

package-lock.json

+34-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@
402402
"dependencies": {
403403
"await-notify": "^1.0.1",
404404
"moment": "^2.24.0",
405+
"vscode-uri": "^3.0.2",
405406
"vscode-debugadapter": "^1.42.1"
406407
}
407408
}

src/commands/checkModel.ts

+21-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { saveStreamToFile } from '../outputSaver';
1010
import { replaceExtension, LANG_TLAPLUS, LANG_TLAPLUS_CFG, listFiles, exists } from '../common';
1111
import { ModelCheckResultSource, ModelCheckResult, SpecFiles } from '../model/check';
1212
import { ToolOutputChannel } from '../outputChannels';
13+
import { Utils } from 'vscode-uri';
1314

1415
export const CMD_CHECK_MODEL_RUN = 'tlaplus.model.check.run';
1516
export const CMD_CHECK_MODEL_RUN_AGAIN = 'tlaplus.model.check.runAgain';
@@ -44,6 +45,19 @@ export async function checkModel(
4445
if (!uri) {
4546
return;
4647
}
48+
49+
// Unless the given filePath already starts with 'MC', prepend MC to the name
50+
// and check if it exists. If yes, it becomes the spec file. If not, fall back
51+
// to the original file.
52+
const b = Utils.basename(uri);
53+
if (!b.startsWith('MC')) {
54+
const n = uri.toString().replace(b.toString(), 'MC' + b);
55+
const specFiles = await getSpecFiles(vscode.Uri.parse(n), false);
56+
if (specFiles) {
57+
doCheckModel(specFiles, true, extContext, diagnostic, true);
58+
return;
59+
}
60+
}
4761
const specFiles = await getSpecFiles(uri);
4862
if (!specFiles) {
4963
return;
@@ -218,32 +232,32 @@ function attachFileSaver(tlaFilePath: string, proc: ChildProcess) {
218232
/**
219233
* Finds all files that needed to run model check.
220234
*/
221-
export async function getSpecFiles(fileUri: vscode.Uri): Promise<SpecFiles | undefined> {
235+
export async function getSpecFiles(fileUri: vscode.Uri, warn = true): Promise<SpecFiles | undefined> {
222236
const filePath = fileUri.fsPath;
223237
let specFiles;
224238
let canRun = true;
225239
if (filePath.endsWith('.cfg')) {
226240
specFiles = new SpecFiles(replaceExtension(filePath, 'tla'), filePath);
227-
canRun = await checkModuleExists(specFiles.tlaFilePath);
241+
canRun = await checkModuleExists(specFiles.tlaFilePath, warn);
228242
} else if (filePath.endsWith('.tla')) {
229243
specFiles = new SpecFiles(filePath, replaceExtension(filePath, 'cfg'));
230-
canRun = await checkModelExists(specFiles.cfgFilePath);
244+
canRun = await checkModelExists(specFiles.cfgFilePath, warn);
231245
}
232246
return canRun ? specFiles : undefined;
233247
}
234248

235-
async function checkModuleExists(modulePath: string): Promise<boolean> {
249+
async function checkModuleExists(modulePath: string, warn = true): Promise<boolean> {
236250
const moduleExists = await exists(modulePath);
237-
if (!moduleExists) {
251+
if (!moduleExists && warn) {
238252
const moduleFile = path.basename(modulePath);
239253
vscode.window.showWarningMessage(`Corresponding TLA+ module file ${moduleFile} doesn't exist.`);
240254
}
241255
return moduleExists;
242256
}
243257

244-
async function checkModelExists(cfgPath: string): Promise<boolean> {
258+
async function checkModelExists(cfgPath: string, warn = true): Promise<boolean> {
245259
const cfgExists = await exists(cfgPath);
246-
if (!cfgExists) {
260+
if (!cfgExists && warn) {
247261
showConfigAbsenceWarning(cfgPath);
248262
}
249263
return cfgExists;

0 commit comments

Comments
 (0)