diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index 8777f595ce..33d6807202 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -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" @@ -293,7 +294,7 @@ export const ChatRowContent = ({ @@ -463,6 +467,7 @@ export const ChatRowContent = ({ @@ -492,7 +497,7 @@ export const ChatRowContent = ({ @@ -712,7 +717,7 @@ export const ChatRowContent = ({ backgroundColor: "var(--vscode-editor-background)", borderTop: "none", }}> - + )} diff --git a/webview-ui/src/components/common/CodeAccordian.tsx b/webview-ui/src/components/common/CodeAccordian.tsx index 4b92fe416e..c3e44e7713 100644 --- a/webview-ui/src/components/common/CodeAccordian.tsx +++ b/webview-ui/src/components/common/CodeAccordian.tsx @@ -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 @@ -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) diff --git a/webview-ui/src/components/common/CodeBlock.tsx b/webview-ui/src/components/common/CodeBlock.tsx index 151a133c25..da3eb6429c 100644 --- a/webview-ui/src/components/common/CodeBlock.tsx +++ b/webview-ui/src/components/common/CodeBlock.tsx @@ -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 @@ -637,57 +637,48 @@ const CodeBlock = memo( ref={copyButtonWrapperRef} onMouseOver={() => updateCodeBlockButtonPosition()} style={{ gap: 0 }}> - {language && ( - { - 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 && ( - - ) + { + 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 ( - - ) - }) - } - - )} + }}> + + { + // Display all available languages in alphabetical order + Object.keys(bundledLanguages) + .sort() + .map((lang) => { + const normalizedLang = normalizeLanguage(lang) + return ( + + ) + }) + } + {showCollapseButton && ( { diff --git a/webview-ui/src/components/common/__mocks__/CodeBlock.tsx b/webview-ui/src/components/common/__mocks__/CodeBlock.tsx index b4d7363367..abf9f303b8 100644 --- a/webview-ui/src/components/common/__mocks__/CodeBlock.tsx +++ b/webview-ui/src/components/common/__mocks__/CodeBlock.tsx @@ -2,7 +2,7 @@ import * as React from "react" interface CodeBlockProps { children?: React.ReactNode - language?: string + language: string } const CodeBlock: React.FC = () =>
Mocked Code Block