A Language Server Protocol (LSP) implementation that provides spell checking using Hunspell dictionaries.
- Real-time spell checking for text documents via LSP
- Support for multiple languages through Hunspell dictionaries
- Language specification via special comments in documents
- Full synchronization with text changes
- Code Actions: Automatic correction suggestions with quick-fix actions
- Rust toolchain (2024 edition or later)
- Hunspell library and development headers
- Hunspell dictionaries for the languages you want to use
Ubuntu/Debian:
# Install Hunspell development library
sudo apt install libhunspell-dev
# Install dictionaries for the languages you need
sudo apt install hunspell-en-us hunspell-de-de-frami hunspell-fr-fr hunspell-nlArch Linux:
sudo pacman -S hunspell hunspell-en-us hunspell-de hunspell-fr hunspell-nlSome Hunspell dictionaries (particularly German, French, and Dutch) may be distributed in ISO-8859-1 encoding. While the modern hunspell-rs library handles UTF-8 properly, you may need to convert dictionaries if you see encoding issues.
If you encounter encoding problems:
# Convert German dictionaries from ISO-8859-1 to UTF-8
iconv -f ISO-8859-1 -t UTF-8 /usr/share/hunspell/de_DE_frami.aff > /tmp/de_DE_frami.aff
iconv -f ISO-8859-1 -t UTF-8 /usr/share/hunspell/de_DE_frami.dic > /tmp/de_DE_frami.dic
sudo cp /tmp/de_DE_frami.* /usr/share/hunspell/If you need to restore original dictionaries:
sudo apt install --reinstall hunspell-de-de-frami hunspell-fr hunspell-nlcargo buildThe compiled binary will be available at target/debug/hunspell-lsp.
The LSP server communicates via stdin/stdout. To use it, you need to configure your editor to launch the binary:
/path/to/hunspell-lspSpecify the language for spell checking by adding a lang: pattern anywhere in your document:
Format: lang: language_code
Examples:
lang: en_US(American English)lang: de_DE(German)lang: fr_FR(French)lang: es_ES(Spanish)
How it works:
- Place
lang: xx_YYanywhere in your document (comments or plain text) - The first
lang:pattern found is used - If no language is specified, defaults to
en_US
Example usage:
In a Markdown file:
<!-- lang: de_DE -->
Dies ist ein deutscher Text.
lang: en_US
This is English text.In a Python file:
# lang: en_GB
def hello_world():
print("Hello World")In plain text:
lang: de_DE
Dieser Text wird auf Deutsch geprüft.
The LSP server provides intelligent correction suggestions:
Smart Code Action Behavior:
- Cursor on misspelled word → Shows corrections for that word only
- Cursor elsewhere on line → Shows corrections for all misspelled words in the line
- Severity → Hints (not warnings) for less intrusive editing
How it works:
- Misspelled words are highlighted with hints
- Hover over the word to see Hunspell suggestions
- Apply quick fixes to automatically replace misspelled words
- Multiple suggestions provided when available
Example diagnostic message:
Possibly misspelled: dksadf. Suggestions: does, dad, sad, dads
Code Action Examples:
- On word:
"--> 'does'"(shows only the suggestion) - On line:
"'ihc' --> 'ich'"(shows word and suggestion)
For a JavaScript file:
// lang: en_US
function hello() {
console.log("Hello"); // Spell checking enabled
}Add to your ~/.config/helix/languages.toml:
[language-server.hunspell-lsp]
command = "/home/user/.cargo/bin/hunspell-lsp"
[[language]]
name = "markdown"
language-servers = ["hunspell-lsp"]
[[language]]
name = "text"
language-servers = ["hunspell-lsp"]Using smart code actions:
- Move cursor to misspelled word → press code action key (typically
space+ain Helix) - Move cursor elsewhere on line → see all misspelled words in line
The server looks for Hunspell dictionaries in /usr/share/hunspell/ by default. Each language requires two files:
<lang>.aff(affix file)<lang>.dic(dictionary file)
For example, for American English:
/usr/share/hunspell/en_US.aff/usr/share/hunspell/en_US.dic
- The LSP server receives document changes from the editor
- Extracts the language specification from comments
- Loads the appropriate Hunspell dictionary
- Checks each word in the document
- Publishes diagnostics (warnings) for misspelled words back to the editor
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.