💡: the extension should ignore files outside the open workspace
Problem
In VSCode, even if we get our repo cspell-clean, if we F12 into other files outside the open workspace e.g., under ~/.rustup/toolchains/ for downloaded std source, the Problems pane is populated with a bunch of misspellings we have no control over.
Solution
At least for the VSCode extension, any files outside the current workspace folder(s) should be ignored. More generally, any directories outside the current working directory could be ignored.
Alternatives
If this is the purpose of the --root (usage docs aren't entirely clear how it's used - presumably only for --relative), that could also be configurable in the configuration file e.g., in .vscode/cspell.json we could add "root": "..".
Additional Context
Once misspellings are added to the Problems pane, even if the file outside the workspace with the unknown words is closed, those problems hang around and are very distracting. We can filter out "Infos" from the Problem pane, but that may also hide some "infos" we want to see from other extensions.
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
I'd be willing to submit a PR, but would like to discuss how best to approach this, if acceptable. It seems a general solution a la cspell-lib is unnecessary because I can't see this problem extending to cspell CLI invocations. It's likely limited to VSCode et. al., but could be supported by code in cspell-lib and friends if there's an extensibility or performance reason for doing so, like a change to some of the functions that check files' paths against the config.
@heaths,
Thank you for your thoughtful input.
Problem
In VSCode, even if we get our repo cspell-clean, if we F12 into other files outside the open workspace e.g., under
~/.rustup/toolchains/for downloadedstdsource, the Problems pane is populated with a bunch of misspellings we have no control over.
Having the Problems pane filled with unrelated spelling errors can be annoying. There are two features to cope with this:
- The
cSpell.spellCheckOnlyWorkspaceFilessetting should limit which files are checked. - The 4.x version (still in preview) has by default moved the spelling issues out of the Problems pane and into its own. This should address the case where code issues are getting covered up by spelling issues.
Solution
At least for the VSCode extension, any files outside the current workspace folder(s) should be ignored. More generally, any directories outside the current working directory could be ignored.
I hope the options given above solve the issue. Please try them out. More feedback is welcome.
Alternatives
If this is the purpose of the
--root(usage docs aren't entirely clear how it's used - presumably only for--relative), that could also be configurable in the configuration file e.g., in.vscode/cspell.jsonwe could add"root": "..".
The --root option sets the effective current working directory. Sometimes it is not always possible or desirable to change the cwd. cspell --root ../docs . would check the sibling docs directory.
The files setting in cspell.json takes a list of globs. By default, it filters the files to be checked.
Additional Context
Once misspellings are added to the Problems pane, even if the file outside the workspace with the unknown words is closed, those problems hang around and are very distracting. We can filter out "Infos" from the Problem pane, but that may also hide some "infos" we want to see from other extensions.
- This hanging around issue is caused by a change in the VS Code behavior. VS Code now keeps the file open in the background even if there are no longer any tabs referencing the file. In v4 issues that do not have an open tab, are now hidden.
I'd be willing to submit a PR, but would like to discuss how best to approach this, if acceptable. It seems a general solution a la
cspell-libis unnecessary because I can't see this problem extending tocspellCLI invocations. It's likely limited to VSCode et. al., but could be supported by code incspell-liband friends if there's an extensibility or performance reason for doing so, like a change to some of the functions that check files' paths against the config.
Thank you for the offer. PRs are welcome. Please try out v4. Any help or feedback on getting it finished would be appreciated.
@larryosterman looks like there's already an option that should help.
The instant I set cSpell.spellCheckOnlyWorkspaceFiles=true in my user profile, a bunch of words from VSCode's own user settings (under my roaming profile) showed up in Problems. That seems...odd.
@heaths,
The instant I set
cSpell.spellCheckOnlyWorkspaceFiles=truein my user profile, a bunch of words from VSCode's own user settings (under my roaming profile) showed up in Problems. That seems...odd.
That is to be expected if you do not have a workspace or folder open (please let me know if that is not the case).
If you do not want the file checked, then just add it to cSpell.ignorePaths.
Possible duplicate of: https://github.com/streetsidesoftware/vscode-spell-checker/issues/3542
I have set "spellCheckOnlyWorkspaceFiles": true in .vscode/cspell.json , but VS Code tells me Property spellCheckOnlyWorkspaceFiles is not allowed.
Â
And when I check files outside the workspace, cspell still shows errors that should be ignored.
The folder is opened as workspace, not as a single file. Â Version: [email protected]
I have set
"spellCheckOnlyWorkspaceFiles": truein.vscode/cspell.json, but VS Code tells meProperty spellCheckOnlyWorkspaceFiles is not allowed. And when I check files outside the workspace, cspell still shows errors that should be ignored.The folder is opened as workspace, not as a single file.  Version: [email protected]
Sorry for the confusion. This is not a CSpell CLI setting, it is a setting only used by the extension. Not all extension settings can be added to a cspell.json file.
Add it to .vscode/settings.json:
Or use files in the cspell.json file:
.vscode/cspell.json
{
"globRoot": "..", // glob root is needed because this file is inside `.vscode/`
"files": ["/**"]
}
Ah okay, thanks for the clarification. I will test tomorrow.
A side question: so it is possible to configure some things in in different configuration files and the configurations are getting merged?
A side question: so it is possible to configure some things in in different configuration files and the configurations are getting merged?
CSpell CLI configuration can be merged. VS Code settings have their own rules: Settings Precedence.
The extension uses the CSpell library to do the spell checking. The CSpell library searches up the directory tree for the nearest CSpell configuration file. Settings found in the CSpell configuration are merged with the settings from VS Code.
It is possible to use the import setting to explicitly import CSpell configuration.
Here is an example import to import config from <workspace root>/project-config/cspell.config.yaml and the German dictionary (needs to be installed separately).
.vscode/cspell.json
{
"import": ["../project-config/cspell.config.yaml", "@cspell/dict-de-de"]
}
.vscode/settings.json
"cSpell.import": ["${workspaceRoot}/project-config/cspell.config.yaml", "@cspell/dict-de-de"]
// ${workspaceRoot} (see below) is needed because the extension doesn't known the
// location of the `settings.json` file.
Special Values in .vscode/settings.json:
${workapceRoot}- The first workspace folder.${workspaceFolder}- Imports will be relative to the current workspace folder${workspaceFolder:<name>}- Where<name>is the name of the workspace folder.
Or use
filesin thecspell.jsonfile:
.vscode/cspell.json{ "globRoot": "..", // glob root is needed because this file is inside `.vscode/` "files": ["/**"] }
I tried this and it does not work. Should I provide screenshots?
The mentioned setting does not work. None of the approaches above prevent the extensions from complaining about the spellings in settings.json.
@tylerlaprade,
VS Code opens files in the background. When it opens the files, it triggers the spell checker.
There are two work arounds:
- Use custom decorations:
cSpell.useCustomDecorationsThe spell checker will handle rendering issues and files opened by VS Code in the background will not show up.
- The
Spell: Toggle Show Spelling Issues,Spell: Show Spelling Issues, andSpell: Hide Spelling Issuescommands can be used to show/hide spelling issues. Using these command will clean up and left over issues in the problem pane.
I'm going to close this for now. There are two different issues being raised here.
- Only spell checking files within the workspace.
- Showing spelling issues for files that are opened in the background by VS Code.
Issue 1. should be working. If it is not, please open a new issue with your configuration. I hope to have a better solution for Issue 2. Please realize it was caused by a change in behavior by VS Code.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.