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

[Question] How to setup a custom dictionary? #681

Closed
lonix1 opened this issue Jan 25, 2021 · 12 comments
Closed

[Question] How to setup a custom dictionary? #681

lonix1 opened this issue Jan 25, 2021 · 12 comments

Comments

@lonix1
Copy link
Contributor

lonix1 commented Jan 25, 2021

I'm a little confused by the various config options, and I've read through this.

I want to store my custom words in a text file at /.vscode/dictionary.txt.

So I added this to my workspace settings (/.vscode/settings.json), but it doesn't work:

"cSpell.dictionaryDefinitions": [
  { "name": "custom", "path": ".vscode/dictionary.txt" },
],
"cSpell.dictionaries": [ "custom" ],

What am I doing wrong?

@Jason3S
Copy link
Collaborator

Jason3S commented Jan 26, 2021

The spell checker cannot find the dictionary because it does not know what the file is relative to.

Please try changing the path to:

"path": "${workspaceFolder}/.vscode/dictionary.txt"

The docs need to be updated to make this clearer, but here is the blurb from the changelog:

${workspaceFolder} substitution in paths and globs

Relative paths were difficult to get working when specified in VS Code settings. It wasn't clear what they should be relative to. Relative paths to a cspell.json files are clear.

It is now possible to have the following setting in VS Code preferences.

"cSpell.import": [
  "${workspaceFolder}/node_modules/company_standards/cspell.json"
]

for a multiroot with folders client, server, common, it is possible to specify the name of the folder:

"ignorePaths": [
  "${workspaceFolder:client}/**/*.json"
],
"cSpell.import": [
  "${workspaceFolder:server}/node_modules/company_standards/cspell.json"
],
"cSpell.dictionaryDefinitions": [
  {
    "name": "Company Terms",
    "path": "${workspaceFolder:common}/dictionaries/terms.txt"
  }
],
"cSpell.dictionaries": ["Company Terms"]

@lonix1
Copy link
Contributor Author

lonix1 commented Jan 26, 2021

Thanks the extension now loads words from that txt file.

But when a word is not recognized and I choose Add: "foo" to workspace dictionary, it is added to .vscode/settings.json instead of .vscode/dictionary.txt

@Jason3S
Copy link
Collaborator

Jason3S commented Jan 27, 2021

It is not very well documented, but it is possible:

"cSpell.customFolderDictionaries": ["custom"]

Will tell the extension to add files to the custom dictionary.

See Release Notes v1.9.0-alpha.0 and #61 (comment)

@Jason3S Jason3S changed the title [Question] Custom dictionary in txt rather than json [Question] How to setup a custom dictionary? Jan 27, 2021
@lonix1
Copy link
Contributor Author

lonix1 commented Jan 27, 2021

Unfortunately that didn't work for me.

From my .vscode/settings.json:

"cSpell.dictionaryDefinitions": [
  { "name": "custom", "path": "${workspaceFolder}/.vscode/dictionary.txt" },
],
"cSpell.dictionaries": [ "custom" ],
"cSpell.customFolderDictionaries": ["custom"],

But still when I use ctrl . over a misspelled word and choose "Add: "foo" to workspace dictionary", it gets added to .vscode/settings.json rather than .vscode/dictionary.txt.

Any ideas? 🤔


If I have a .vscode/cspell.json file then the word is added there, as expected

I'm using the latest versions of vscode and the extension

@Jason3S
Copy link
Collaborator

Jason3S commented Jan 27, 2021

I'm guessing you have just a single folder in your workspace.

Please try:

"cSpell.customWorkspaceDictionaries": [ "custom" ]

@Jason3S
Copy link
Collaborator

Jason3S commented Jan 27, 2021

VS Code is a bit confusing on how it deals we workspaces and folders.

If you have a single folder open, that folder is considered the "workspace". If you have multiple folders open, then there is a .code-workspace file that defines the workspaces.

