Open ordian opened 4 years ago
The relevant bit of code to look at is https://github.com/rust-analyzer/rust-analyzer/blob/7a9ba1657daa9fd90c639dcd937da11b4f526675/crates/ra_ide/src/syntax_highlighting.rs#L473-L510
Well, that's the relevant bit of code just for syntax highlighting, right? For proper analysis, completion etc. this gets even more interesting/fun :smile:
(Conversely, completion in ra_fixture
parameters would be cool, if not that useful... And a problem if the fixture is a test for a crash...)
That's another use case for hypothetical, -1 durability things in salsa btw.
Hmm doctests don't need to be hypothetical though, right? They could just be normal HIR files, or am I missing something? (Kind of similar to macros)
Hm, I guess we could make them real files, but I'd rather avoid that. Like, we don't want to bust caches when we add an impl
to a doc test. More generally, they feel like they should be something which is processed only after everything else is fully analyzed.
Well, I guess this is rather hypothetical anyway currently :thinking:
looks like this can be closed?
Was completion, type resolution, etc implemented? As far as I see, only syntax highlighting was (which is great btw, thank you!).
was #4683 also supposed to work with inner doctests? e.g.: is missing syntax highlighting here intended?
That should ideally work but doesn't due to the way its currently implemented, see https://github.com/rust-analyzer/rust-analyzer/issues/6873.
I am not sure if I missed something, but to me, it seems like #6873 only discusses block comments, but line comments don't work either for me.
Oh sorry, I misunderstood that. I'm a bit confused though because inner line doc comment highlighting works for me 🤔
Do you have Semantic Highlighting enabled? Without that Doccomment highlighting injection won't work, that is your theme has to support semantic highlighting.
Oh, that's my fault - I didn't realise that whether it is enabled or not is by default dependant on the selected theme.
After setting "editor.semanticHighlighting.enabled": true
everything works as expected.
Hello, Someone knows the steps (or where to look) for implementing completion in doctests ? Maybe just some hints. Thanks
I don't think we have a clear view on how we want to achieve this yet
I think a good workaround is implementing a proc macro that generates the doctests comment from source code. I did this in https://gist.github.com/mohe2015/84725cc7b60040afe2d44fe03a9d5eef. The advantage also is that you don't need to handle the weird /// at the start of every line and in my opinion it just looks nicer. Also line number information seems to be more correct in normal tests than in doctests.
Edit: I hope I have now improved it so it plays nicely with rust-analyzer.
I'm interested in this if it is planned to include refactoring, i.e. if I'm renaming a function/struct in my code base that the change also gets propagated to docstrings
Maybe by pretending a doctest is a file somehow ? I'm really not familiar with rust analyzer internals, would be curious to know more about this topic
Would it be possible to implement this the same way normal code is treated? Rust-analyzer is so useful, it's hugely noticeable to not have on doctests (which are simultaneously awesome usage examples, unit tests, and enablers of compile_fail) ... i'd love to see rust-analyzer's feedback on doctest code, doctests are great, more doctest driven development could help the community a lot
With syntax highlighting, completion, etc. See https://github.com/intellij-rust/intellij-rust/pull/3144.