Repository navigation
fix: color a code block of the documentation by the TextMate grammar of its own language - #2086
Merged
Conversation
…of its own language When IntelliJ has no language for the language of a code block, the TextMate grammar of the file whose documentation it is came first. So ```python in the documentation of a Rust file was colored by the rules of Rust, and its comments weren't gray. The language of the code block now comes first, also when its name isn't a file extension, as rust for .rs or python for .py, and the grammar of the file is used for a code block whose language has none, as before.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2086 +/- ##
==========================================
+ Coverage 50.24% 50.32% +0.07%
==========================================
Files 816 816
Lines 33699 33730 +31
Branches 6935 6934 -1
==========================================
+ Hits 16931 16973 +42
+ Misses 14127 14110 -17
- Partials 2641 2647 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #557.
What
#557's case works on
main: in the documentation of a Rust file, the//comments of a```rustcode block are gray, as in the editor. But when IntelliJ has no language for the language of a code block, LSP4IJ colors it with a TextMate grammar, and took the grammar of the file whose documentation it is first:```python#comments aren't gray```python```rust```pythonThe language of the code block was used only when the file has no grammar, and only as a file extension, so
pythonandrust, which aren't ones, found nothing unless a language server's mapping gave them an extension.Change
TextMateHighlighterHelper.findLanguageDescriptortakes the grammar of the code block's language first:ts;rustfor.rs,pythonfor.py,typescriptfor.ts,shellscriptandbashfor.sh, and so on. The names are compared in lower case.The grammar of the file comes after, for a code block without a language, as before, and for one whose language has no grammar, which it colored before too. Code blocks whose language IntelliJ has, as Java, are colored by its lexer, as before.
Test
MarkdownConverterWithPsiFileTest.testACodeBlockIsColoredByTheTextMateGrammarOfItsLanguage: a```pythoncode block renders the same in the documentation of a Rust file and of a text file as in that of a Python file, and a```rustone the same in that of a text file as in that of a Rust file. It compares the renderings with each other, not with colors, which differ between IntelliJ versions. Without the change, the Python code block in the documentation of a Rust file differs.testACodeBlockOfALanguageWithoutAGrammarIsColoredByTheGrammarOfTheFile: a code block of a language without a grammar renders as one without a language, by the grammar of the file, as before.