diff --git a/src/extension.ts b/src/extension.ts index a738fc5..02fd31d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -53,12 +53,13 @@ function createFIMPrompt(prefix: string, language: string): string { return `${prefix}${language}\n`; } + const previewDecorationType = vscode.window.createTextEditorDecorationType({ after: { color: '#888888', // Grayed-out preview text fontStyle: 'italic', }, - isWholeLine: true, // Support multiline properly + isWholeLine: true, // Ensure it handles multiline properly }); async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationToken?: vscode.CancellationToken) { @@ -119,12 +120,13 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo range, renderOptions: { after: { - contentText: line, // Show each line + contentText: line, // Show each line properly } } }; }); + // Set decorations for each line textEditor.setDecorations(previewDecorationType, previewRanges); const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => { @@ -150,7 +152,11 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo const edit = new vscode.WorkspaceEdit(); const insertPosition = new vscode.Position(position.line, 0); edit.insert(document.uri, insertPosition, '\n' + completionText); - await vscode.workspace.applyEdit(edit); + + // Ensure response is added only once + if (!document.getText().includes(completionText)) { + await vscode.workspace.applyEdit(edit); + } const newPosition = new vscode.Position(position.line + lines.length, lines[lines.length - 1].length); textEditor.selection = new vscode.Selection(newPosition, newPosition); @@ -173,6 +179,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:}');