microsoft / vscode

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

Inline chat for direct single edit application #190239

Open marrej opened 10 months ago

marrej commented 10 months ago

Utilizing the Inline chat as means for showing edits.

TLDR; The Inline chat could be cheaply extended to provide In editor edits. (PR https://github.com/microsoft/vscode/pull/190258 )

image

Intro

At the moment the experimental inline chat, provides very interesting way how to display edits that are restricted to a single file (TextEdits). And assuming that this API is something that the extension authors are interested in (e.g. see https://github.com/microsoft/vscode/issues/85682 ) might provide a great addition to the extension author toolbelt.

The main benefits being (compared to Refactor Preview), that for small edits/single file edits:

At the same time, I realise that the Inline chat purpose is to Chat, but at the moment it seems that the edit preview logic is fused with the internals of the chat and can not be easily extracted.

Proposal

Extend the existing inlineChat.start (or introduce a new command e.g. inlineChat.showEdit) which would allow to take in edits: vscode.TextEdit[] (or vscode.WorkspaceEdit, and add additional checks in the inlineChat). The edits would be added to the options (which are passed to the InlineChatController), and would modify the state flow a bit. After INIT_UI, break the _nextState and Attach the edit as a new response, then continue the _nextState with APPLY_EDIT If edits are provided in the options, then hide parts of the toolbar (the conversational pieces), and keep only the actions.

Done in PR https://github.com/microsoft/vscode/pull/190258

Additional nice to have

VS Code version: 1.81.1 OS version: ChromeOS 114.0.5735.239

luhc228 commented 8 months ago

Will this PR merge in the future?

marrej commented 7 months ago

happy to update the PR to the latest version if @jrieken will agree to have it enabled. Although lets note that this is not the clean way how this should be done. Rather the functionality should be exposed via a dedicated API and best have the Inline diff totally separated (as a whole new Core Component).

That being said, the dedicated API could be added easily, with the provider being registered automatically for extensionHost (While allowing only the mentioned command to be called) as intermediate step, allowing then to switch the functionality in the background of the API to a separate inline Diff with edit panel.

(Happy to add that in if agreed :))