48

It is required to have a dictionary for Intellij Idea spellchecking, that meets the following requirements:

  1. May be shared by VCS, so all developers can use it
  2. Every developer should be able to edit it easily

As far as I know, where are 2 types of dictionaries in Idea:

  1. One user dictionary, named "%username%.xml" (Settings-->Spelling-->Accepted Words)
  2. Number of custom dictionaries, "*.dic" (Settings-->Spelling-->Dictionaries)

But none of them meets the requirements.

User dictionary is easy to edit (Alt+Enter "Save ... to dictionary") and can be added to VCS, but it has a predefined user name, so it's impossible to share (e.g. developer A shared his A.xml, but developer B can't use it, because his Idea project only works with B.xml)

Custom dictionary has no problems with sharing, but it should be edited manually and it needs to reestart Idea to apply changes (e.g. make it see new words)

I've not found a plugin to solve that problem or any similar question, which makes me think that nobody needs such dictionary or the answer is too obvious.

So, is there any way to do it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
kdoker
  • 496
  • 5
  • 10

3 Answers3

41

Note that, even though the words added to the dictionary by each developer are stored in a separate file, IntelliJ IDEA takes the words added by all developers, and does not highlight any of them as typos. The storage in separate files was designed specifically to avoid merge conflicts when storing the dictionary in a version control system.

Therefore, the default functionality of IntelliJ IDEA should meet your requirements.

yole
  • 92,896
  • 20
  • 260
  • 197
  • 1
    do you mean by _takes the words added by all developers_ that with spelling inspection configured to highlight typos IDEA will take words from all files in .idea/dictionaries? Because if I create a new file with words, e.g.".idea/dictionaries/test.xml", it doesn't work – kdoker Jan 26 '15 at 15:25
  • 3
    That is what @yole meant. Make sure the `name' attribute of the `dictionary` element matches the file name ("Test" in your case). A project reload may be needed. I'm not sure if IDEA reloads those files on a VCS update. (We do not store our `.idea` settings in VCS). Yole would know as he's one of the developers at JetBrains. I've successfully created multiple dictionary files in that directory. – Javaru Jan 26 '15 at 16:03
  • Yes, this is what I meant. We're using this setup at JetBrains and it works as intended. – yole Jan 26 '15 at 17:56
  • 2
    I **renamed** the dictionary file from `username.xml` to `developer.xml` to avoid **exposing my user name** at my machine. I also changed the value of `name` attribute in the file. I also changed the respective entries in `workspace.xml` and closed and reopened the project. When I add a new word to the dictionary a **new `username.xml` file is created**, though. JetBrains, please let users configure this. – JJD Jan 20 '17 at 16:38
  • 1
    @JJD Please try adding "user.name=" to idea.properties – yole Jan 23 '17 at 12:43
  • @yole In which file/file path please? In a new file called `idea.properties` in the project root or in the `.idea/` folder? – JJD Jan 30 '17 at 16:51
  • @JJD see this link: https://www.jetbrains.com/help/idea/file-idea-properties.html – ngreen Sep 20 '17 at 14:59
  • 1
    @ngreen If I understand correctly, you suggest maintain the configuration in the HOME folder of the user - outside of the project folder. That is not practical since a development team wants to share a common dictionary. – JJD Sep 21 '17 at 13:07
  • @JJD The only configuration stored in the HOME folder of the user is the username used by this user. The dictionaries themselves are stored under the project and shared in the VCS. As stated in my reply, you don't need to have a single dictionary file for all developers; words from all dictionaries are combined. – yole Sep 21 '17 at 17:57
  • Using dictionaries with names that are different from my user name does not work for me with PyCharm Community 2020.1 – Stefan Jul 02 '20 at 09:23
  • I also tried to change the user.name property="all" to use all.xml instead of me.xml, but that did not work. – Stefan Jul 02 '20 at 09:38
  • 1
    @yole Absolutely agree that the name of the project-level dictionary where words are added **should be configurable per project per user**. Having to manually edit words on the dictionary is really inconvenient. C'mon, just make a setting in "Spelling"! It's not like merging a dictionary file has any risk of conflicts... specially if you discourage users from manually editing those files by adding this feature. This would improve user's privacy and control. – geekley Sep 18 '21 at 02:53
  • @yole Ideally, when "use single dictionary for saving words" is disabled, the editor should list all the available project-level dictionaries (including username.xml even if not exists yet) + app-level, instead of just giving the option between app-level and username.xml. You may want to keep different dictionaries per "domain" (like with code-spell-checker extension in vscode); just adding this simple feature would not only solve the privacy problem, but also help with this use case. – geekley Sep 18 '21 at 03:02
10

As a Git specific alternative to suggestion by Mark Vedder:

Depending on your situation, you might want to add the following or similar to your .gitignore file to keep the per developer dictionary files in the central git repo:

# Exclude IntelliJ files, they will be recreated from the build files.
.idea/*
# But keep dictionaries to have less false positives in spellcheck inspection.
!.idea/dictionaries
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69
  • Are you sure it works? Did not work for me, and I found this in gitignore docs: "It is not possible to re-include a file if a parent directory of that file is excluded" -- https://git-scm.com/docs/gitignore – Vadim Kotov Oct 25 '16 at 11:20
  • You can find more info about what I've mentioned here -- http://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder – Vadim Kotov Oct 25 '16 at 11:28
  • 1
    @VadimKotov Make sure you include the `*` on the `.idea/*`, otherwise it doesn't work. – Will Calderwood Apr 28 '20 at 11:15
6

In addition to @Yole's answer, you might also want to consider using option 2 (as listed in your question) along with option 1. A good strategy I've seen used is to use the system dictionaries (of option 2) for words common across all/most projects in your domain. Create a VCS project for just the dictionary file(s) and commit them. Have your developers check-out/clone that VCS project/repo on their PCs. Then set those dictionaries in their default settings (File > Other Settings > Default Settings) so they will be present for all new projects. Then have the developers set up a scheduled script (either via a cron job or Windows task scheduler) to regularly update those dictionaries. Developers will need to restart IDEA occasionally to get any new versions. But once those 'domain' word files get established, they will not change too frequently. And it saves you from having to add routine words to the project level dictionary.

Then use the project dictionary for project specific words.

When a new unknown word is encountered, developers can add it to the poject dictionary via Alt+Enter. If it's a word that is likely to occur across all projects (say the name of a company your company merged with or the name of a new library you will use a lot), they can take a moment and add it to the "all projects" dictionary and commit/push it.

Finally you may want to vote/watch these feature requests:

  • IDEA-26854 Spelling: doesn't reload changes .dic files
  • IDEA-121886 Improve ability to handle multiple spelling dictionaries
Javaru
  • 30,412
  • 11
  • 93
  • 70