Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit a58b4b3

Browse files
authored
Add setting for enabling/disabling cody chat syntax highlighting (#8185)
## Changes This PR allows users to disable chat code highlighting using `cody.chatCodeSyntaxHighlightingEnabled` user setting. This may be useful e.g. for testing purposes, as we recently discovered that in some environments syntax highlighting seems to be causing a memory leak when multiple code snippets are streamed. ## Test plan 1. Run `pnpm dev:standalone` 2. Open http://localhost:5777/ and ask cody to give you a short java code snippet. 3. Make sure code **is highlighted** 4. In your user settings at https://sourcegraph.sourcegraph.com/users/{username}/settings add the following setting: ``` { "cody.chatCodeSyntaxHighlightingEnabled": false } ``` 5. Refresh http://localhost:5777/ and ask cody to give you a short java code snippet again. 6. Make sure code **is NOT highlighted**
1 parent 6cc6d66 commit a58b4b3

15 files changed

Lines changed: 100 additions & 62 deletions

File tree

lib/shared/src/sourcegraph-api/clientConfig.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { graphqlClient } from './graphql/client'
1010

1111
const CLIENT_CONFIG_FIXTURE: CodyClientConfig = {
1212
chatEnabled: true,
13+
chatCodeHighlightingEnabled: true,
1314
autoCompleteEnabled: true,
1415
customCommandsEnabled: true,
1516
attributionEnabled: false,
@@ -300,6 +301,7 @@ describe('ClientConfigSingleton', () => {
300301
const fixture2: CodyClientConfig = {
301302
...CLIENT_CONFIG_FIXTURE,
302303
chatEnabled: !CLIENT_CONFIG_FIXTURE.chatEnabled,
304+
chatCodeHighlightingEnabled: CLIENT_CONFIG_FIXTURE.chatCodeHighlightingEnabled,
303305
}
304306
fetchHTTPMock.mockResolvedValue(fixture2)
305307
authStatusSubject.next({ ...AUTH_STATUS_FIXTURE_AUTHED, endpoint: 'https://other.example.com' })

lib/shared/src/sourcegraph-api/clientConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export interface CodyClientConfig {
3939
// Whether the site admin allows this user to make use of the Cody chat feature.
4040
chatEnabled: boolean
4141

42+
// Whether code snippets in the Cody chat should be highlighted.
43+
chatCodeHighlightingEnabled?: boolean
44+
4245
// Whether the site admin allows this user to make use of the Cody autocomplete feature.
4346
autoCompleteEnabled: boolean
4447

@@ -95,6 +98,7 @@ export const dummyClientConfigForTest: CodyClientConfig = {
9598
siteVersion: undefined,
9699
omniBoxEnabled: false,
97100
codeSearchEnabled: false,
101+
chatCodeHighlightingEnabled: true,
98102
}
99103

100104
/**
@@ -248,6 +252,9 @@ export class ClientConfigSingleton {
248252
message: notice?.message ?? '',
249253
})
250254
)
255+
256+
config.chatCodeHighlightingEnabled =
257+
viewerSettings?.['cody.chatCodeSyntaxHighlightingEnabled'] ?? true
251258
}
252259

253260
return config

vscode/webviews/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
219219
errorMessages={errorMessages}
220220
setErrorMessages={setErrorMessages}
221221
chatEnabled={clientConfig?.chatEnabled ?? true}
222+
chatCodeHighlightingEnabled={clientConfig?.chatCodeHighlightingEnabled ?? true}
222223
instanceNotices={clientConfig?.notices ?? []}
223224
messageInProgress={messageInProgress}
224225
transcript={transcript}

vscode/webviews/Chat.story.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const meta: Meta<typeof Chat> = {
2525
transcript: FIXTURE_TRANSCRIPT.simple2,
2626
messageInProgress: null,
2727
chatEnabled: true,
28+
chatCodeHighlightingEnabled: true,
2829
vscodeAPI: {
2930
postMessage: () => {},
3031
onMessage: () => () => {},

vscode/webviews/Chat.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useUserAccountInfo } from './utils/useConfig'
2323

2424
interface ChatboxProps {
2525
chatEnabled: boolean
26+
chatCodeHighlightingEnabled: boolean
2627
messageInProgress: ChatMessage | null
2728
transcript: ChatMessage[]
2829
tokenUsage?:
@@ -49,6 +50,7 @@ export const Chat: React.FunctionComponent<React.PropsWithChildren<ChatboxProps>
4950
models,
5051
vscodeAPI,
5152
chatEnabled = true,
53+
chatCodeHighlightingEnabled = true,
5254
guardrails,
5355
showWelcomeMessage = true,
5456
showIDESnippetActions = true,
@@ -217,6 +219,7 @@ export const Chat: React.FunctionComponent<React.PropsWithChildren<ChatboxProps>
217219
smartApply={smartApply}
218220
userInfo={userInfo}
219221
chatEnabled={chatEnabled}
222+
chatCodeHighlightingEnabled={chatCodeHighlightingEnabled}
220223
postMessage={postMessage}
221224
guardrails={guardrails}
222225
/>

vscode/webviews/CodyPanel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface CodyPanelProps {
4040
}
4141
errorMessages: string[]
4242
chatEnabled: boolean
43+
chatCodeHighlightingEnabled: boolean
4344
instanceNotices: CodyNotice[]
4445
messageInProgress: ChatMessage | null
4546
transcript: ChatMessage[]
@@ -70,6 +71,7 @@ export const CodyPanel: FunctionComponent<CodyPanelProps> = ({
7071
errorMessages,
7172
setErrorMessages,
7273
chatEnabled,
74+
chatCodeHighlightingEnabled,
7375
instanceNotices,
7476
messageInProgress,
7577
transcript,
@@ -159,6 +161,7 @@ export const CodyPanel: FunctionComponent<CodyPanelProps> = ({
159161
{view === View.Chat && (
160162
<Chat
161163
chatEnabled={chatEnabled}
164+
chatCodeHighlightingEnabled={chatCodeHighlightingEnabled}
162165
messageInProgress={messageInProgress}
163166
transcript={transcript}
164167
tokenUsage={tokenUsage}

vscode/webviews/chat/ChatMessageContent/ChatMessageContent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface ChatMessageContentProps {
4545
setThoughtProcessOpened?: (open: boolean) => void
4646

4747
guardrails: Guardrails
48+
chatCodeHighlightingEnabled?: boolean
4849
className?: string
4950
}
5051

@@ -61,6 +62,7 @@ export const ChatMessageContent: React.FunctionComponent<ChatMessageContentProps
6162
onRegenerate,
6263
regeneratingCodeBlocks,
6364
guardrails,
65+
chatCodeHighlightingEnabled,
6466
className,
6567
smartApply,
6668
isThoughtProcessOpened,
@@ -122,6 +124,7 @@ export const ChatMessageContent: React.FunctionComponent<ChatMessageContentProps
122124
smartApply={smartApply}
123125
className={clsx(styles.content, className)}
124126
hasEditIntent={humanMessage?.intent === 'edit'}
127+
chatCodeHighlightingEnabled={chatCodeHighlightingEnabled}
125128
/>
126129
</div>
127130
)

vscode/webviews/chat/Transcript.story.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const meta: Meta<typeof Transcript> = {
4141
userInfo: FIXTURE_USER_ACCOUNT_INFO,
4242
postMessage: () => {},
4343
chatEnabled: true,
44+
chatCodeHighlightingEnabled: true,
4445
models: FIXTURE_MODELS,
4546
setActiveChatContext: () => {},
4647
guardrails: new MockNoGuardrails(),

vscode/webviews/chat/Transcript.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const PROPS: Omit<ComponentProps<typeof Transcript>, 'transcript'> = {
1414
insertButtonOnSubmit: () => {},
1515
userInfo: FIXTURE_USER_ACCOUNT_INFO,
1616
chatEnabled: true,
17+
chatCodeHighlightingEnabled: true,
1718
postMessage: () => {},
1819
models: FIXTURE_MODELS,
1920
setActiveChatContext: () => {},

vscode/webviews/chat/Transcript.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface TranscriptProps {
5353
activeChatContext?: Context
5454
setActiveChatContext: (context: Context | undefined) => void
5555
chatEnabled: boolean
56+
chatCodeHighlightingEnabled: boolean
5657
transcript: ChatMessage[]
5758
tokenUsage?:
5859
| {
@@ -95,6 +96,7 @@ export const Transcript: FC<TranscriptProps> = props => {
9596
activeChatContext,
9697
setActiveChatContext,
9798
chatEnabled,
99+
chatCodeHighlightingEnabled,
98100
transcript,
99101
tokenUsage,
100102
models,
@@ -219,6 +221,7 @@ export const Transcript: FC<TranscriptProps> = props => {
219221
tokenUsage={tokenUsage}
220222
models={models}
221223
chatEnabled={chatEnabled}
224+
chatCodeHighlightingEnabled={chatCodeHighlightingEnabled}
222225
userInfo={userInfo}
223226
guardrails={guardrails}
224227
postMessage={postMessage}
@@ -250,6 +253,7 @@ export const Transcript: FC<TranscriptProps> = props => {
250253
tokenUsage,
251254
models,
252255
chatEnabled,
256+
chatCodeHighlightingEnabled,
253257
userInfo,
254258
guardrails,
255259
postMessage,
@@ -400,6 +404,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
400404
priorAssistantMessageIsLoading,
401405
userInfo,
402406
chatEnabled,
407+
chatCodeHighlightingEnabled,
403408
postMessage,
404409
guardrails,
405410
insertButtonOnSubmit,
@@ -771,6 +776,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
771776
userInfo={userInfo}
772777
models={models}
773778
chatEnabled={chatEnabled}
779+
chatCodeHighlightingEnabled={chatCodeHighlightingEnabled}
774780
message={assistantMessage}
775781
copyButtonOnSubmit={copyButtonOnSubmit}
776782
insertButtonOnSubmit={insertButtonOnSubmit}

0 commit comments

Comments
 (0)