-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autoedit): Support image rendering for complex diffs (#6545)
<img width="542" alt="image" src="https://github.com/user-attachments/assets/68601e33-8f0d-4ce1-a911-73d55abe8789" /> ## Description This PR adds support for generating diff-like images of code snippets, that we can use to render auto-edit suggestions to the user. We are using [CanvasKit](https://skia.org/docs/user/modules/canvaskit/), which has good cross platform support (a WASM binary is provided) and means we can efficiently draw and paint text to a canvas. We can then convert this to a PNG for rendering as a decoration (via `contentIconPath`). We are also using [Shiki](https://shiki.matsu.io/), which provides syntax highlighting for our code snippets. Unfortunately we cannot access the users' selected theme colors programmatically ([see this issue](microsoft/vscode#32813)). ### Design Considerations Due to some limitations in the VS Code API, I have taken some design considerations which I think work well - but I am happy to discuss alternative solutions. **Syntax Highlighting theme**: We cannot access the users' syntax highlighting colors, so we use [Vitesse Dark/Light](https://shiki.style/themes#:~:text=Vitesse%20Dark,vitesse%2Dlight). From my testing, these colors are fairly neutral and work well, but could possibly be an eye sore for users if it doesn't match their preferred highlight colors. **Image background**: I have made the background of the image transparent, this is because we can actually provide our own background through the VS Code decoration options. So we *can* theme the background and border to match the users editor. This means that it many cases the suggestions look great. There is a possibility that this could clash with the highlighting theme we have chosen though. The alternative would be to provide our own background color and accept it would likely not match the users' theme. Note: We may have to do this for non-VSCode clients anyway. **Font**: We are using [DejaVu Sans Mono](https://dejavu-fonts.github.io/). This is a publicly available font that renders a wide range of code snippets clearly, from my testing. It is also the font that the Menlo font (default on MacOS) is based off, so many users are likely to be familiar with it. We do not currently adjust the image to match the users' font size, but this is something we should be able to do. Likewise with the users' line height. ### Screenshots **Suggestion Dark** <img width="514" alt="image" src="https://github.com/user-attachments/assets/1ec2d178-7c75-4ae1-b5b9-8568c6022bec" /> **Suggestion Light** <img width="512" alt="image" src="https://github.com/user-attachments/assets/4ab1e670-1cf3-4bdf-a913-ffd8a9e7db73" /> **Suggestion Alternative Theme A** <img width="497" alt="image" src="https://github.com/user-attachments/assets/046dbc1d-d32b-4d6f-a326-8ac66ec94674" /> **Suggestion Alternative Theme B** <img width="529" alt="image" src="https://github.com/user-attachments/assets/460b9b85-3a93-4e37-aae1-32e5603d920e" /> **Raw Image**  ## How to manually test 1. Checkout this branch and run it locally in VS Code 2. Ensure that the following settings are set, to enable auto-edit and the image generation ``` "cody.suggestions.mode": "auto-edit (Experimental)", "cody.experimental.autoedit.renderer": "image", ``` 3. Try triggering some auto-edits! # Test plan 1. Enable auto edits 4. Generate suggestions where lines are expected to be added/modified 5. Observe results Also tested with E2E and unit visual tests
- Loading branch information
Showing
22 changed files
with
1,024 additions
and
47 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
!dist/*.exe | ||
!dist/*.wasm | ||
!dist/*.node | ||
!dist/*.ttf | ||
|
||
!resources/* | ||
!walkthroughs/*.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { copyFileSync, existsSync, mkdirSync } from 'node:fs' | ||
import path from 'node:path' | ||
|
||
const DIST_DIRECTORY = path.join(__dirname, '../dist') | ||
const FONT_PATH = path.join(__dirname, '../resources/DejaVuSansMono.ttf') | ||
|
||
export async function main(): Promise<void> { | ||
try { | ||
copyFonts() | ||
console.log('Fonts were successfully copied to dist directory') | ||
} catch (error) { | ||
console.error('Error copying fonts:', error) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
void main() | ||
|
||
function copyFonts(): void { | ||
const hasDistDir = existsSync(DIST_DIRECTORY) | ||
|
||
if (!hasDistDir) { | ||
mkdirSync(DIST_DIRECTORY) | ||
} | ||
|
||
copyFileSync(FONT_PATH, path.join(DIST_DIRECTORY, 'DejaVuSansMono.ttf')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.