Skip to content

Commit 4f58afc

Browse files
committed
0.0.5
1 parent a724c00 commit 4f58afc

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ The extension is a great addition to Amazon CodeWhisperer or Github Copilot if y
4444

4545
## Release Notes
4646

47+
### 0.0.5
48+
- Created code is formatted (Format selection)
49+
4750
### 0.0.4
4851
- Time reporting fixed for create or refactor
4952
- More language profiles for AI priming (Dart, JavaScript, TypeScript, Python, Java, C#, Go, Ruby, Rust, HTML, CSS, JSON, YAML, C, C++, Swift, Objective-C, Objective-C++, Kotlin)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cptx",
33
"displayName": "cptX: ChatGPT as copilot",
44
"description": "Use ChatGPT as your (aslmost)free copilot",
5-
"version": "0.0.4",
5+
"version": "0.0.5",
66
"publisher": "MaximSaplin",
77
"icon": "images/icon.png",
88
"engines": {

src/createOrRefactor.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ export async function createOrRefactor(openAi: OpenAIApi) {
3232
const refactor = selectedCode.length > 0;
3333
let aboveText = '';
3434
let belowText = '';
35-
let cursorLine = 0;
3635
if (refactor) {
3736
({ aboveText, belowText } = common.getCodeAroundSelection(editor));
3837
}
3938
else {
40-
({ aboveText, belowText, cursorLine } = common.getCodeAroundCursor(editor));
39+
({ aboveText, belowText } = common.getCodeAroundCursor(editor));
4140
}
4241

4342
let { expert, language } = common.getExpertAndLanguage(editor);
@@ -56,20 +55,26 @@ export async function createOrRefactor(openAi: OpenAIApi) {
5655
}
5756

5857
if (!token.isCancellationRequested) {
59-
editor.edit((editBuilder) => {
58+
await editor.edit((editBuilder) => {
6059
if (refactor) {
6160
editBuilder.replace(editor.selection, result);
6261
} else {
63-
const selection = new vscode.Selection(cursorLine, 0, cursorLine, 0);
64-
editBuilder.insert(selection.end, '\n');
65-
editBuilder.insert(selection.end, result);
66-
// editor.selection = new vscode.Selection(
67-
// editor.selection.active.line-1, 0,
68-
// editor.selection.active.line-1+result.split('\n').length, 0);
62+
const cursorLineNotEmpty = !editor.document.lineAt(editor.selection.end.line).isEmptyOrWhitespace;
63+
if (cursorLineNotEmpty) {
64+
editBuilder.insert(editor.selection.end, '\n');
65+
}
66+
editBuilder.insert(editor.selection.end, result);
6967
}
7068

7169
});
70+
if (!refactor) {
71+
var endPos = editor.selection.end;
72+
var startPos = new vscode.Position(endPos.line-result.split('\n').length+1, 0);
73+
editor.selection = new vscode.Selection(startPos, endPos);
74+
}
7275
vscode.window.showInformationMessage(`cptX completed operation (${common.getElapsed(start)}s)`);
76+
77+
await vscode.commands.executeCommand('editor.action.formatSelection');
7378
}
7479
});
7580
} catch (error) {

0 commit comments

Comments
 (0)