bartosz-antosik / vscode-spellright

Multilingual, Offline and Lightweight Spellchecker for Visual Studio Code
Other
359 stars 36 forks source link

Location of the remote workspace/folder dictionary. #566

Open kkm000 opened 7 months ago

kkm000 commented 7 months ago

I'm running VSCode on Windows 11 v10.0.22621.2715, but developing on a remote Linux machine over a devtunnel (Debian 12, x64). The README says:

All the extension's commands add words to two main files, user and workspace dictionaries, both contained in spellright.dict files, one located in user settings folder and the other in workspace settings folder (.vscode). I'm using an implicit, single-folder workspace (i.e, "Open folder", not "Open workspace").

Indeed, when I added an empty spellright.dict file under .vscode/, a new menu option appeared: in addition to "Add XXX to user dictionary", there is also "Add XXX to workspace dictionary". However, when I'm trying to add a word to workspace dictionary, I'm getting an error banner in the lower-right corner of VSCode frame, with the red circled ×: "A system error occurred (ENOENT: no such file or directory, open)".

The Extension Host output logs the following stack trace, twice (I cleared the window before selecting the "add ... to workspace ..." menu item):

2023-11-22 19:20:04.908 [error] Error: ENOENT: no such file or directory, open
    at Object.openSync (node:fs:603:3)
    at Object.func [as openSync] (node:electron/js2c/asar_bundle:2:1869)
    at SpellRight.addWordToDictionary (c:\Users\kkm\.vscode\extensions\ban.spellright-3.0.118\src\spellright.js:1832:29)
    at SpellRight.addWordToWorkspaceDictionary (c:\Users\kkm\.vscode\extensions\ban.spellright-3.0.118\src\spellright.js:1843:22)
    at SpellRight.addToWorkspaceDictionaryCodeAction (c:\Users\kkm\.vscode\extensions\ban.spellright-3.0.118\src\spellright.js:1737:19)
    at i.h (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:139669)
    at i.g (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:138661)
    at i.executeCommand (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:138568)
    at s.h (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:142019)
    at i.h (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:139669)
    at i.$executeContributedCommand (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:140529)
    at n.S (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:10836)
    at n.Q (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:10602)
    at n.M (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:9686)
    at n.L (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:8762)
    at h.value (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:7565)
    at c.y (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:1902)
    at c.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:2119)
    at d.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:14047)
    at h.value (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:153:7918)
    at c.y (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:1902)
    at c.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:2119)
    at d.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:14047)
    at MessagePortMain.<anonymous> (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:153:6198)
    at MessagePortMain.emit (node:events:513:28)
    at MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:367) spellright.addToWorkspaceDictionaryCodeAction {"value":"ban.spellright","_lower":"ban.spellright"}
2023-11-22 19:20:04.908 [error] Error: ENOENT: no such file or directory, open
    at Object.openSync (node:fs:603:3)
    at Object.func [as openSync] (node:electron/js2c/asar_bundle:2:1869)
    at SpellRight.addWordToDictionary (c:\Users\kkm\.vscode\extensions\ban.spellright-3.0.118\src\spellright.js:1832:29)
    at SpellRight.addWordToWorkspaceDictionary (c:\Users\kkm\.vscode\extensions\ban.spellright-3.0.118\src\spellright.js:1843:22)
    at SpellRight.addToWorkspaceDictionaryCodeAction (c:\Users\kkm\.vscode\extensions\ban.spellright-3.0.118\src\spellright.js:1737:19)
    at i.h (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:139669)
    at i.g (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:138661)
    at i.executeCommand (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:138568)
    at s.h (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:142019)
    at i.h (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:139669)
    at i.$executeContributedCommand (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:125:140529)
    at n.S (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:10836)
    at n.Q (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:10602)
    at n.M (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:9686)
    at n.L (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:8762)
    at h.value (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:134:7565)
    at c.y (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:1902)
    at c.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:2119)
    at d.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:14047)
    at h.value (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:153:7918)
    at c.y (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:1902)
    at c.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:2119)
    at d.fire (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:14047)
    at MessagePortMain.<anonymous> (u:\kkm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:153:6198)
    at MessagePortMain.emit (node:events:513:28)
    at MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:367) spellright.addToWorkspaceDictionaryCodeAction undefined

Unfortunately, there is no clue as to what exact file the extension is trying to open.

Adding words to the user dictionary (on the local Windows machine) works just fine.

What surprised me was that the extension is hosted in the local Extension Host. As expected, the "Extension Host (Remote)" output logged nothing. But I don't really understand how extensions work, and whether local extensions have access to remote files. Looks like they do, as adding the workspace empty dictionary resulted in adding a new menu item.

Am I doing anything wrong?


UPDATE:

I rigged the function `addWordToDictionary(word, filename) at line 1830 to log arguments. The filename argument ended up empty.

    SpellRight.prototype.addWordToDictionary = function (word, filename) {
        console.log("addWordToDictionary(", word, filename, ")")
        if (!fs.existsSync(filename)) {
            console.log("addWordToDictionary thinks fs.existsSync(filename) is false")
            fs.closeSync(fs.openSync(filename, 'w'));
        }

        fs.appendFileSync(filename, word + os.EOL);
    }

Output to dev tools console (the word I tried to add was "tf"):

console.ts:137 [Extension Host] addWordToDictionary( tf  )
console.ts:137 [Extension Host] addWordToDictionary thinks fs.existsSync(filename) is false
notificationsAlerts.ts:42 A system error occurred (ENOENT: no such file or directory, open)

Tangentially, os.EOL refers to which os? I think that '\n' works on any os. I long ago set all defaults (VSCode, Visual Studio 2022, Notepad++) on Windows to LF line ending, never saw any issues. But Linux gets very angry at "\r\n".

dzerrenner commented 7 months ago

I'm running into this too. Same setup: VSCode remote ssh and trying to add a word to the workspace dictionary. To me it seems too that the extension is run locally and thus tries to access the linux path on the windows host. It determines the path in https://github.com/bartosz-antosik/vscode-spellright/blob/f843d5d369dc70a363fda5a9b38fcafcd5d0eacc/src/spellright.js#L1973 But I don't know why the path is not correct.

kkm000 commented 7 months ago

@dzerrenner Yeah possibly. There appears to be the remote fs API, but it's extremely poor.