vscode-spell-checker icon indicating copy to clipboard operation
vscode-spell-checker copied to clipboard

[Bug]: Unhandled file type: "cspell.config.js"

Open jerone opened this issue 1 year ago • 4 comments

Adding a word to the words list in the config file, within VSCode, results in the following error modal:

Unhandled file type: "cspell.config.js"

The output for CSpell was empty, but I did find the error in the "Window" output filter.
2024-02-17 12:58:06.650 [error] [Extension Host] Error: context (Register command: cSpell.addWordsToConfigFileFromServer): [tl [Error]: Unhandled file type: "cspell.config.js"
	at wq (c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:402:7874)
	at rg (c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:402:7810)
	at Cc (c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:405:6760)
	at cSpell.addWordsToConfigFileFromServer (c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:407:2314)
	at c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:405:16835
	at c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:405:16767
	at An (c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:405:16771)
	at c:\Users\jeron\.vscode\extensions\streetsidesoftware.code-spell-checker-3.0.1\packages\client\dist\extension.js:405:16828
	at s.h (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:150:175243)
	at s.g (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:150:174235)
	at s.executeCommand (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:150:174142)
	at d.h (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:150:177580)
	at s.h (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:150:175243)
	at s.$executeContributedCommand (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:150:176103)
	at d.S (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:147:5520)
	at d.Q (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:147:5286)
	at d.M (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:147:4376)
	at d.L (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:147:3455)
	at g.value (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:147:2242)
	at r.y (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:1902)
	at r.fire (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:2119)
	at n.fire (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:105:14073)
	at g.value (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:173:8051)
	at r.y (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:1902)
	at r.fire (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:80:2119)
	at n.fire (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:105:14073)
	at MessagePortMain.<anonymous> (c:\Users\jeron\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:173:6331)
	at MessagePortMain.emit (node:events:514:28)
	at MessagePortMain.emit (node:domain:489:12)
	at Object.emit (node:electron/js2c/utility_init:2:2285)] {
  [stack]: [Getter/Setter],
  [message]: 'Unhandled file type: "cspell.config.js"'
}

Config file

const cspell = {
  version: "0.2",
  language: "en",
  words: [],
};

module.exports = cspell;

Version

VSCode: 1.86.2 (user setup) Code Spell Checker extension: v3.0.1 OS: Windows_NT x64 10.0.19045

Steps to reproduce

  1. Open a project in VSCode with Code Spell Checker extension installed.
  2. Create file cspell.config.js with the contents from above.
  3. Find a unknown word and choose the "Add: XXX to config: project/cspell.config.js" option.
  4. Notice error.

Expected behavior

Expected no error and unknown word to be added to the words list in cspell.config.js.

jerone avatar Feb 17 '24 12:02 jerone

Apparently, JavaScript config files are not supported: https://github.com/streetsidesoftware/vscode-spell-checker/blob/df8229e8d7a584ffecfe9048438eb91187583dfb/packages/client/src/settings/configFileReadWrite.ts#L17-L21

Aldo, it's in the list of supported config file names: https://cspell.org/configuration/#configuration

jerone avatar Feb 17 '24 15:02 jerone

@jerone,

It is not possible for the spell checker to add words to a JavaScript file. The complexity of correctly adding words to code is beyond the capabilities of the spell checker. If you create a dictionary file, the spell check can add words to that.

cspell.config.js

const cspell = {
  version: "0.2",
  language: "en",
  dictionaryDefinitions: [
    { name: "custom-words", path: "./words.txt", addWords: true },
  ],
  dictionaries: ["custom-words"],
};

module.exports = cspell;

words.txt

# one word per line.

Jason3S avatar Feb 17 '24 18:02 Jason3S

Thank for the explanation and the workaround (will try that later).

The confusion started because of the "Add: XXX to config: project/cspell.config.js" quick fix: image

Maybe clicking that can result in a message that only JSON config files are supported. Or hide the option at all if the project config file is not of a supported type.

jerone avatar Feb 17 '24 19:02 jerone

@jerone,

Thank you. I'll look into why it was presented as an option. It should not have been.

Jason3S avatar Feb 22 '24 12:02 Jason3S