Skip to content

Commit

Permalink
refactor(vscode): enhance chat.edit.editNLOutline command and update …
Browse files Browse the repository at this point in the history
…NLOutlinesProvider
  • Loading branch information
Sma1lboy committed Sep 4, 2024
1 parent 9608ab7 commit 4c69fc1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
26 changes: 16 additions & 10 deletions clients/vscode/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,26 @@ export class Commands {
},
);
},
"chat.edit.editNLOutline": async () => {
"chat.edit.editNLOutline": async (uri?: Uri, startLine?: number) => {
const editor = window.activeTextEditor;
if (!editor) return;
const position = editor.selection.active;
const line = position.line;
const content = this.nlOutlinesProvider.getOutline(editor.document.uri.toString(), line);

let documentUri: string;
let line: number;

if (uri && startLine !== undefined) {
documentUri = uri.toString();
line = startLine;
} else {
documentUri = editor.document.uri.toString();
line = editor.selection.active.line;
}

const content = this.nlOutlinesProvider.getOutline(documentUri, line);
getLogger().info("get content");
if (!content) return;

getLogger().info("shown");
window.showInformationMessage(content);

const quickPick = window.createQuickPick();
quickPick.items = [{ label: content }];
quickPick.placeholder = "Edit NL Outline content";
Expand All @@ -532,14 +541,11 @@ export class Commands {
quickPick.onDidAccept(async () => {
const newContent = quickPick.value;
quickPick.hide();

await this.nlOutlinesProvider.updateNLOutline(editor.document.uri.toString(), line, newContent);

await this.nlOutlinesProvider.updateNLOutline(documentUri, line, newContent);
window.showInformationMessage(`Updated NL Outline: ${newContent}`);
});

quickPick.show();
return;
},
"chat.edit.stop": async () => {
this.chatEditCancellationTokenSource?.cancel();
Expand Down
10 changes: 5 additions & 5 deletions clients/vscode/src/NLOutlinesProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ export class NLOutlinesProvider extends EventEmitter<void> implements CodeLensPr

const editCommand: Command = {
title: "Edit",
command: "extension.editOutline",
arguments: [document.uri, outline.startLine, outline.content],
command: "tabby.chat.edit.editNLOutline",
arguments: [document.uri, outline.startLine],
};
const editCodeLens = new CodeLens(range, editCommand);

Expand Down Expand Up @@ -259,9 +259,9 @@ export class NLOutlinesProvider extends EventEmitter<void> implements CodeLensPr
return this.outlines.get(documentUri)?.find((outline) => outline.startLine === lineNumber)?.content;
}

//TODO: do diff when adding new code with old code, user should accpet or discard the new code;
//TODO: dynamic update remain outline or find a new way to show new code
//TODO: stream prompt new code not directly prompt everything
//TODO(Sma1lboy): do diff when adding new code with old code, user should accpet or discard the new code;
//TODO(Sma1lboy): dynamic update remain outline or find a new way to show new code
//TODO(Sma1lboy): stream prompt new code not directly prompt everything
async updateNLOutline(documentUri: string, lineNumber: number, newContent: string) {
const outlines = this.outlines.get(documentUri) || [];
const oldOutlineIndex = outlines.findIndex((outline) => outline.startLine === lineNumber);
Expand Down

0 comments on commit 4c69fc1

Please sign in to comment.