Skip to content

feat(new-webui): Add JSON syntax highlighting for clp-s query results; Configure syntax based on storage engine.#973

Merged
davemarco merged 7 commits into
y-scope:mainfrom
davemarco:json
Jun 10, 2025
Merged

feat(new-webui): Add JSON syntax highlighting for clp-s query results; Configure syntax based on storage engine.#973
davemarco merged 7 commits into
y-scope:mainfrom
davemarco:json

Conversation

@davemarco

@davemarco davemarco commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

This PR should be merged after #967, since there is new support for determining clp-s vs. clp in that PR

Description

PR adds syntax highlighting for JSON. Before was specific for unstructured.
Screenshot 2025-06-06 at 4 16 32 PM

I also removed highlight js dependency and just switched to a theme supported by react syntax highligher.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Highlighted as json

Summary by CodeRabbit

  • Style
    • Updated syntax highlighting in log messages to use a new visual theme.
    • Syntax highlighting language is now selected automatically based on configuration.
  • Chores
    • Removed an unused dependency to improve package management.

@davemarco davemarco requested a review from a team as a code owner June 6, 2025 20:27
@davemarco davemarco requested a review from junhaoliao June 6, 2025 20:27
@coderabbitai

coderabbitai Bot commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes remove the "highlight.js" dependency from the client package and update the Message component to use a different syntax highlighting style and dynamic language selection based on configuration. No exported interfaces or public APIs were changed.

Changes

File(s) Change Summary
components/log-viewer-webui/client/package.json Removed "highlight.js" from dependencies.
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx Updated syntax highlighting: switched to "tomorrow" style, removed inline styles, and added dynamic language selection based on configuration.

Sequence Diagram(s)

sequenceDiagram
    participant Config
    participant MessageComponent
    participant SyntaxHighlighter

    MessageComponent->>Config: Import CLP_STORAGE_ENGINES, SETTINGS_STORAGE_ENGINE
    MessageComponent->>MessageComponent: Determine language (json or armasm)
    MessageComponent->>SyntaxHighlighter: Render with 'tomorrow' style and selected language
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c69d4cf and 1c826e9.

⛔ Files ignored due to path filters (1)
  • components/log-viewer-webui/client/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • components/log-viewer-webui/client/package.json (0 hunks)
  • components/log-viewer-webui/client/src/config/index.ts (1 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • components/log-viewer-webui/client/package.json
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx
  • components/log-viewer-webui/client/src/config/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (2)
components/log-viewer-webui/client/src/config/index.ts (1)

17-19: 🧹 Nitpick (assertive)

Consider using STREAM_TYPE constant for better readability.

The conditional logic is correct but could be more readable by referencing the STREAM_TYPE constant that's derived from this logic.

-const STREAM_TYPE = CLP_STORAGE_ENGINES.CLP === SETTINGS_STORAGE_ENGINE ?
-    "ir" :
-    "json";
+const STREAM_TYPE = SETTINGS_STORAGE_ENGINE === CLP_STORAGE_ENGINES.CLP ? "ir" : "json";

Likely an incorrect or invalid review comment.

components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx (1)

2-2: LGTM! Good improvement to syntax highlighting.

The change from a hardcoded style to the qtcreatorLight theme from react-syntax-highlighter is a good improvement that removes the dependency on highlight.js while maintaining consistent styling.

Also applies to: 45-45

CLP_S = "clp-s",
}

const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding runtime validation for the type assertion.

The type assertion as CLP_STORAGE_ENGINES assumes that settings.ClpStorageEngine will always be a valid enum value, but this could cause runtime issues if the settings file contains an unexpected value.

-const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;
+const SETTINGS_STORAGE_ENGINE = Object.values(CLP_STORAGE_ENGINES).includes(settings.ClpStorageEngine as CLP_STORAGE_ENGINES) 
+    ? settings.ClpStorageEngine as CLP_STORAGE_ENGINES 
+    : CLP_STORAGE_ENGINES.CLP; // Default fallback
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;
-const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;
+const SETTINGS_STORAGE_ENGINE = Object.values(CLP_STORAGE_ENGINES).includes(settings.ClpStorageEngine as CLP_STORAGE_ENGINES)
+ ? settings.ClpStorageEngine as CLP_STORAGE_ENGINES
+ : CLP_STORAGE_ENGINES.CLP; // Default fallback
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/config/index.ts at line 12, the code
uses a type assertion to cast settings.ClpStorageEngine to CLP_STORAGE_ENGINES
without runtime validation, which can cause issues if the value is invalid. Add
a runtime check to verify that settings.ClpStorageEngine is a valid member of
the CLP_STORAGE_ENGINES enum before assigning it to SETTINGS_STORAGE_ENGINE, and
handle invalid values appropriately, such as by throwing an error or falling
back to a default.

