From 916ea8ca4a1560c37cbddb9c96623ea41011bcaf Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 10 Sep 2024 20:34:10 +0200 Subject: [PATCH] new code with partically work preview --- src/extension.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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:}');