Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions webview-ui/src/components/chat/ChatRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useExtensionState } from "@src/context/ExtensionStateContext"
import { findMatchingResourceOrTemplate } from "@src/utils/mcp"
import { vscode } from "@src/utils/vscode"
import { removeLeadingNonAlphanumeric } from "@src/utils/removeLeadingNonAlphanumeric"
import { getLanguageFromPath } from "@src/utils/getLanguageFromPath"
import { Button } from "@src/components/ui"

import { ToolUseBlock, ToolUseBlockHeader } from "../common/ToolUseBlock"
Expand Down Expand Up @@ -291,7 +292,7 @@ export const ChatRowContent = ({
<CodeAccordian
path={tool.path}
code={tool.content ?? tool.diff}
language={tool.tool === "appliedDiff" ? "diff" : undefined}
language="diff"
progressStatus={message.progressStatus}
isLoading={message.partial}
isExpanded={isExpanded}
Expand Down Expand Up @@ -339,6 +340,7 @@ export const ChatRowContent = ({
<CodeAccordian
path={tool.path}
code={tool.diff}
language="diff"
progressStatus={message.progressStatus}
isLoading={message.partial}
isExpanded={isExpanded}
Expand All @@ -356,6 +358,7 @@ export const ChatRowContent = ({
<CodeAccordian
path={tool.path}
code={tool.content}
language={getLanguageFromPath(tool.path || "") || "log"}
isLoading={message.partial}
isExpanded={isExpanded}
onToggleExpand={onToggleExpand}
Expand Down Expand Up @@ -401,6 +404,7 @@ export const ChatRowContent = ({
</div>
<CodeAccordian
code={tool.content}
language="markdown"
isLoading={message.partial}
isExpanded={isExpanded}
onToggleExpand={onToggleExpand}
Expand Down Expand Up @@ -441,7 +445,7 @@ export const ChatRowContent = ({
<CodeAccordian
path={tool.path}
code={tool.content}
language="shell-session"
language="shellsession"
isExpanded={isExpanded}
onToggleExpand={onToggleExpand}
/>
Expand All @@ -461,6 +465,7 @@ export const ChatRowContent = ({
<CodeAccordian
path={tool.path}
code={tool.content}
language="markdown"
isExpanded={isExpanded}
onToggleExpand={onToggleExpand}
/>
Expand Down Expand Up @@ -490,7 +495,7 @@ export const ChatRowContent = ({
<CodeAccordian
path={tool.path! + (tool.filePattern ? `/(${tool.filePattern})` : "")}
code={tool.content}
language="log"
language="shellsession"
isExpanded={isExpanded}
onToggleExpand={onToggleExpand}
/>
Expand Down Expand Up @@ -710,7 +715,7 @@ export const ChatRowContent = ({
backgroundColor: "var(--vscode-editor-background)",
borderTop: "none",
}}>
<CodeBlock source={`${"```"}plaintext\n${message.text || ""}\n${"```"}`} />
<CodeBlock source={message.text || ""} language="xml" />
</div>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions webview-ui/src/components/common/CodeAccordian.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CodeBlock from "./CodeBlock"
interface CodeAccordianProps {
path?: string
code?: string
language?: string | undefined
language: string
progressStatus?: ToolProgressStatus
isLoading?: boolean
isExpanded: boolean
Expand All @@ -29,7 +29,7 @@ const CodeAccordian = ({
isFeedback,
onToggleExpand,
}: CodeAccordianProps) => {
const inferredLanguage = useMemo(() => language ?? (path ? getLanguageFromPath(path) : undefined), [path, language])
const inferredLanguage = useMemo(() => language ?? (path ? getLanguageFromPath(path) : "txt"), [path, language])
const source = useMemo(() => code.trim(), [code])
const hasHeader = Boolean(path || isFeedback)

Expand Down
93 changes: 42 additions & 51 deletions webview-ui/src/components/common/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ minWidth: "max-content",
interface CodeBlockProps {
source?: string
rawSource?: string // Add rawSource prop for copying raw text
language?: string
language: string
preStyle?: React.CSSProperties
initialWordWrap?: boolean
collapsedHeight?: number
Expand Down Expand Up @@ -637,57 +637,48 @@ const CodeBlock = memo(
ref={copyButtonWrapperRef}
onMouseOver={() => updateCodeBlockButtonPosition()}
style={{ gap: 0 }}>
{language && (
<LanguageSelect
value={currentLanguage}
style={{
width: `calc(${currentLanguage?.length || 0}ch + 9px)`,
}}
onClick={(e) => {
e.currentTarget.focus()
}}
onChange={(e) => {
const newLang = normalizeLanguage(e.target.value)
userChangedLanguageRef.current = true
setCurrentLanguage(newLang)
if (onLanguageChange) {
onLanguageChange(newLang)
}
}}>
{
// Display original language at top of list for quick selection
language && (
<option
value={normalizeLanguage(language)}
style={{ fontWeight: "bold", textAlign: "left", fontSize: "1.2em" }}>
{normalizeLanguage(language)}
</option>
)
<LanguageSelect
value={currentLanguage}
style={{
width: `calc(${currentLanguage?.length || 0}ch + 9px)`,
}}
onClick={(e) => {
e.currentTarget.focus()
}}
onChange={(e) => {
const newLang = normalizeLanguage(e.target.value)
userChangedLanguageRef.current = true
setCurrentLanguage(newLang)
if (onLanguageChange) {
onLanguageChange(newLang)
}
{
// Display all available languages in alphabetical order
Object.keys(bundledLanguages)
.sort()
.map((lang) => {
const normalizedLang = normalizeLanguage(lang)
return (
<option
key={normalizedLang}
value={normalizedLang}
style={{
fontWeight:
normalizedLang === currentLanguage ? "bold" : "normal",
textAlign: "left",
fontSize:
normalizedLang === currentLanguage ? "1.2em" : "inherit",
}}>
{normalizedLang}
</option>
)
})
}
</LanguageSelect>
)}
}}>
<option
value={normalizeLanguage(language)}
style={{ fontWeight: "bold", textAlign: "left", fontSize: "1.2em" }}>
{normalizeLanguage(language)}
</option>
{
// Display all available languages in alphabetical order
Object.keys(bundledLanguages)
.sort()
.map((lang) => {
const normalizedLang = normalizeLanguage(lang)
return (
<option
key={normalizedLang}
value={normalizedLang}
style={{
fontWeight: normalizedLang === currentLanguage ? "bold" : "normal",
textAlign: "left",
fontSize: normalizedLang === currentLanguage ? "1.2em" : "inherit",
}}>
{normalizedLang}
</option>
)
})
}
</LanguageSelect>
{showCollapseButton && (
<CodeBlockButton
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion webview-ui/src/components/common/__mocks__/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react"

interface CodeBlockProps {
children?: React.ReactNode
language?: string
language: string
}

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