Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: added initial documentation for user and file dictionaries
Elijah Potter1d00d3d4ab23
diff --git a/harper-ls/README.md b/harper-ls/README.mdindex 8835c6b4d..4b50315ed 100644--- a/harper-ls/README.md+++ b/harper-ls/README.md@@ -18,3 +18,45 @@ cargo install harper-lsRight now we only support using `nvim-lspconfig` to run Harper in Neovim.Refer to [the documentation](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#harper_ls) for more information.++## Dictionaries++`harper-ls` has three kinds of dictionaries: user, file-local, and static dictionaries.++### User Dictionary++Each user of `harper-ls` has their own dictionary, located in the following directories on each operating system:++| Operating System | Location |+| :--------------- | ---------------------------------------------: |+| Linux | `$XDG_CONFIG_HOME/harper-ls/` |+| MacOS | `$HOME/Library/Application Support/harper-ls/` |+| Windows | `{FOLDERID_LocalAppData}/harper-ls/` |++This dictionary is a simple word list in plain-text.+You can add and remove words at will.+You can add to the user dictionary with code actions on misspelled words.++### File-Local Dictionary++Sometimes, you'll encounter a word (or name) that is only valid within the context of a specific file.+In this case, you can use the code action that adds the word to the file-local dictionary.+Any words added to this dictionary will, like the name implies, only be included in the dictionary when performing corrections on the file at that specific path.++You can find the file-local dictionaries in the following directories on each operation system:++| Operating System | Location |+| :--------------- | -----------------------------------------------------------------------------------------------: |+| Linux | `$XDG_DATA_HOME/harper-ls/file_dictionaries` or `$HOME/.local/share/harper-ls/file_dictionaries` |+| MacOS | `$HOME/Library/Application Support/harper-ls/file_dictionaries` |+| Windows | `{FOLDERID_LocalAppData}/harper-ls/file_dictionaries` |++The format of these files is identical to user dictionaries.++### Static Dictionary++The static dictionary is built into the binary and is (as of now) immutable.+It contains almost all words you could possibly encounter.++I _do_ take pull requests or issues for adding words to the static dictionary.+It is composed of two files: `harper-core/dictionary.dict` and `harper-core/dictionary.dict`diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rsindex e5e9d763f..ba2c9763d 100644--- a/harper-ls/src/backend.rs+++ b/harper-ls/src/backend.rs@@ -129,10 +129,13 @@ impl Backend {async fn update_document(&self, url: &Url, text: &str) -> anyhow::Result<()> {let mut lock = self.doc_state.lock().await;- let doc_state = lock.entry(url.clone()).or_insert(DocumentState {++ // TODO: Only reset linter when underlying dictionaries change++ let mut doc_state = DocumentState {linter: LintSet::new().with_standard(self.generate_file_dictionary(url).await?),..Default::default()- });+ };doc_state.document = if let Some(extension) = url.to_file_path().unwrap().extension() {if let Some(ts_parser) =@@ -160,6 +163,8 @@ impl Backend {Document::new(text, Box::new(Markdown))};+ lock.insert(url.clone(), doc_state);+Ok(())}diff --git a/harper-ls/src/config.rs b/harper-ls/src/config.rsindex 56ac4db0b..2cfe09002 100644--- a/harper-ls/src/config.rs+++ b/harper-ls/src/config.rs@@ -12,7 +12,9 @@ impl Default for Config {fn default() -> Self {Self {user_dict_path: config_dir().unwrap().join("harper-ls/dictionary.txt"),- file_dict_path: data_local_dir().unwrap().join("harper-ls"),+ file_dict_path: data_local_dir()+ .unwrap()+ .join("harper-ls/file_dictionaries/"),}}}