Skip to content

Commit 9317765

Browse files
KJ7LNWEric Wheeler
andauthored
Fix: Missing or inconsistent syntax highlighting across UI components (RooCodeInc#3656)
* fix: Missing or inconsistent syntax highlighting across UI components - Change file listings to use 'shellsession' for terminal-like highlighting - Use 'markdown' for code definitions and instructions - Add file extension-based language detection for new files - Ensure consistent 'diff' highlighting for all diff content - Use 'xml' language for error messages - Make language property required in CodeAccordian - Set default fallback to 'txt' instead of undefined Fixes: RooCodeInc#3655 Signed-off-by: Eric Wheeler <[email protected]> * chore: make language property required in CodeBlock - Updated CodeBlockProps interface to make language property required - Updated mock implementation to match the interface change - Ensured CodeAccordian always provides a fallback language value Signed-off-by: Eric Wheeler <[email protected]> --------- Signed-off-by: Eric Wheeler <[email protected]> Co-authored-by: Eric Wheeler <[email protected]>
1 parent ad9c87a commit 9317765

File tree

4 files changed

+54
-58
lines changed

4 files changed

+54
-58
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useExtensionState } from "@src/context/ExtensionStateContext"
1313
import { findMatchingResourceOrTemplate } from "@src/utils/mcp"
1414
import { vscode } from "@src/utils/vscode"
1515
import { removeLeadingNonAlphanumeric } from "@src/utils/removeLeadingNonAlphanumeric"
16+
import { getLanguageFromPath } from "@src/utils/getLanguageFromPath"
1617
import { Button } from "@src/components/ui"
1718