VS Code Merges the settings in the following order: user, workspace, folder.

If the folder has a setting of the same name, it overrides the settings from user and workspace.

To be able to write words to different dictionaries, it is necessary to be able to distinguish between the three different configurations. To accomplish this, three different settings are used:

  • customUserDictionaries
  • customWorkspaceDictionaries
  • customFolderDictionaries

@lonix1
Copy link
Contributor Author

lonix1 commented Jan 27, 2021

"cSpell.dictionaryDefinitions": [
  { "name": "custom", "path": "${workspaceFolder}/.vscode/dictionary.txt" },
],
"cSpell.customWorkspaceDictionaries": [ "custom" ]

That works! Thank you!

I assume you're talking about those "multi root" workspaces? Yeah I'm just using one root / workspace.

The docs could benefit from my above use case... the customWorkspaceDictionaries setting is the magic sauce to make it work.

This is an excellent extension, thanks for making and maintaining it!

@lonix1 lonix1 closed this as completed Jan 27, 2021
@lonix1
Copy link
Contributor Author

lonix1 commented Jan 27, 2021

BTW the docs mention this twice, but the addWords setting doesn't exist:

// If addWords is true words will be added to this dictionary.

@lonix1
Copy link
Contributor Author

lonix1 commented Oct 22, 2021

Hey @Jason3S I've been using your above recommendation for most of this year:

"cSpell.dictionaryDefinitions": [
  { "name": "custom", "path": "${workspaceFolder}/.vscode/dictionary.txt" },
],
"cSpell.customWorkspaceDictionaries": [ "custom" ]

But now customWorkspaceDictionaries gives a deprecation notice Use customDictionaries instead..

I can't find any docs to explain how to move from the old to new config. Any pointers?

@Jason3S
Copy link
Collaborator

Jason3S commented Oct 25, 2021

@lonix1,

Some docs and an example are here:
Configuration Settings - Spell Checker

Both of the following will work:

"cSpell.dictionaryDefinitions": [
  { "name": "custom", "path": "${workspaceFolder}/.vscode/dictionary.txt" },
],
"cSpell.customDictionaries": { "custom": true }
"cSpell.customDictionaries": {
  "custom": { "name": "custom", "path": "${workspaceFolder}/.vscode/dictionary.txt", "addWords": true }
},

The change was made to support how VS Code merges User / Workspace / Folder / Language settings.

If you define "cSpell.dictionaryDefinitions" at the Workspace and Folder level, due to the way VS Code merges the settings, the Folder will not have access to the Workspace dictionaries.

By using an Object instead of an Array, VS Code will merge the settings:

Workspace

"cSpell.customDictionaries": {
  "custom": { "name": "custom", "path": "${workspaceFolder:Root}/.vscode/dictionary.txt", "addWords": true },
  "internal": { "path": "${workspaceFolder:Root}/internal-terms.txt" }
},

Folder

"cSpell.customDictionaries": {
  "web-terms": { "path": "${workspaceFolder:Web}/terms.txt", "addWords": true },
  "internal": false
},

Result

"cSpell.customDictionaries": {
  "custom": { "name": "custom", "path": "${workspaceFolder:Root}/.vscode/dictionary.txt", "addWords": true },
  "web-terms": { "path": "${workspaceFolder:Web}/terms.txt", "addWords": true }
},

@lonix1
Copy link
Contributor Author

lonix1 commented Oct 25, 2021

That works, thanks!

jeffmccune added a commit to openinfrastructure/pypackage that referenced this issue Oct 28, 2021
This patch adds a custom dictionary to the folder level so the project
name doesn't show up as a spelling error.  See [how to set up a custom
dictionary][1].

Markdown lint is also configured to support details and summary HTML
tags, which are fantastic for Github issue readability.

[1]: streetsidesoftware/vscode-spell-checker#681 (comment)
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 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 Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants