Use IDEA code highlighting functionality#922
Conversation
c6c1d04 to
83af629
Compare
WalkthroughReplaces the previous highlights system in the IDEA plugin with a HighlightedCode-based approach: removes the highlightsCore dependency and the KtCodeViewer component; adds CodeHighlight utilities (rememberCodeHighlight, HighlightedCode value class, underline DSL) and an EditorText composable; updates call sites and function signatures to accept HighlightedCode and adjusts previews to use ProjectPreviewTheme. The changelog gains an Unreleased entry. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kt (1)
25-29: Preview doesn't demonstrateEditorTextfunctionality.The preview renders a plain
Textcomponent instead of using theEditorTextcomposable it's meant to showcase. However, sincerememberCodeHighlightrequiresLocalProjectcontext (provided byProjectPreviewTheme), this preview would need to be updated to useProjectPreviewThemelike other previews in this PR.♻️ Suggested fix
+import io.github.composegears.valkyrie.jewel.highlight.rememberCodeHighlight + `@Preview` `@Composable` -private fun EditorTextPreview() = PreviewTheme(alignment = Alignment.Center) { - Text(text = "editor text style") +private fun EditorTextPreview() = ProjectPreviewTheme(alignment = Alignment.Center) { + EditorText(code = rememberCodeHighlight(text = "val x: Int = 42")) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kt` around lines 25 - 29, The EditorTextPreview currently renders a plain Text instead of using the EditorText composable and lacks the LocalProject context required by rememberCodeHighlight; update the preview function EditorTextPreview to wrap its content in ProjectPreviewTheme (like other previews in this PR) so LocalProject is provided, and instantiate EditorText (not Text) with an appropriate sample code string and any required params so rememberCodeHighlight can run in preview.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kt`:
- Around line 24-61: The underline end index is off-by-one because addStyle
expects an exclusive end; update the styling loop in rememberCodeHighlight to
use range.endInclusive + 1 (or range.last + 1) when calling addStyle for each
entry in dsl.ranges (from UnderlineDsl), and clamp the computed end to the
annotated string length to avoid out-of-bounds indices when building the
AnnotatedString with SpanStyle.
---
Nitpick comments:
In
`@tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kt`:
- Around line 25-29: The EditorTextPreview currently renders a plain Text
instead of using the EditorText composable and lacks the LocalProject context
required by rememberCodeHighlight; update the preview function EditorTextPreview
to wrap its content in ProjectPreviewTheme (like other previews in this PR) so
LocalProject is provided, and instantiate EditorText (not Text) with an
appropriate sample code string and any required params so rememberCodeHighlight
can run in preview.
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
tools/idea-plugin/CHANGELOG.mdtools/idea-plugin/build.gradle.ktstools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeTooltip.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/KtCodeViewer.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/common/CodeTooltipHeader.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/common/IconPackEditor.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/settings/tabs/generator/GeneratorSettingsScreen.kt
💤 Files with no reviewable changes (2)
- tools/idea-plugin/build.gradle.kts
- tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/KtCodeViewer.kt
ac13252 to
9275c61
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kt (1)
25-29: Preview does not exercise theEditorTextcomposable.The preview renders a plain
Textwith a hardcoded string instead of using theEditorTextcomposable withrememberCodeHighlight. This means the actual rendering path isn't being previewed. Additionally, other files in this PR useProjectPreviewTheme(which providesLocalProject), but this preview usesPreviewTheme.Since
rememberCodeHighlightrequiresLocalProject.current(perCodeHighlight.kt), usingProjectPreviewThemewould be necessary to properly previewEditorText.Suggested fix
`@Preview` `@Composable` -private fun EditorTextPreview() = PreviewTheme(alignment = Alignment.Center) { - Text(text = "editor text style") +private fun EditorTextPreview() = ProjectPreviewTheme(alignment = Alignment.Center) { + EditorText(code = rememberCodeHighlight(text = "val example: String = \"Hello\"")) }Also update the import:
-import io.github.composegears.valkyrie.jewel.tooling.PreviewTheme +import io.github.composegears.valkyrie.jewel.tooling.ProjectPreviewTheme🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kt` around lines 25 - 29, The preview currently renders a plain Text instead of exercising EditorText and doesn't provide LocalProject; update EditorTextPreview to wrap its content in ProjectPreviewTheme (so LocalProject is available) and call EditorText using rememberCodeHighlight with a sample code string to exercise the actual rendering path (keep the PreviewTheme import replaced by ProjectPreviewTheme import). Ensure you reference EditorTextPreview, EditorText, rememberCodeHighlight, ProjectPreviewTheme and LocalProject when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kt`:
- Around line 25-29: The preview currently renders a plain Text instead of
exercising EditorText and doesn't provide LocalProject; update EditorTextPreview
to wrap its content in ProjectPreviewTheme (so LocalProject is available) and
call EditorText using rememberCodeHighlight with a sample code string to
exercise the actual rendering path (keep the PreviewTheme import replaced by
ProjectPreviewTheme import). Ensure you reference EditorTextPreview, EditorText,
rememberCodeHighlight, ProjectPreviewTheme and LocalProject when making the
change.
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
tools/idea-plugin/CHANGELOG.mdtools/idea-plugin/build.gradle.ktstools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeTooltip.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/KtCodeViewer.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/common/CodeTooltipHeader.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/common/IconPackEditor.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/settings/tabs/generator/GeneratorSettingsScreen.kt
💤 Files with no reviewable changes (2)
- tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/KtCodeViewer.kt
- tools/idea-plugin/build.gradle.kts
✅ Files skipped from review due to trivial changes (1)
- tools/idea-plugin/CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (2)
- tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/common/CodeTooltipHeader.kt
- tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kt
9275c61 to
ff30bc6
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kt (1)
33-35: Consider addingprojectas a remember key.If the
projectinstance ever changes during the composable's lifecycle, the cachedcodeHighlighterwould become stale. While this is unlikely in typical usage, addingprojectas a key would make the code more defensive.♻️ Optional: Add project as remember key
- val codeHighlighter = remember { CodeHighlighterFactory.getInstance(project).createHighlighter() } + val codeHighlighter = remember(project) { CodeHighlighterFactory.getInstance(project).createHighlighter() }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kt` around lines 33 - 35, The remember block that creates codeHighlighter should include the current project as a key so the cached highlighter is recreated if LocalProject.current changes; update the remember usage around CodeHighlighterFactory.getInstance(project).createHighlighter() to pass project as the key (i.e., remember(project) { ... }) so codeHighlighter is always valid for the current LocalProject.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kt`:
- Around line 33-35: The remember block that creates codeHighlighter should
include the current project as a key so the cached highlighter is recreated if
LocalProject.current changes; update the remember usage around
CodeHighlighterFactory.getInstance(project).createHighlighter() to pass project
as the key (i.e., remember(project) { ... }) so codeHighlighter is always valid
for the current LocalProject.
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
tools/idea-plugin/CHANGELOG.mdtools/idea-plugin/build.gradle.ktstools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeHighlight.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/CodeTooltip.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/KtCodeViewer.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/common/CodeTooltipHeader.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/mode/iconpack/common/IconPackEditor.kttools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/settings/tabs/generator/GeneratorSettingsScreen.kt
💤 Files with no reviewable changes (2)
- tools/idea-plugin/build.gradle.kts
- tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/highlight/KtCodeViewer.kt
🚧 Files skipped from review as they are similar to previous changes (3)
- tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/settings/tabs/generator/GeneratorSettingsScreen.kt
- tools/idea-plugin/CHANGELOG.md
- tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/jewel/EditorText.kt
📝 Changelog
If this PR introduces user-facing changes, please update the relevant Unreleased section in changelogs: