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

💡: the extension should ignore files outside the open workspace

Open heaths opened this issue 1 year ago • 10 comments

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

heaths avatar Aug 30 '24 01:08 heaths

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 avatar Aug 30 '24 01:08 heaths

@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 downloaded std source, 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.spellCheckOnlyWorkspaceFiles setting should limit which files are checked. image
  • 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. image

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.json we 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-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.

Thank you for the offer. PRs are welcome. Please try out v4. Any help or feedback on getting it finished would be appreciated.

Jason3S avatar Aug 30 '24 07:08 Jason3S

@larryosterman looks like there's already an option that should help.

heaths avatar Aug 30 '24 15:08 heaths

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 avatar Aug 30 '24 23:08 heaths

@heaths,

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.

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. image

Possible duplicate of: https://github.com/streetsidesoftware/vscode-spell-checker/issues/3542

Jason3S avatar Aug 31 '24 08:08 Jason3S

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]

swaldhoer avatar Sep 10 '24 09:09 swaldhoer

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]

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:

image

Or use files in the cspell.json file:

.vscode/cspell.json

{
    "globRoot": "..", // glob root is needed because this file is inside `.vscode/`
    "files": ["/**"]
}

Jason3S avatar Sep 10 '24 14:09 Jason3S

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?

swaldhoer avatar Sep 10 '24 16:09 swaldhoer

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.

Jason3S avatar Sep 11 '24 03:09 Jason3S

Or use files in the cspell.json file:

.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?

swaldhoer avatar Sep 17 '24 21:09 swaldhoer

The mentioned setting does not work. None of the approaches above prevent the extensions from complaining about the spellings in settings.json.

tylerlaprade avatar Nov 20 '24 18:11 tylerlaprade

@tylerlaprade,

VS Code opens files in the background. When it opens the files, it triggers the spell checker.

There are two work arounds:

  1. Use custom decorations: cSpell.useCustomDecorations image The spell checker will handle rendering issues and files opened by VS Code in the background will not show up.
  2. The Spell: Toggle Show Spelling Issues, Spell: Show Spelling Issues, and Spell: Hide Spelling Issues commands can be used to show/hide spelling issues. Using these command will clean up and left over issues in the problem pane. image

Jason3S avatar Nov 21 '24 06:11 Jason3S

I'm going to close this for now. There are two different issues being raised here.

  1. Only spell checking files within the workspace.
  2. 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.

Jason3S avatar Nov 21 '24 06:11 Jason3S

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.

github-actions[bot] avatar Dec 22 '24 05:12 github-actions[bot]