Comment on lines +47 to +51
language={
CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE ?
"json" :
"armasm"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider documenting the choice of "armasm" as the default language.

The conditional logic correctly selects "json" for CLP_S, but the choice of "armasm" as the default language for CLP seems unconventional for log data. Consider adding a comment explaining this choice or evaluating if a more generic language like "text" would be more appropriate.

                    language={
+                        // Use JSON highlighting for CLP_S, armasm for CLP intermediate representation
                        CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE ?
                            "json" :
                            "armasm"
                    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
language={
CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE ?
"json" :
"armasm"
}
language={
// Use JSON highlighting for CLP_S, armasm for CLP intermediate representation
CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE ?
"json" :
"armasm"
}
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx
around lines 47 to 51, add a comment explaining why "armasm" is chosen as the
default language when SETTINGS_STORAGE_ENGINE is not CLP_S. This clarifies the
rationale behind using "armasm" for log data and helps future maintainers
understand the decision. Alternatively, evaluate if using a more generic
language like "text" would be more suitable and update the code accordingly.

Comment on lines +6 to +9
import {
CLP_STORAGE_ENGINES,
SETTINGS_STORAGE_ENGINE,
} from "../.././../../../config";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

❓ Verification inconclusive

Verify the import path for the config module.

The import path ../.././../../../config appears to have an unusual number of relative directory navigations. Please verify this resolves to the correct config module location.


🏁 Script executed:

#!/bin/bash
# Description: Verify the config module import path is correct
# Expected: The path should resolve to components/log-viewer-webui/client/src/config/index.ts

# Find the config file location
fd "index.ts" --path "**/config/**"

# Check the actual file structure to verify the relative path
fd "index.tsx" --path "**/Message/**" --exec dirname {} | head -1 | xargs -I {} bash -c 'echo "Message component location: {}" && echo "Relative path from Message to config:" && realpath --relative-to="{}" "components/log-viewer-webui/client/src/config"'

Length of output: 726


Import path is valid but simplify the redundant segment

The import

import {
    CLP_STORAGE_ENGINES,
    SETTINGS_STORAGE_ENGINE,
} from "../.././../../../config";

correctly resolves to components/log-viewer-webui/client/src/config/index.ts, but the ./ is unnecessary. Please update it to:

-import {
-    CLP_STORAGE_ENGINES,
-    SETTINGS_STORAGE_ENGINE,
-} from "../.././../../../config";
+import {
+    CLP_STORAGE_ENGINES,
+    SETTINGS_STORAGE_ENGINE,
+} from "../../../../../config";

This small change improves readability without affecting functionality.

🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx
around lines 6 to 9, the import path for the config module includes an
unnecessary './' segment in "../.././../../../config". Remove the redundant './'
so the import path becomes "../../../../../config" to simplify and improve
readability without changing functionality.

junhaoliao
junhaoliao previously approved these changes Jun 9, 2025

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe this depends on #967 so let's merge 967 first

For the PR title, how about:

feat(new-webui): Add JSON syntax highlighting for clp-s query results; Configure syntax based on storage engine.

language={
CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE ?
"json" :
"armasm"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope of this PR - We should consider adding a custom language instead of reusing armasm since armasm is not directly related to logging

@coderabbitai submit an issue to track this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

@junhaoliao I've created a GitHub issue to track the suggestion about using a custom language for syntax highlighting instead of reusing armasm for logging data. The issue includes the context from this PR and discussion, and has been assigned to you as requested.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue to track the custom language improvement
gh issue create \
  --title "Consider adding custom language for syntax highlighting instead of reusing armasm" \
  --body "Currently, the syntax highlighter uses \`armasm\` as a fallback language for non-JSON log data, but \`armasm\` (ARM assembly) is not directly related to logging and may not provide optimal highlighting for log messages.

**Current behavior:**
- When \`CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE\`, JSON syntax highlighting is used
- Otherwise, \`armasm\` is used as the fallback language

**Suggested improvement:**
Consider implementing a custom language definition specifically tailored for log data or use a more appropriate existing language that better matches the structure of log messages.

**References:**
- Original PR: https://github.com/y-scope/clp/pull/973
- Discussion: https://github.com/y-scope/clp/pull/973#discussion_r2136170754

**Requested by:** @junhaoliao" \
  --assignee junhaoliao

Length of output: 962


@junhaoliao Perfect! I've successfully created GitHub issue #989 to track the suggestion about using a custom language for syntax highlighting instead of reusing armasm.

The issue has been:

  • ✅ Created with a descriptive title and detailed explanation
  • ✅ Assigned to you as requested
  • ✅ Includes references to this PR and discussion thread
  • ✅ Explains the current behavior and suggested improvement

You can view the issue at: #989

This will help track the improvement for future implementation while keeping it separate from the current PR scope.


🧬 Code Graph Analysis Results

Possibly relevant snippets from components/log-viewer-webui/client/src/config/index.ts

At line range 22-23:

CLP_STORAGE_ENGINES
SETTINGS_STORAGE_ENGINE

These constants are imported and used in the Message component to determine the syntax highlighting language. Specifically, the code checks if CLP_STORAGE_ENGINES.CLP_S equals SETTINGS_STORAGE_ENGINE to decide whether to use "json" or "armasm" as the language for syntax highlighting.


Possibly relevant snippet from components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/utils.ts

At line range 5-11:

export const highlighterCustomStyles: React.CSSProperties = {
    background: "none",
    border: "none",
    fontFamily: "inherit",
    margin: "0",
    padding: "0",
};

This object defines custom CSS styles applied to the SyntaxHighlighter component in the Message component to control its appearance, ensuring it inherits font styles and has no extra padding or borders.


These snippets provide context on the configuration constants controlling the syntax highlighting language choice and the styling applied to the syntax highlighter in the Message component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure i agree

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@davemarco

davemarco commented Jun 9, 2025

Copy link
Copy Markdown
Contributor Author

switch to "tomorrow" per @kirkrodrigues
Screenshot 2025-06-09 at 2 25 16 PM

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any thoughts on the previously proposed title?

feat(new-webui): Add JSON syntax highlighting for clp-s query results; Configure syntax based on storage engine.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx (1)

43-55: 🧹 Nitpick (assertive)

Lazy-load heavy syntax highlighter
react-syntax-highlighter can bloat the bundle. Consider dynamic import or React.lazy for the SyntaxHighlighter so it’s only loaded when needed.

♻️ Duplicate comments (2)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx (2)

6-9: Remove redundant segment in import path
The ./ in "../.././../../../config" is unnecessary. Simplify the import to improve readability without affecting functionality:

-import {
-    CLP_STORAGE_ENGINES,
-    SETTINGS_STORAGE_ENGINE,
-} from "../.././../../../config";
+import {
+    CLP_STORAGE_ENGINES,
+    SETTINGS_STORAGE_ENGINE,
+} from "../../../../../config";

47-51: Document fallback language choice
Falling back to "armasm" for non-JSON logs may confuse future maintainers. Add a comment explaining this choice or consider a more generic language like "text".

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c826e9 and 3d49ada.

📒 Files selected for processing (1)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx
🧬 Code Graph Analysis (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx (1)
components/log-viewer-webui/client/src/config/index.ts (2)
  • CLP_STORAGE_ENGINES (22-22)
  • SETTINGS_STORAGE_ENGINE (23-23)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-check (ubuntu-latest)
🔇 Additional comments (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx (1)

45-46: Verify default inline styling
By dropping useInlineStyles={false}, the highlighter now applies inline styles by default. Ensure this doesn’t conflict with your global CSS or AntD theming.

@@ -1,12 +1,15 @@
import SyntaxHighlighter from "react-syntax-highlighter";
import {tomorrow} from "react-syntax-highlighter/dist/esm/styles/hljs";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider making the theme configurable
Hardcoding the tomorrow style ties the component to one theme. To support future theming (e.g. dark mode), consider passing the style as a prop or using a context/provider.

🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/index.tsx
at line 2, the import of the hardcoded 'tomorrow' theme from
react-syntax-highlighter limits theming flexibility. Refactor the component to
accept the syntax highlighter style as a prop or obtain it from a
context/provider, removing the direct import of 'tomorrow'. This will enable
dynamic theming such as dark mode in the future.

@davemarco davemarco changed the title feat(new-webui): Add json syntax highlighting for clp-s feat(new-webui): Add JSON syntax highlighting for clp-s query results; Configure syntax based on storage engine. Jun 10, 2025
@davemarco davemarco merged commit 58b839a into y-scope:main Jun 10, 2025
8 checks passed
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 2026
…; Configure syntax based on storage engine. (y-scope#973)

Co-authored-by: Marco <david.marcovitch@yscope.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants