Final Version. Everything is working; atleast for Python🥳
This commit is contained in:
parent
c1d0a53720
commit
a3bf2f93bb
17
package.json
17
package.json
|
@ -4,7 +4,7 @@
|
||||||
"displayName": "Fabelous Autocoder",
|
"displayName": "Fabelous Autocoder",
|
||||||
"description": "A simple to use Ollama autocompletion Plugin",
|
"description": "A simple to use Ollama autocompletion Plugin",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"publisher": "fabel",
|
"publisher": "Falko Habel",
|
||||||
"license": "CC BY-ND 4.0",
|
"license": "CC BY-ND 4.0",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitea.fabelous.app/fabel/Fabelous-Autocoder/issues"
|
"url": "https://gitea.fabelous.app/fabel/Fabelous-Autocoder/issues"
|
||||||
|
@ -114,11 +114,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"keybindings": [
|
"keybindings": [
|
||||||
{
|
{
|
||||||
"command": "fabelous-autocoder.handleTab",
|
"command": "fabelous-autocoder.handleTab",
|
||||||
"key": "tab",
|
"key": "tab",
|
||||||
"when": "editorTextFocus && !editorTabMovesFocus"
|
"when": "editorTextFocus && !editorTabMovesFocus"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"command": "fabelous-autocoder.handleBackspace",
|
||||||
|
"key": "backspace",
|
||||||
|
"when": "editorTextFocus"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -144,31 +144,39 @@ class CompletionManager {
|
||||||
const edit = new vscode.WorkspaceEdit();
|
const edit = new vscode.WorkspaceEdit();
|
||||||
const completionLines = this.completionText.split('\n');
|
const completionLines = this.completionText.split('\n');
|
||||||
const numberOfLines = completionLines.length;
|
const numberOfLines = completionLines.length;
|
||||||
|
|
||||||
// Ensure the start position is never negative
|
// Ensure the start position is never negative
|
||||||
const safeStartPosition = new vscode.Position(Math.max(0, this.startPosition.line - 1), 0);
|
const safeStartPosition = new vscode.Position(Math.max(0, this.startPosition.line - 1), 0);
|
||||||
|
|
||||||
// Prepare the range to replace
|
// Prepare the range to replace
|
||||||
const rangeToReplace = new vscode.Range(
|
const rangeToReplace = new vscode.Range(
|
||||||
safeStartPosition,
|
safeStartPosition,
|
||||||
this.startPosition.translate(numberOfLines, 0)
|
this.startPosition.translate(numberOfLines, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Construct the content to insert
|
// Construct the content to insert
|
||||||
const contentToInsert = (safeStartPosition.line === 0 ? '' : '\n') + this.completionText + '\n';
|
const contentToInsert = (safeStartPosition.line === 0 ? '' : '\n') + this.completionText + '\n';
|
||||||
edit.replace(this.document.uri, rangeToReplace, contentToInsert);
|
edit.replace(this.document.uri, rangeToReplace, contentToInsert);
|
||||||
|
|
||||||
await vscode.workspace.applyEdit(edit);
|
await vscode.workspace.applyEdit(edit);
|
||||||
this.clearPreview(); // Clear the preview decorations
|
|
||||||
|
// Clear the preview decorations
|
||||||
|
this.clearPreview();
|
||||||
|
|
||||||
|
// Set activeCompletionManager to null
|
||||||
|
activeCompletionManager = null;
|
||||||
|
|
||||||
// Calculate the new cursor position from the inserted content
|
// Calculate the new cursor position from the inserted content
|
||||||
const lastCompletionLine = completionLines[completionLines.length - 1];
|
const lastCompletionLine = completionLines[completionLines.length - 1];
|
||||||
const newPosition = new vscode.Position(this.startPosition.line + numberOfLines - 1, lastCompletionLine.length);
|
const newPosition = new vscode.Position(
|
||||||
|
this.startPosition.line + numberOfLines - 1,
|
||||||
// Set the new cursor position without any additional move
|
lastCompletionLine.length
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set the new cursor position
|
||||||
this.textEditor.selection = new vscode.Selection(newPosition, newPosition);
|
this.textEditor.selection = new vscode.Selection(newPosition, newPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public clearPreview() {
|
public clearPreview() {
|
||||||
|
@ -204,6 +212,7 @@ class CompletionManager {
|
||||||
this.textEditor.selection = new vscode.Selection(this.startPosition, this.startPosition);
|
this.textEditor.selection = new vscode.Selection(this.startPosition, this.startPosition);
|
||||||
|
|
||||||
console.log(`Lines ${startLine + 1} to ${endLine + 1} removed successfully`);
|
console.log(`Lines ${startLine + 1} to ${endLine + 1} removed successfully`);
|
||||||
|
activeCompletionManager = null;
|
||||||
} else {
|
} else {
|
||||||
console.log('No lines to remove');
|
console.log('No lines to remove');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue