Compare commits
No commits in common. "2a46e061d336a342ec60bff90dc5a716b0575fc1" and "66c88a053b40c7c688e8f3cd97c486c42f57fae7" have entirely different histories.
2a46e061d3
...
66c88a053b
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "fabelous-autocoder",
|
||||
"version": "0.2.58",
|
||||
"version": "0.2.49",
|
||||
"displayName": "Fabelous Autocoder",
|
||||
"description": "A simple to use Ollama autocompletion Plugin",
|
||||
"icon": "icon.png",
|
||||
|
|
|
@ -112,39 +112,31 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
|||
// Split the completion text by new lines
|
||||
const lines = completionText.split('\n');
|
||||
|
||||
// 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
|
||||
// Define the preview start and end lines
|
||||
const startLine = Math.max(0, position.line); // Use cursor position directly
|
||||
const endLine = position.line + lines.length;
|
||||
|
||||
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
|
||||
const rangeToReplace = new vscode.Range(
|
||||
new vscode.Position(startLine, 0),
|
||||
new vscode.Position(endLine, 0)
|
||||
);
|
||||
|
||||
// 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: range, // Range for the line
|
||||
range: new vscode.Range(linePos, linePos),
|
||||
renderOptions: {
|
||||
after: {
|
||||
before: {
|
||||
contentText: line,
|
||||
color: '#888888', // Grayed-out text
|
||||
fontStyle: 'italic', // Italic text for preview
|
||||
fontStyle: 'italic', // Italic text
|
||||
}
|
||||
}
|
||||
};
|
||||
}).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
|
||||
});
|
||||
|
||||
textEditor.setDecorations(previewDecorationType, previewRanges);
|
||||
|
||||
let previewInserted = true;
|
||||
|
||||
|
@ -167,12 +159,6 @@ 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);
|
||||
|
@ -195,7 +181,6 @@ 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:}');
|
||||
|
|
Loading…
Reference in New Issue