Compare commits

..

2 Commits

2 changed files with 32 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{
"name": "fabelous-autocoder",
"version": "0.2.49",
"version": "0.2.58",
"displayName": "Fabelous Autocoder",
"description": "A simple to use Ollama autocompletion Plugin",
"icon": "icon.png",

View File

@ -112,31 +112,39 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
// Split the completion text by new lines
const lines = completionText.split('\n');
// Define the preview start and end lines
const startLine = Math.max(0, position.line); // Use cursor position directly
const endLine = position.line + lines.length;
// Define the start line and end line based on context (adjusting the preview to the same lines)
let startLine = position.line - (context.split('\n').length - 1);
if (startLine < 0) startLine = 0; // Ensure startLine is not negative
const rangeToReplace = new vscode.Range(
new vscode.Position(startLine, 0),
new vscode.Position(endLine, 0)
);
const endLine = Math.min(startLine + lines.length, document.lineCount); // Ensure endLine doesn't exceed document line count
// Apply the preview line by line over the context range
const previewRanges: vscode.DecorationOptions[] = lines.map((line: string, index: number): vscode.DecorationOptions | null => {
const currentLine = startLine + index;
// Ensure the current line is within the bounds of the document
if (currentLine >= document.lineCount) return null;
const _ = new vscode.Position(currentLine, 0); // Position for each preview line
const endOfLine = document.lineAt(currentLine).text.length; // Full range for the current line
const range = new vscode.Range(
new vscode.Position(currentLine, 0),
new vscode.Position(currentLine, endOfLine)
); // Create range for each line
// Apply the preview with multi-line support
const previewRanges = lines.map((line: string, index: number) => {
const linePos = new vscode.Position(startLine + index, 0);
return {
range: new vscode.Range(linePos, linePos),
range: range, // Range for the line
renderOptions: {
before: {
after: {
contentText: line,
color: '#888888', // Grayed-out text
fontStyle: 'italic', // Italic text
fontStyle: 'italic', // Italic text for preview
}
}
};
});
textEditor.setDecorations(previewDecorationType, previewRanges);
}).filter((range: vscode.DecorationOptions | null): range is vscode.DecorationOptions => range !== null); // Filter out any invalid ranges
textEditor.setDecorations(previewDecorationType, previewRanges as any); // Apply the decorations for the preview
let previewInserted = true;
@ -159,6 +167,12 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
// Replace the context with the actual completion
const acceptedText = completionText;
const rangeToReplace = new vscode.Range(
new vscode.Position(startLine, 0),
new vscode.Position(endLine, document.lineAt(endLine - 1).text.length)
);
edit.replace(document.uri, rangeToReplace, acceptedText);
await vscode.workspace.applyEdit(edit);
@ -181,6 +195,7 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
}
async function provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, cancellationToken: vscode.CancellationToken) {
const item = new vscode.CompletionItem("Fabelous autocompletion");
item.insertText = new vscode.SnippetString('${1:}');