1819
import { ToolUseBlock, ToolUseBlockHeader } from "../common/ToolUseBlock"
@@ -293,7 +294,7 @@ export const ChatRowContent = ({
293294
<CodeAccordian
294295
path={tool.path}
295296
code={tool.content ?? tool.diff}
296-
language={tool.tool === "appliedDiff" ? "diff" : undefined}
297+
language="diff"
297298
progressStatus={message.progressStatus}
298299
isLoading={message.partial}
299300
isExpanded={isExpanded}
@@ -341,6 +342,7 @@ export const ChatRowContent = ({
341342
<CodeAccordian
342343
path={tool.path}
343344
code={tool.diff}
345+
language="diff"
344346
progressStatus={message.progressStatus}
345347
isLoading={message.partial}
346348
isExpanded={isExpanded}
@@ -358,6 +360,7 @@ export const ChatRowContent = ({
358360
<CodeAccordian
359361
path={tool.path}
360362
code={tool.content}
363+
language={getLanguageFromPath(tool.path || "") || "log"}
361364
isLoading={message.partial}
362365
isExpanded={isExpanded}
363366
onToggleExpand={onToggleExpand}
@@ -403,6 +406,7 @@ export const ChatRowContent = ({
403406
</div>
404407
<CodeAccordian
405408
code={tool.content}
409+
language="markdown"
406410
isLoading={message.partial}
407411
isExpanded={isExpanded}
408412
onToggleExpand={onToggleExpand}
@@ -443,7 +447,7 @@ export const ChatRowContent = ({
443447
<CodeAccordian
444448
path={tool.path}
445449
code={tool.content}
446-
language="shell-session"
450+
language="shellsession"
447451
isExpanded={isExpanded}
448452
onToggleExpand={onToggleExpand}
449453
/>
@@ -463,6 +467,7 @@ export const ChatRowContent = ({
463467
<CodeAccordian
464468
path={tool.path}
465469
code={tool.content}
470+
language="markdown"
466471
isExpanded={isExpanded}
467472
onToggleExpand={onToggleExpand}
468473
/>
@@ -492,7 +497,7 @@ export const ChatRowContent = ({
492497
<CodeAccordian
493498
path={tool.path! + (tool.filePattern ? `/(${tool.filePattern})` : "")}
494499
code={tool.content}
495-
language="log"
500+
language="shellsession"
496501
isExpanded={isExpanded}
497502
onToggleExpand={onToggleExpand}
498503
/>
@@ -712,7 +717,7 @@ export const ChatRowContent = ({
712717
backgroundColor: "var(--vscode-editor-background)",
713718
borderTop: "none",
714719
}}>
715-
<CodeBlock source={`${"```"}plaintext\n${message.text || ""}\n${"```"}`} />
720+
<CodeBlock source={message.text || ""} language="xml" />
716721
</div>
717722
)}
718723
</div>

webview-ui/src/components/common/CodeAccordian.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CodeBlock from "./CodeBlock"
1111
interface CodeAccordianProps {
1212
path?: string
1313
code?: string
14-
language?: string | undefined
14+
language: string
1515
progressStatus?: ToolProgressStatus
1616
isLoading?: boolean
1717
isExpanded: boolean
@@ -29,7 +29,7 @@ const CodeAccordian = ({
2929
isFeedback,
3030
onToggleExpand,
3131
}: CodeAccordianProps) => {
32-
const inferredLanguage = useMemo(() => language ?? (path ? getLanguageFromPath(path) : undefined), [path, language])
32+
const inferredLanguage = useMemo(() => language ?? (path ? getLanguageFromPath(path) : "txt"), [path, language])
3333
const source = useMemo(() => code.trim(), [code])
3434
const hasHeader = Boolean(path || isFeedback)
3535

webview-ui/src/components/common/CodeBlock.tsx

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ minWidth: "max-content",
3030
interface CodeBlockProps {
3131
source?: string
3232
rawSource?: string // Add rawSource prop for copying raw text
33-
language?: string
33+
language: string
3434
preStyle?: React.CSSProperties
3535
initialWordWrap?: boolean
3636
collapsedHeight?: number
@@ -637,57 +637,48 @@ const CodeBlock = memo(
637637
ref={copyButtonWrapperRef}
638638
onMouseOver={() => updateCodeBlockButtonPosition()}
639639
style={{ gap: 0 }}>
640-
{language && (
641-
<LanguageSelect
642-
value={currentLanguage}
643-
style={{
644-
width: `calc(${currentLanguage?.length || 0}ch + 9px)`,
645-
}}
646-
onClick={(e) => {
647-
e.currentTarget.focus()
648-
}}
649-
onChange={(e) => {
650-
const newLang = normalizeLanguage(e.target.value)
651-
userChangedLanguageRef.current = true
652-
setCurrentLanguage(newLang)
653-
if (onLanguageChange) {
654-
onLanguageChange(newLang)
655-
}
656-
}}>
657-
{
658-
// Display original language at top of list for quick selection
659-
language && (
660-
<option
661-
value={normalizeLanguage(language)}
662-
style={{ fontWeight: "bold", textAlign: "left", fontSize: "1.2em" }}>
663-
{normalizeLanguage(language)}
664-
</option>
665-
)
640+
<LanguageSelect
641+
value={currentLanguage}
642+
style={{
643+
width: `calc(${currentLanguage?.length || 0}ch + 9px)`,
644+
}}
645+
onClick={(e) => {
646+
e.currentTarget.focus()
647+
}}
648+
onChange={(e) => {
649+
const newLang = normalizeLanguage(e.target.value)
650+
userChangedLanguageRef.current = true
651+
setCurrentLanguage(newLang)
652+
if (onLanguageChange) {
653+
onLanguageChange(newLang)
666654
}
667-
{
668-
// Display all available languages in alphabetical order
669-
Object.keys(bundledLanguages)
670-
.sort()
671-
.map((lang) => {
672-
const normalizedLang = normalizeLanguage(lang)
673-
return (
674-
<option
675-
key={normalizedLang}
676-
value={normalizedLang}
677-
style={{
678-
fontWeight:
679-
normalizedLang === currentLanguage ? "bold" : "normal",
680-
textAlign: "left",
681-
fontSize:
682-
normalizedLang === currentLanguage ? "1.2em" : "inherit",
683-
}}>
684-
{normalizedLang}
685-
</option>
686-
)
687-
})
688-
}
689-
</LanguageSelect>
690-
)}
655+
}}>
656+
<option
657+
value={normalizeLanguage(language)}
658+
style={{ fontWeight: "bold", textAlign: "left", fontSize: "1.2em" }}>
659+
{normalizeLanguage(language)}
660+
</option>
661+
{
662+
// Display all available languages in alphabetical order
663+
Object.keys(bundledLanguages)
664+
.sort()
665+
.map((lang) => {
666+
const normalizedLang = normalizeLanguage(lang)
667+
return (
668+
<option
669+
key={normalizedLang}
670+
value={normalizedLang}
671+
style={{
672+
fontWeight: normalizedLang === currentLanguage ? "bold" : "normal",
673+
textAlign: "left",
674+
fontSize: normalizedLang === currentLanguage ? "1.2em" : "inherit",
675+
}}>
676+
{normalizedLang}
677+
</option>
678+
)
679+
})
680+
}
681+
</LanguageSelect>
691682
{showCollapseButton && (
692683
<CodeBlockButton
693684
onClick={() => {

webview-ui/src/components/common/__mocks__/CodeBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react"
22

33
interface CodeBlockProps {
44
children?: React.ReactNode
5-
language?: string
5+
language: string
66
}
77

88
const CodeBlock: React.FC<CodeBlockProps> = () => <div data-testid="mock-code-block">Mocked Code Block</div>

0 commit comments

Comments
 (0)