drahnr / cargo-spellcheck

Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar
Apache License 2.0
314 stars 32 forks source link

How to add words? #293

Open ehuss opened 1 year ago

ehuss commented 1 year ago

How to add words interactively?

I'm trying to figure out how to add words to a dictionary (or at least to ignore the same word). Most spell checkers I am used to have an "Add to Dictionary" option or an "Ignore" option that will ignore the same word for the rest of the document. None of the options in the cargo spellcheck fix menu seem to provide that:

y - apply this suggestion
n - do not apply the suggested correction
q - quit; do not stage this hunk or any of the remaining ones
d - do not apply this suggestion and skip the rest of the file
g - select a suggestion to go to
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
e - manually edit the current hunk
? - print help

How to manually set up a dictionary?

Assuming it doesn't support adding words automatically, I tried several things to set up a custom dictionary. However, I found several roadblocks.

  1. Add to extra_dictionaries in the config mentioned at https://github.com/drahnr/cargo-spellcheck/blob/master/docs/configuration.md. I created .config/spellcheck.toml with the contents:
[Hunspell]
extra_dictionaries = ["spelling.txt"]

Got error: 0: Could not find extra dictionary spelling.txt in any of the search paths

  1. Tried extra_dictionaries = ["./spelling.txt"], go the same error.

  2. Tried with an absolute path, got 0: Failed to find any en_US.dic / en_US.aff in any search dir or no search provided

  3. After lots of messing around, figured out that creating a table disabled the default settings, so I had to add:

[Hunspell]
extra_dictionaries = ["/path/to/spelling.txt"]
use_builtin = true

Got an error:

   0: First line of extra dictionary must a number, but is: >foobar<
   1: invalid digit found in string
  1. I thought the extra dictionaries would be a "personal dictionary" according to the hunspell docs, which says it should be a text file with words. But apparently it is a .dic file. I added a random number at the top of the file, and was able to progress.

  2. However, now after each word, I have to stop, edit the file, restart cargo spellcheck (which takes a long time to start up).

I think I am missing something fundamental, or maybe I am very confused?

drahnr commented 1 year ago

It's a missing feature, to interactively modify the dictionary. Happy to review a PR to enhance the UI on it.

@ehuss I'd really appreciate a PR on the docs from a first-time user and what would have helped you to avoid you tripping up issue to issue.

dpc commented 1 year ago

@ehuss Thank you for your details post. I was able to get it working

> cat .config/spellcheck.toml 
[Hunspell]
use_builtin = true
skip_os_lookups = false
search_dirs = [ "." ]
extra_dictionaries = [ "spellcheck.dic" ]
> cat .config/spellcheck.dic 
1000
config
tx

I would like to confirm that the current config setup is not ideal.