CptWesley / vscode-mcrl2

Visual Studio Code Extension for mCRL2
MIT License
1 stars 0 forks source link

Error when parsing mcrl2 file #1

Open keenstoat opened 2 months ago

keenstoat commented 2 months ago

Actual output

When running the example for the vending machine here: https://www.mcrl2.org/web/user_manual/tutorial/machine/index.html#first-variation

act
    ins10, optA, acc10, putA, coin, ready ;
proc
    User = ins10 . optA . User ;
    Mach = acc10 . putA . Mach ;
init
    allow(
        { coin, ready },
        comm(
            { ins10|acc10 -> coin, optA|putA -> ready },
            User || Mach
        ) 
    ) ;

And running the "Parse" action button (also for the mCRL2:Parse command)

Then an error is displayed with the message: Cannot read properties of undefined (reading 'uri')

image

And the developer tools console shows the following error:

notificationsAlerts.ts:40 Error: Cannot read properties of undefined (reading 'uri')
    at h (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:161:210901)
    at h.$executeContributedCommand (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:161:211414)
    at y.S (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:158:5968)
    at y.Q (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:158:5734)
    at y.M (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:158:4767)
    at y.L (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:158:3602)
    at i.value (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:158:2297)
    at r.B (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:732)
    at r.fire (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:949)
    at a.fire (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:115:14463)
    at i.value (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:184:8635)
    at r.B (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:732)
    at r.fire (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:949)
    at a.fire (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:115:14463)
    at h.A (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:115:17622)
    at i.value (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:115:16996)
    at r.B (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:732)
    at r.fire (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:949)
    at m.acceptChunk (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:115:12209)
    at i.value (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:115:11479)
    at r.B (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:732)
    at r.fire (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:90:949)
    at a.z (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:181:21815)
    at a.acceptFrame (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:181:21621)
    at i.n (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:181:20066)
    at /home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:181:16993
    at Socket.b (/home/charles/.vscode-server/bin/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40/out/vs/workbench/api/node/extensionHostProcess.js:181:14623)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:191:23)

Expected output

Parsing the file with the tool shows a successful message: image

Note

The error happens for all commands: parse, show graph, simulate, etc

keenstoat commented 2 months ago

Found what was causing the problem.

In the toProjectPath() function vscode.workspace.workspaceFolders.filter filter returns an empty array:

const dir = vscode.workspace.workspaceFolders
        ? vscode.workspace.workspaceFolders.filter(x => x.name == vscode.workspace.name)[0].uri.fsPath
        : px.dirname(vscode.window.activeTextEditor.document.fileName);

I've solved it locally with the following:

function toProjectPath(pathName='') {
    const wsFolders = vscode.workspace.workspaceFolders ? 
        vscode.workspace.workspaceFolders.filter(x => x.name == vscode.workspace.name) : [];
    const dir = wsFolders.length > 0
        ? wsFolders[0].uri.fsPath
        : px.dirname(vscode.window.activeTextEditor.document.fileName);

    const normalized = px.normalize(dir);
    const trimmed = pathName.trim();

    if (trimmed.length == 0) {
        return normalized;
    }

    return px.join(normalized, trimmed);
}

I'm getting an expected output now image

CptWesley commented 1 month ago

@keenstoat Hi, thank you for reporting this issue. Would you be willing to create a pull request to apply your fix? I will then release a new version of the extension. I will need some time to figure out how to do that again exactly, since it's been a while since I released the original version.