streetsidesoftware / vscode-spell-checker

A simple source code spell checker for code
https://streetsidesoftware.github.io/vscode-spell-checker/
Other
1.43k stars 128 forks source link

Extension doesn't get disabled in some file types when using `cSpell.enabledLanguageIds` #2660

Open dalbitresb12 opened 1 year ago

dalbitresb12 commented 1 year ago

Hi! Thanks for the awesome work with this extension.

I'm trying to only enable the spell checker on specific file types (e.g. Markdown, Plain Text, Latex and other non-code files but not TypeScript, Python, etc). I've tried using cSpell.enableFiletypes to manually disable each file type I don't want checked, but I can't find a way to not have to list every language with a ! at the start to disable it. I've tried using !* but it doesn't seem to work (or it's not implemented).

I've also tried only listing specific language ids using cSpell.enabledLanguageIds. Using this option does disable the extension in most of the file types, but it doesn't for some. For example, the extension still shows suggestions when using Dart, so I've had to disable it manually with cSpell.enabledLanguageIds.

My current settings look like this:

{
  "cSpell.checkOnlyEnabledFileTypes": true,
  "cSpell.enabledLanguageIds": [
    "git-commit",
    "git-rebase",
    "latex",
    "markdown",
    "plaintext",
    "restructuredtext",
    "scminput",
    "text"
  ],
  "cSpell.enableFiletypes": [
    "!dart"
  ],
}

I'm not sure if #1893 is related to this issue, but I'm linking it anyways because I get the same result in the UI and I still get suggestions if I don't disable Dart with cSpell.enableFiletypes as you can see in the following screenshots.

User preferences ![User preferences showing Dart is disabled](https://github.com/streetsidesoftware/vscode-spell-checker/assets/7624090/113e6e2f-410f-4c2a-84e0-ff286072d962)
Workspace preferences ![Workspace preferences showing Dart is also disabled](https://github.com/streetsidesoftware/vscode-spell-checker/assets/7624090/bc182c3b-75ca-4101-b06a-17b4f86307cc)
File preferences ![File preferences showing Dart is somehow enabled](https://github.com/streetsidesoftware/vscode-spell-checker/assets/7624090/d91d04a6-28a4-4edd-9c58-20eac0437fc8)
Jason3S commented 1 year ago

@dalbitresb12,

It does seem to be a bit confusing.

Both enabledLanguageIds and enableFiletypes are use to determine the list of enabled file types. There is some history behind them, but essentially enabledLanguageIds is an absolute list of ids where enableFiletypes is used to add/remove file types from the list defined by enabledLanguageIds. It looks like the Dart dictionary includes an enableFiletypes setting: [

image

](https://github.com/streetsidesoftware/cspell-dicts/blob/7f36f91f3496641461d9f15b1c0b75b97e68bdb3/dictionaries/dart/cspell-ext.json#L15)

I think a different approach might be better in your case.

cSpell.languageSettings allows you to control settings based upon file type (aka languageId).

image
  "cSpell.languageSettings": [
    // turn off spell checker for ALL file types
    { "languageId": "*", "enabled": false },
    // renable the spell checker for selective types
    { "languageId": ["markdown", "plaintext", "latex"], "enabled": true}
  ],
Jason3S commented 1 year ago

languageId is a legacy name based upon VS Codes' API. It is confusing because it is not clear what it refers to (JavaScript vs English). I hope to replace it with fileType. Natural language settings will move towards locale.

Initially when VS Code and the Spell Checker only supported a few langaugeIds, using an absolute list like enabledLanguageIds made sense. But it broke down when support for more and more file types as added by VS Code or the Spell Checker because it required someone to copy the entire list into their settings just to add spell checking on a new file type, which is why enableFiletypes was added.

dalbitresb12 commented 1 year ago

Thank for the reply! It is indeed confusing.

I tried using your suggestion with cSpell.languageSettings and it does work! No spell checking happens in Dart files, but it is still confusing because it looks like the extension is still enabled on the file:

File preferences showing Dart is enabled even though no suggestions are generated

Spell checker in status bar saying "main.dart is spell checked"

This also happens somehow for the rest of files I guess, since those now are showing as enabled in User preferences:

User preferences showing default languages enabled even though they should be disabled

I guess that the extension is working correctly internally, but the UI is not reflecting it and that's why it seems confusing.

acramsay commented 9 months ago

For any readers that are trying to whitelist the filetypes and languages, the extension documentation is a bit misleading in the Enabled File Types section. It instructs you to configure the cSpell.enableFiletypes setting (which doesn't help) and much later mentions cSpell.enabledLanguageIds. You can add this code snippet to your vscode settings.json file.

"cSpell.enabledLanguageIds": [
    "markdown"
  ]

If you start typing cSpell.enabledLanguageIds in settings.json, you can use the tab completion to populate the content with all of the languages that are enabled by default.

Jason3S commented 9 months ago

@acramsay,

The two different settings work in different ways. The enabledLanguageIds sets the base list of file types to check and enableFiletypes modifies that list by allowing you to add or remove file types.