Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom dictionaries defined in cspell.json do not show up in drop-down to add words. #2056

Closed
adam-grant-hendry opened this issue Jul 1, 2022 · 5 comments

Comments

@adam-grant-hendry
Copy link

I'm not sure if this is by design or an accident, but I cannot add customDictionaries to a cspell.json. It is only available within a settings.json when using VSCode.

image

Per the docs:

The spell checker configuration can be controlled via VS Code preferences or cspell.json configuration file.

Order of precedence:

Workspace Folder cspell.json
Workspace Folder .vscode/cspell.json
VS Code Preferences cSpell section.

Hence, the cspell.json overrides the VSCode settings.json settings. Thus, I can't see my right-click drop-down of custom dictionaries. In addition to taking it out, I have tried simply leaving the customDictionaries property in regardless of the error. In both cases, the right-click context menu dropdown does not show the custom dictionaries.

This makes things a little cumbersome when trying to sync settings with other developers who don't use VSCode.

System Info

OS: Windows 10, x64-bit
cSpell: v2.2.5
VSCode: 1.68.1

Project Directory Layout

myproj/
├─.cspell/
│ ├─acronyms.txt
│ ├─authors.txt
│ └─python-packages.txt
├─.gitignore
├─.vscode/
│ └─settings.json
├─cspell.json
├─.pre-commit-config.yaml
└─myproj/
  ├─__init__.py
  └─main.py
settings.json
{
    "cSpell.useGitignore": true,
    "cSpell.allowCompoundWords": true,
    "cSpell.diagnosticLevel": "Error",
    "cSpell.dictionaries": [
        "python",
        "wordsEn",
        "companies",
        "softwareTerms",
        "medical terms",
        "scientific-terms-us",
        "acronyms",
        "authors",
        "python-packages"
    ],
    "cSpell.ignorePaths": [
        "*.dll",
        "*.html",
        "*.css",
        "*.json",
        "*.git/**",
        "**/build/**",
        ".venv/",
        "*.bat"
    ],
    "cSpell.ignoreRegExpList": [
        "Email"
    ],
    "cSpell.includeRegExpList": [
        "comments",
        "docstring",
        "string",
        "imports"
    ],
    "cSpell.patterns": [
        {
            "name": "comment-single-line",
            "pattern": "/#.*/"
        },
        {
            "name": "comment-multi-line",
            "pattern": "/(?:\\/\\*[\\s\\S]*?\\*\\/)/g"
        },
        {
            "name": "comments",
            "pattern": ["comments-single-line", "comments-multiline"]
        },
        {
            "name": "docstring",
            "pattern": "/([\"]{3}|[']{3})[^\\1]*?\\1/g"
        },
        {
            "name": "single-line-imports",
            "pattern": "import\\s*.*\".*?\""
        },
        {
            "name": "multi-line-imports",
            "pattern": "import\\s*\\((.|[\r\n])*?\\)"
        },
        {
            "name": "imports",
            "pattern": ["single-line-imports", "multi-line-imports"]
        }
    ],
    "cSpell.customDictionaries": {
        "acronyms": {
            "name": "acronyms",
            "path": "${workspaceFolder}/.cspell/acronyms.txt",
            "description": "Acronyms used in this project",
            "addWords": true
        },
        "python-packages": {
            "name": "python-packages",
            "path": "${workspaceFolder}/.cspell/python-packages.txt",
            "description": "Names of python packages used in this project",
            "addWords": true
        },
        "authors": {
            "name": "authors",
            "path": "${workspaceFolder}/.cspell/authors.txt",
            "description": "Names of authors contributing to this project",
            "addWords": true
        }
    }
}
cspell.json
{
    "allowCompoundWords": true,
    "customDictionaries": {
        "acronyms": {
            "name": "acronyms",
            "path": "${workspaceFolder}/.cspell/acronyms.txt",
            "description": "Acronyms used in this project",
            "addWords": true
        },
        "python-packages": {
            "name": "python-packages",
            "path": "${workspaceFolder}/.cspell/python-packages.txt",
            "description": "Names of python packages used in this project",
            "addWords": true
        },
        "authors": {
            "name": "authors",
            "path": "${workspaceFolder}/.cspell/authors.txt",
            "description": "Names of authors contributing to this project",
            "addWords": true
        }
    },
    "dictionaries": [
        "python",
        "python-common",
        "wordsEn",
        "companies",
        "softwareTerms",
        "medical terms",
        "scientific-terms-us",
        "acronyms",
        "authors",
        "python-packages"
    ],
    "dictionaryDefinitions": [
        {
            "name": "acronyms",
            "path": "./.cspell/acronyms.txt"
        },
        {
            "name": "python-packages",
            "path": "./.cspell/python-packages.txt"
        },
        {
            "name": "authors",
            "path": "./.cspell/authors.txt"
        }
    ],
    "flagWords": [
        "hte"
    ],
    "ignorePaths": [
        "*.dll",
        "*.html",
        "*.css",
        "*.json",
        "*.git/**",
        "**/build/**",
        ".venv/",
        "*.bat"
    ],
    "ignoreRegExpList": [
        "Email"
    ],
    "includeRegExpList": [
        "comments",
        "docstring",
        "string",
        "imports"
    ],
    "patterns": [
        {
            "name": "comment-single-line",
            "pattern": "/#.*/"
        },
        {
            "name": "comment-multi-line",
            "pattern": "/(?:\\/\\*[\\s\\S]*?\\*\\/)/g"
        },
        {
            "name": "comments",
            "pattern": [
                "comments-single-line",
                "comments-multiline"
            ]
        },
        {
            "name": "docstring",
            "pattern": "/([\"]{3}|[']{3})[^\\1]*?\\1/g"
        },
        {
            "name": "single-line-imports",
            "pattern": "import\\s*.*\".*?\""
        },
        {
            "name": "multi-line-imports",
            "pattern": "import\\s*\\((.|[\r\n])*?\\)"
        },
        {
            "name": "imports",
            "pattern": [
                "single-line-imports",
                "multi-line-imports"
            ]
        }
    ],
    "useGitignore": true,
    "version": "0.2"
}

