Compare commits
No commits in common. "2a46e061d336a342ec60bff90dc5a716b0575fc1" and "66c88a053b40c7c688e8f3cd97c486c42f57fae7" have entirely different histories.
2a46e061d3
...
66c88a053b
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "fabelous-autocoder",
|
"name": "fabelous-autocoder",
|
||||||
"version": "0.2.58",
|
"version": "0.2.49",
|
||||||
"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",
|
||||||
|
|
|
@ -112,39 +112,31 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
||||||
// Split the completion text by new lines
|
// Split the completion text by new lines
|
||||||
const lines = completionText.split('\n');
|
const lines = completionText.split('\n');
|
||||||
|
|
||||||
// Define the start line and end line based on context (adjusting the preview to the same lines)
|
// Define the preview start and end lines
|
||||||
let startLine = position.line - (context.split('\n').length - 1);
|
const startLine = Math.max(0, position.line); // Use cursor position directly
|
||||||
if (startLine < 0) startLine = 0; // Ensure startLine is not negative
|
const endLine = position.line + lines.length;
|
||||||
|
|
||||||
const endLine = Math.min(startLine + lines.length, document.lineCount); // Ensure endLine doesn't exceed document line count
|
const rangeToReplace = new vscode.Range(
|
||||||
|
new vscode.Position(startLine, 0),
|
||||||
// Apply the preview line by line over the context range
|
new vscode.Position(endLine, 0)
|
||||||
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 {
|
return {
|
||||||
range: range, // Range for the line
|
range: new vscode.Range(linePos, linePos),
|
||||||
renderOptions: {
|
renderOptions: {
|
||||||
after: {
|
before: {
|
||||||
contentText: line,
|
contentText: line,
|
||||||
color: '#888888', // Grayed-out text
|
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;
|
let previewInserted = true;
|
||||||
|
|
||||||
|
@ -167,12 +159,6 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
|
||||||
|
|
||||||
// Replace the context with the actual completion
|
// Replace the context with the actual completion
|
||||||
const acceptedText = completionText;
|
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);
|
edit.replace(document.uri, rangeToReplace, acceptedText);
|
||||||
|
|
||||||
await vscode.workspace.applyEdit(edit);
|
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) {
|
async function provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, cancellationToken: vscode.CancellationToken) {
|
||||||
const item = new vscode.CompletionItem("Fabelous autocompletion");
|
const item = new vscode.CompletionItem("Fabelous autocompletion");
|
||||||
item.insertText = new vscode.SnippetString('${1:}');
|
item.insertText = new vscode.SnippetString('${1:}');
|
||||||
|
|
Loading…
Reference in New Issue