@@ -10,6 +10,7 @@ import { saveStreamToFile } from '../outputSaver';
10
10
import { replaceExtension , LANG_TLAPLUS , LANG_TLAPLUS_CFG , listFiles , exists } from '../common' ;
11
11
import { ModelCheckResultSource , ModelCheckResult , SpecFiles } from '../model/check' ;
12
12
import { ToolOutputChannel } from '../outputChannels' ;
13
+ import { Utils } from 'vscode-uri' ;
13
14
14
15
export const CMD_CHECK_MODEL_RUN = 'tlaplus.model.check.run' ;
15
16
export const CMD_CHECK_MODEL_RUN_AGAIN = 'tlaplus.model.check.runAgain' ;
@@ -44,6 +45,19 @@ export async function checkModel(
44
45
if ( ! uri ) {
45
46
return ;
46
47
}
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
+ }
47
61
const specFiles = await getSpecFiles ( uri ) ;
48
62
if ( ! specFiles ) {
49
63
return ;
@@ -218,32 +232,32 @@ function attachFileSaver(tlaFilePath: string, proc: ChildProcess) {
218
232
/**
219
233
* Finds all files that needed to run model check.
220
234
*/
221
- export async function getSpecFiles ( fileUri : vscode . Uri ) : Promise < SpecFiles | undefined > {
235
+ export async function getSpecFiles ( fileUri : vscode . Uri , warn = true ) : Promise < SpecFiles | undefined > {
222
236
const filePath = fileUri . fsPath ;
223
237
let specFiles ;
224
238
let canRun = true ;
225
239
if ( filePath . endsWith ( '.cfg' ) ) {
226
240
specFiles = new SpecFiles ( replaceExtension ( filePath , 'tla' ) , filePath ) ;
227
- canRun = await checkModuleExists ( specFiles . tlaFilePath ) ;
241
+ canRun = await checkModuleExists ( specFiles . tlaFilePath , warn ) ;
228
242
} else if ( filePath . endsWith ( '.tla' ) ) {
229
243
specFiles = new SpecFiles ( filePath , replaceExtension ( filePath , 'cfg' ) ) ;
230
- canRun = await checkModelExists ( specFiles . cfgFilePath ) ;
244
+ canRun = await checkModelExists ( specFiles . cfgFilePath , warn ) ;
231
245
}
232
246
return canRun ? specFiles : undefined ;
233
247
}
234
248
235
- async function checkModuleExists ( modulePath : string ) : Promise < boolean > {
249
+ async function checkModuleExists ( modulePath : string , warn = true ) : Promise < boolean > {
236
250
const moduleExists = await exists ( modulePath ) ;
237
- if ( ! moduleExists ) {
251
+ if ( ! moduleExists && warn ) {
238
252
const moduleFile = path . basename ( modulePath ) ;
239
253
vscode . window . showWarningMessage ( `Corresponding TLA+ module file ${ moduleFile } doesn't exist.` ) ;
240
254
}
241
255
return moduleExists ;
242
256
}
243
257
244
- async function checkModelExists ( cfgPath : string ) : Promise < boolean > {
258
+ async function checkModelExists ( cfgPath : string , warn = true ) : Promise < boolean > {
245
259
const cfgExists = await exists ( cfgPath ) ;
246
- if ( ! cfgExists ) {
260
+ if ( ! cfgExists && warn ) {
247
261
showConfigAbsenceWarning ( cfgPath ) ;
248
262
}
249
263
return cfgExists ;
0 commit comments