if file empty insert and return
This commit is contained in:
parent
f425cadcda
commit
56313d83eb
3 changed files with 27 additions and 9 deletions
|
|
@ -43,7 +43,7 @@ export async function* streamLazyApply(
|
|||
let lazyCompletionLines = streamLines(lazyCompletion, true);
|
||||
// Process line output
|
||||
// lazyCompletionLines = filterEnglishLinesAtStart(lazyCompletionLines);
|
||||
lazyCompletionLines = stopAtLines(lazyCompletionLines, () => {}, ["```"]);
|
||||
lazyCompletionLines = stopAtLines(lazyCompletionLines, () => { }, ["```"]);
|
||||
lazyCompletionLines = filterLeadingNewline(lazyCompletionLines);
|
||||
|
||||
// Fill in unchanged code
|
||||
|
|
|
|||
|
|
@ -635,6 +635,22 @@ class IdeProtocolClient(
|
|||
val text = msg["text"] as String
|
||||
val curSelectedModelTitle = msg["curSelectedModelTitle"] as String
|
||||
|
||||
val editor = FileEditorManager.getInstance(project).selectedTextEditor
|
||||
|
||||
if (editor == null) {
|
||||
showToast("error", "No active editor to apply edits to")
|
||||
respond(null)
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (editor.document.text.trim().isEmpty()) {
|
||||
WriteCommandAction.runWriteCommandAction(project) {
|
||||
document.insertString(0, text)
|
||||
}
|
||||
respond(null)
|
||||
return@launch
|
||||
}
|
||||
|
||||
val config = readConfigJson()
|
||||
var llm = getModelByRole(config, "applyCodeBlock")
|
||||
|
||||
|
|
@ -654,14 +670,6 @@ class IdeProtocolClient(
|
|||
val prompt =
|
||||
"The following code was suggested as an edit:\n```\n${text}\n```\nPlease apply it to the previous code."
|
||||
|
||||
val editor = FileEditorManager.getInstance(project).selectedTextEditor
|
||||
|
||||
if (editor == null) {
|
||||
showToast("error", "No active editor to apply edits to")
|
||||
respond(null)
|
||||
return@launch
|
||||
}
|
||||
|
||||
val rif = getHighlightedCode()
|
||||
|
||||
val (prefix, highlighted, suffix) = if (rif == null) {
|
||||
|
|
|
|||
|
|
@ -158,6 +158,16 @@ export class VsCodeMessenger {
|
|||
return;
|
||||
}
|
||||
|
||||
// If document is empty, insert at 0,0 and finish
|
||||
if (!editor.document.getText().trim()) {
|
||||
editor.edit(builder => builder.insert(new vscode.Position(0, 0), data.text));
|
||||
await webviewProtocol.request("updateApplyState", {
|
||||
streamId: data.streamId,
|
||||
status: "done",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Get LLM from config
|
||||
const configHandler = await configHandlerPromise;
|
||||
const config = await configHandler.loadConfig();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue