mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 22:41:31 +01:00
inline chat from line should handle discarding more graceful
This commit is contained in:
@@ -11,7 +11,7 @@ import { localize, localize2 } from 'vs/nls';
|
||||
import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { InlineChatController } from 'vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
||||
import { InlineChatController, State } from 'vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
||||
import { CTX_INLINE_CHAT_HAS_AGENT, CTX_INLINE_CHAT_VISIBLE } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
|
||||
import { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
@@ -20,6 +20,7 @@ import { Range } from 'vs/editor/common/core/range';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { AbstractInlineChatAction } from 'vs/workbench/contrib/inlineChat/browser/inlineChatActions';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { IValidEditOperation } from 'vs/editor/common/model';
|
||||
|
||||
|
||||
export const CTX_INLINE_CHAT_EXPANSION = new RawContextKey<boolean>('inlineChatExpansion', false, localize('inlineChatExpansion', "Whether the inline chat expansion is enabled when at the end of a just-typed line"));
|
||||
@@ -125,7 +126,7 @@ export class InlineChatExpandLineAction extends EditorAction2 {
|
||||
});
|
||||
}
|
||||
|
||||
override runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
|
||||
override async runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
|
||||
const ctrl = InlineChatController.get(editor);
|
||||
if (!ctrl || !editor.hasModel()) {
|
||||
return;
|
||||
@@ -139,15 +140,29 @@ export class InlineChatExpandLineAction extends EditorAction2 {
|
||||
const endColumn = model.getLineMaxColumn(lineNumber);
|
||||
|
||||
// clear the line
|
||||
editor.pushUndoStop();
|
||||
editor.executeEdits('inlinePromptCurrentLine', [EditOperation.replace(new Range(lineNumber, startColumn, lineNumber, endColumn), '')]);
|
||||
editor.pushUndoStop();
|
||||
|
||||
// trigger chat
|
||||
return ctrl.run({
|
||||
autoSend: true,
|
||||
message: lineContent.trim(),
|
||||
position: new Position(lineNumber, startColumn)
|
||||
let undoEdits: IValidEditOperation[] = [];
|
||||
model.pushEditOperations(null, [EditOperation.replace(new Range(lineNumber, startColumn, lineNumber, endColumn), '')], (edits) => {
|
||||
undoEdits = edits;
|
||||
return null;
|
||||
});
|
||||
|
||||
let lastState: State | undefined;
|
||||
const d = ctrl.onDidEnterState(e => lastState = e);
|
||||
|
||||
try {
|
||||
// trigger chat
|
||||
await ctrl.run({
|
||||
autoSend: true,
|
||||
message: lineContent.trim(),
|
||||
position: new Position(lineNumber, startColumn)
|
||||
});
|
||||
|
||||
} finally {
|
||||
d.dispose();
|
||||
}
|
||||
|
||||
if (lastState === State.CANCEL) {
|
||||
model.pushEditOperations(null, undoEdits, () => null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user