Add a spell checker as "extension". #14389
Replies: 4 comments 17 replies
-
A spell checker is vastly different from a code formatter. A code formatter needs knowledge about the structure of the language it targets, a spell checker does not. A spell checker can target any source files from any language without requiring any specific support for languages while a code formatter is usually tied to a certain language. As such this is very much out of scope for rust-analyzer and would be better served as its own extension |
Beta Was this translation helpful? Give feedback.
-
No I am not |
Beta Was this translation helpful? Give feedback.
-
Hi @Veykril, I researched about the subject a bit more, and I am still not totally conviced that this is really out of scope... @matklad seems to think that an ideal spell checker for code should be aware of the language (comment here and here). Also looking more into Typos, it seems to be language aware at some extend (see They already discuss the idea to integrate LSP and spellcheckers. Typos is a mature tool, past 1.0, has many features, differenciates between identifiers and words, and support several outputs formats, including json. I really feel that it can improve the devlopper experience and it really seems that it would not even be that hard to plug this into r-a, all what the spell checker needs, is to be fed, which r-a does already for rustfmt, cargo-check and cargo-clippy, and the outputs needs to be understood by r-a to know what to underlines in the IDE and provide the fix suggestions in the IDE, exactly like with the linter. So if r-a has already a specific format that it expect from the linter, why not simply use the same for Typos ? I would like to hear what @matklad think of this. Please think of it for a couple of days. I really think it would be a great feature that cost near to nothing to r-a and would improve dev experience. After I will close this I promess. |
Beta Was this translation helpful? Give feedback.
-
Some thoughts:
That's the general design principle for features in rust-analyzer:
For spell checker, a significant chunk of the logic indeed belongs to rust-analyzer. Specifically, rust-analyzer should:
I think adding the following API would make sense: struct SpellWord {
text: String,
range: TextRange
}
impl Analysis {
/// Returns the list of words for spell-checking.
/// Note that this returns strings and not just ranges, because the value of
/// the word to spell-check might differ from the text at range due to escaping.
pub fn spell_words(&self, file_id: FileId) -> Vec<SpellWord>
/// Correct spelling (this might trigger rename refactor).
pub fn correct_spelling(&self, file_id: FileId, word: SpellWord, correction: String) -> SourceChange
} Implementaiton wise, I think to be pedantically correct we need to run this on macro-expanded code, but I think it'd be more robust to restrict this feature to be based strictly on the syntax. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Now, we have a code formater with
rustfmt
, we have a linter withcargo check
orcargo clippy
, why not a spell checker?A spell checker sounds like an easy addition, it's basically just a linter specialize in spelling.
I know a spell checker sounds a bit out of scope for Rust Analyzer, but is it really ? I mean we do have a formater already, having code well formatted help with consistency and to focus on the logic instead of the aesthetic, I would argue that the same holds for spelling.
Typos is a source code spell checker written in Rust, it supports several interfaces, file,
stdin
tostdout
and--format json
.Its design choice is described here.
Instead of having Typos to make it's own LSP (if it's even relevant, as I heard that editors will not work with multiple LSP servers for one language, but could not confirm), or having several custom plugging for each IDE, it could instead work like a "linter supplier" to existing LSP, such as Rust Analyzer to start with.
What would it requires from Typos to make it work with Rust Analyzer and is it simple enough/possible for Rust Analyzer to add a spell checker source too ?
(Also I hope this is the right place to open this conversation, if needed, I can open an issue "feature request" instead)
(Mention to crate-ci/typos#263 and @epage)
Beta Was this translation helpful? Give feedback.
All reactions