-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[JEWEL-741] Use TextMate as Fallback for Languages Without Parsers #3171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[JEWEL-741] Use TextMate as Fallback for Languages Without Parsers #3171
Conversation
47b2042 to
467987b
Compare
platform/jewel/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/code/MimeType.kt
Show resolved
Hide resolved
...ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/code/highlighting/CodeAnnotator.kt
Show resolved
Hide resolved
platform/jewel/ide-laf-bridge/src/main/resources/intellij.platform.jewel.ideLafBridge.xml
Outdated
Show resolved
Hide resolved
...rc/test/kotlin/org/jetbrains/jewel/bridge/code/highlighting/LexerBasedCodeHighlighterTest.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ide-laf-bridge/intellij.platform.jewel.ideLafBridge.iml
Outdated
Show resolved
Hide resolved
514626f to
765abbf
Compare
...les/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/ComponentShowcaseTab.kt
Outdated
Show resolved
Hide resolved
.../core/src/main/kotlin/org/jetbrains/jewel/markdown/rendering/DefaultMarkdownBlockRenderer.kt
Outdated
Show resolved
Hide resolved
I always use the language name personally lol... maybe we should still keep a lang name -> extension that, while it won't cover all cases, at least should cover the ones the IDE supports out of the box? |
|
@rock3r I mean, if that's the case then I think we wouldn't even need to call |
|
That wouldn't work, as we would lose semantic highlighting if we only relied on textmate bundles. I'll finish reviewing asap and will add more context :) |
b7c2f10 to
e93bbe0
Compare
platform/jewel/ide-laf-bridge/intellij.platform.jewel.ideLafBridge.iml
Outdated
Show resolved
Hide resolved
platform/jewel/ide-laf-bridge/intellij.platform.jewel.ideLafBridge.iml
Outdated
Show resolved
Hide resolved
...undation/src/main/kotlin/org/jetbrains/jewel/foundation/code/highlighting/CodeHighlighter.kt
Show resolved
Hide resolved
...undation/src/main/kotlin/org/jetbrains/jewel/foundation/code/highlighting/CodeHighlighter.kt
Outdated
Show resolved
Hide resolved
...ge/src/main/kotlin/org/jetbrains/jewel/bridge/code/highlighting/LexerBasedCodeHighlighter.kt
Outdated
Show resolved
Hide resolved
platform/jewel/ide-laf-bridge/src/main/resources/intellij.platform.jewel.ideLafBridge.xml
Outdated
Show resolved
Hide resolved
...rc/test/kotlin/org/jetbrains/jewel/bridge/code/highlighting/LexerBasedCodeHighlighterTest.kt
Outdated
Show resolved
Hide resolved
platform/jewel/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/MarkdownBlock.kt
Outdated
Show resolved
Hide resolved
...les/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/ComponentShowcaseTab.kt
Outdated
Show resolved
Hide resolved
...in/kotlin/org/jetbrains/jewel/bridge/code/highlighting/codefence/CodeFenceLanguageAliases.kt
Show resolved
Hide resolved
...in/kotlin/org/jetbrains/jewel/bridge/code/highlighting/codefence/CodeFenceLanguageAliases.kt
Show resolved
Hide resolved
...in/kotlin/org/jetbrains/jewel/bridge/code/highlighting/codefence/CodeFenceLanguageAliases.kt
Show resolved
Hide resolved
...in/kotlin/org/jetbrains/jewel/bridge/code/highlighting/codefence/CodeFenceLanguageAliases.kt
Outdated
Show resolved
Hide resolved
...in/kotlin/org/jetbrains/jewel/bridge/code/highlighting/codefence/CodeFenceLanguageGuesser.kt
Outdated
Show resolved
Hide resolved
platform/jewel/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/MarkdownBlock.kt
Outdated
Show resolved
Hide resolved
...in/kotlin/org/jetbrains/jewel/bridge/code/highlighting/codefence/CodeFenceLanguageGuesser.kt
Outdated
Show resolved
Hide resolved
...idge/src/main/kotlin/org/jetbrains/jewel/bridge/code/highlighting/IntelliJCodeHighlighter.kt
Show resolved
Hide resolved
...idge/src/main/kotlin/org/jetbrains/jewel/bridge/code/highlighting/IntelliJCodeHighlighter.kt
Outdated
Show resolved
Hide resolved
...l/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessor.kt
Outdated
Show resolved
Hide resolved
.../core/src/main/kotlin/org/jetbrains/jewel/markdown/rendering/DefaultMarkdownBlockRenderer.kt
Outdated
Show resolved
Hide resolved
platform/jewel/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/code/MimeType.kt
Outdated
Show resolved
Hide resolved
dbdc3e9 to
cb690f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
e5243ea to
245c2d8
Compare
|
We'll punt this to 0.31, since we have to figure out why the test fails. |
dd92894 to
1771489
Compare
1395de1 to
c47f3de
Compare
c90d668 to
91c65fc
Compare
9d0a9b0 to
1207b4c
Compare
37e70d7 to
e329d2b
Compare
Added necessary code logic to actually use the language identifier from a code block and use that to find a plugin that can add semantic highlighting or token-based if no plugin is found by delegating to TextMate move fromMimeTypeString to DefaultMarkdownBlockRenderer add suppress to MarkdownProcessor Fix coroutines error + trying to add textmate plugin turn java test to html add Markdown tab to JewelDemoToolWindowFactory
e329d2b to
166689f
Compare
Disclaimer
This PR can only ever be merged when it's safe to bump the IDEA version to 253
Problem
Our syntax highlighting code for Markdown code blocks currently only highlights code that the IDE has a plugin that supports it. So, if you open PyCharm for instance, it'll render python code blocks but not Kotlin. The idea here is to fallback to using TextMate to highlight code in such cases.
Solution
Instead of relying on the
MimeTypeclass, we now useCodeFenceLanguageGuesser.guessLanguageForInjection()that finds a plugin that provides a syntax highlighting for a given language. The cool thing about this class is that it knows thatkt,ktsandkotlinare all related to the Kotlin language. This means we don't need to keep adding mime types toMimeTypejust to map theinfopart of a code block to a given language.If
CodeFenceLanguageGuesseris unable to find a corresponding plugin, then we resort to TextMate. The caveat here is that if the code block is declared as:TextMate won't be able to highlight the code, since the file we provide to it will have the extension
.rubyinstead of.rb.Personally, I don't think this is a big deal since usually code blocks use the file extension instead of the programming language name, but it's valid to know about this current limitation. The plus side is that we don't have to map a bunch of programming languages in
MimeTypejust for such cases.Changes
MimeTypeto highlight code.MimeTypeitself, though I'm 90% sure it's best to do so.MimeType.FencedCodeBlockInfothat hascodeandinfoas parameters instead ofcodeandmimeTypeas is the case withFencedCodeBlock. The name however is kinda lame.LexerBasedCodeHighlightera bit to delegate the actual highlighting code to a new class calledCodeAnnotator.LexerBasedCodeHighlightercode to mirror the logic presented in the Solution section of this description.ComponentShowcaseTab.kt.LexerBasedCodeHighlighterandCodeAnnotatorMimeType.displayName()text/kotlin role=gradlesince thenormalizeStringcall never returned the base name (in this case,text/kotlin) to fetch the correct display name in thewhenblock.Evidences
Release Notes
mimeType: MimeType?parameter name fromFencedCodeBlockclass was changed tolanguage: String?, which takes the raw string for the code block language identifier. This won't introduce binary nor behavioural changes sinceMimeTypeis a value class that is seen asString?by the compiler.New features
Bug fixes
displayNamewasn't returning the correct display name for mime types that also defined aroleDeprecated API
MimeTypevalue class has been deprecated, along with all of its functions, variables and extensions.CodeHighlighter.highlight(code: String, mimeType: MimeType?)has been deprecated. Please usehighlight(code: String, language: String).