Skip to content

Commit

Permalink
fix memory leak in syntax highlighting (causing gray webviews) (#4459)
Browse files Browse the repository at this point in the history
  • Loading branch information
sqs authored Jun 5, 2024
1 parent c04cfad commit 5e921f0
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 23 deletions.
136 changes: 117 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a

- Chat: Don't append @ when "Add context" is pressed multiple times. [pull/4439](https://github.com/sourcegraph/cody/pull/4439)
- Performance: Reduced the performance overhead for certain types of context fetching, especially for larger files. This might have caused issues with slow autocomplete before. [pull/4446](https://github.com/sourcegraph/cody/pull/4446)
- Chat: Fixed an issue where the chat view would crash and display a gray screen in VS Code due to an out-of-memory situation. [pull/4459](https://github.com/sourcegraph/cody/pull/4459)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@
"parse-git-diff": "^0.0.14",
"proxy-agent": "^6.4.0",
"react-markdown": "^9.0.1",
"rehype-highlight": "^7.0.0",
"rehype-highlight": "^6.0.0",
"rehype-sanitize": "^6.0.0",
"remark-gfm": "^4.0.0",
"semver": "^7.5.4",
Expand Down
16 changes: 13 additions & 3 deletions vscode/webviews/components/MarkdownFromCody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function markdownPluginProps(): Pick<
'rehypePlugins' | 'remarkPlugins'
> {
if (_markdownPluginProps) {
//return _markdownPluginProps
return _markdownPluginProps
}

_markdownPluginProps = {
Expand All @@ -102,13 +102,23 @@ function markdownPluginProps(): Pick<
} satisfies RehypeSanitizeOptions,
],
[
rehypeHighlight,
// HACK(sqs): Need to use rehype-highlight@^6.0.0 to avoid a memory leak
// (https://github.com/remarkjs/react-markdown/issues/791), but the types are
// slightly off.
rehypeHighlight as any,
{
detect: true,
languages: Object.fromEntries(
Object.entries(all).filter(([language]) => LANGUAGES.includes(language))
),
} satisfies RehypeHighlightOptions,

// `ignoreMissing: true` is required to avoid errors when trying to highlight
// partial code blocks received from the LLM that have (e.g.) "```p" for
// "```python". This is only needed on rehype-highlight@^6.0.0, which we needed
// to downgrade to in order to avoid a memory leak
// (https://github.com/remarkjs/react-markdown/issues/791).
ignoreMissing: true,
} satisfies RehypeHighlightOptions & { ignoreMissing: boolean },
],
],
remarkPlugins: [remarkGFM],
Expand Down

0 comments on commit 5e921f0

Please sign in to comment.