cspell.json Removed (settings.json Alone)

cspell_working

Both cspell.json and settings.json

cspell_notworking

@adam-grant-hendry
Copy link
Author

adam-grant-hendry commented Jul 1, 2022

@Jason3S It appears from looking at your cSpell.json that one can use the properties addWords and scope within dictionaryDefinitions.

Would you mind updating the documentation to reflect this?

@adam-grant-hendry
Copy link
Author

@Jason3S I also wanted to say thank you for this extension!

As a recommendation, it would be very helpful to users if your examples showed how to use ALL configuration settings in each file format that is supported in a single example section at the end of the documentation.

e.g., the cspell.json section is rather sparse

cspell.json
// cSpell Settings
{
    // Version of the setting file.  Always 0.2
    "version": "0.2",
    // language - current active spelling language
    "language": "en",
    // words - list of words to be always considered correct
    "words": [
        "mkdirp",
        "tsmerge",
        "githubusercontent",
        "streetsidesoftware",
        "vsmarketplacebadge",
        "visualstudio"
    ],
    // flagWords - list of words to be always considered incorrect
    // This is useful for offensive words and common spelling errors.
    // For example "hte" should be "the"
    "flagWords": [
        "hte"
    ]
}

the VSCode settings.json section has a bit more

settings.json
    //-------- Code Spell Checker Configuration --------
    // The Language local to use when spell checking. "en", "en-US" and "en-GB" are currently supported by default.
    "cSpell.language": "en",

    // Controls the maximum number of spelling errors per document.
    "cSpell.maxNumberOfProblems": 100,

    // Controls the number of suggestions shown.
    "cSpell.numSuggestions": 8,

    // The minimum length of a word before checking it against a dictionary.
    "cSpell.minWordLength": 4,

    // Specify file types to spell check.
    "cSpell.enabledLanguageIds": [
        "csharp",
        "go",
        "javascript",
        "javascriptreact",
        "markdown",
        "php",
        "plaintext",
        "typescript",
        "typescriptreact",
        "yml"
    ],

    // Enable / Disable the spell checker.
    "cSpell.enabled": true,

    // Display the spell checker status on the status bar.
    "cSpell.showStatus": true,

    // Words to add to dictionary for a workspace.
    "cSpell.words": [],

    // Enable / Disable compound words like 'errormessage'
    "cSpell.allowCompoundWords": false,

    // Words to be ignored and not suggested.
    "cSpell.ignoreWords": ["behaviour"],

    // User words to add to dictionary.  Should only be in the user settings.
    "cSpell.userWords": [],

    // Specify paths/files to ignore.
    "cSpell.ignorePaths": [
        "node_modules",        // this will ignore anything the node_modules directory
        "**/node_modules",     // the same for this one
        "**/node_modules/**",  // the same for this one
        "node_modules/**",     // Doesn't currently work due to how the current working directory is determined.
        "vscode-extension",    //
        ".git",                // Ignore the .git directory
        "*.dll",               // Ignore all .dll files.
        "**/*.dll"             // Ignore all .dll files
    ],

    // flagWords - list of words to be always considered incorrect
    // This is useful for offensive words and common spelling errors.
    // For example "hte" should be "the"`
    "cSpell.flagWords": ["hte"],

    // Set the delay before spell checking the document. Default is 50.
    "cSpell.spellCheckDelayMs": 50,

but neither demonstrates how to use all the available options.

@Jason3S
Copy link
Collaborator

Jason3S commented Jul 3, 2022

@adam-grant-hendry,

As you figured out, adding addWords to your cspell.json file will tell the extension to show the dictionaries.

I'll take a look at making addWords optional, since sharing configuration is common.

customDictionaries is really only a VS Code settings value. It doesn't hurt anything to have it in a cspell.json file, but it isn't used by the cspell library. On the other hand, it is used by the VS Code Spell Checker Extension.

customDictionaries was added because VS Code does not support merging settings if they are an array, making defining a User level dictionary and a Workspace level dictionary impossible.

@Jason3S Jason3S changed the title [BUG]: customDictionaries Not Permitted in cspell.json Custom dictionaries defined in cspell.json do not show up drop-down to add words. Jul 3, 2022
@Jason3S Jason3S changed the title Custom dictionaries defined in cspell.json do not show up drop-down to add words. Custom dictionaries defined in cspell.json do not show up in drop-down to add words. Jul 3, 2022
@adam-grant-hendry
Copy link
Author

@Jason3S What about “scope”. Will that also be optional?

Regardless, can you please add both of these to your documentation because they are not there.

Jason3S added a commit that referenced this issue Jul 5, 2022
Jason3S added a commit that referenced this issue Jul 5, 2022
* fix: Show all possible dictionaries on codeAction
   Related to #2056
@Jason3S Jason3S closed this as completed Jul 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2022

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 github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants