microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.52k stars 28.1k forks source link

Editor selection lost while response is streaming #208191

Open theskcd opened 3 months ago

theskcd commented 3 months ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

  1. Ask Copilot to add comments to all over the file
  2. Try to select a selection and copy that to clipboard, the selection keeps getting reset, I do think its because of the re-rendering happening to the DOM node in the chat

https://github.com/microsoft/vscode/assets/10356126/68163337-a5e7-4fc3-8801-68e43e671cb7

I am also adding a scree-grab on the behaviour I am able to see

Note: This also happens not just for the code blocks but also the text being rendered in the chat when the output from the LLM is streaming.

I am also on Copilot Chat preview version right now.

VSCodeTriageBot commented 3 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.87.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

theskcd commented 3 months ago

I updated to the latest vscode version: Version: 1.87.2 (Universal) Commit: 863d2581ecda6849923a2118d93a088b0745d9d6 Date: 2024-03-08T15:21:31.043Z Electron: 27.3.2 ElectronBuildId: 26836302 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Darwin arm64 23.0.0

still the same issue

theskcd commented 3 months ago

Here are some debugging traces which might be helpful, I think whats happening is that the list-renderer is replacing the DOM node without diffing it properly at this code location: https://github.com/microsoft/vscode/blob/dd42b9fda56ee3c2f37cf94941a1220c213aca4f/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts#L642

So I tried using DomDiff to apply just the diff to the element, but turns out the ID of the whole Dom node is changing causing a re-render which is triggered from here: https://github.com/microsoft/vscode/blob/dd42b9fda56ee3c2f37cf94941a1220c213aca4f/src/vs/workbench/contrib/chat/browser/chatWidget.ts#L317-L332 here the ID changes because on every update to the stream we increment the dataid here: https://github.com/microsoft/vscode/blob/dd42b9fda56ee3c2f37cf94941a1220c213aca4f/src/vs/workbench/contrib/chat/common/chatViewModel.ts#L353-L355

I am not sure how to solve this proper, but I think for the code blocks being generated (since they are just monaco editors in disguise) we can avoid the re-rendering in a smart way.

I stopped debugging at this point, because I did not want to spend more time understanding the re-rendering logic. Hopefully this helps!

roblourens commented 3 months ago

Yeah, this is more complex than that, thanks for the analysis though