feat/preview #3

Merged
Fabel merged 25 commits from feat/preview into develop 2024-10-09 12:27:58 +00:00
1 changed files with 8 additions and 7 deletions
Showing only changes of commit fb6e9a5d1f - Show all commits

View File

@ -108,23 +108,23 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
let completionText = response.data.response; let completionText = response.data.response;
completionText = completionText.replace(/<fim_middle>|<fim_suffix>|<fim_prefix>/g, '').trim(); completionText = completionText.replace(/<fim_middle>|<fim_suffix>|<fim_prefix>/g, '').trim();
// Split the completion text by new lines
// Split the completion text by new lines // Split the completion text by new lines
const lines = completionText.split('\n'); const lines = completionText.split('\n');
// Create a decoration for each line of the response // Create a decoration for each line of the response
const previewRanges = lines.map((line: string, idx: number) => { const previewRanges = lines.map((line: string, idx: number) => {
// Determine the start and end positions for each line // Determine the start position for each line
const startPos = new vscode.Position(position.line + idx, 0); const startPos = new vscode.Position(position.line + idx, 0);
const endPos = new vscode.Position(position.line + idx, line.length);
// Create a range covering the whole line // Create a range that decorates the line, spanning from start to start (empty range)
const range = new vscode.Range(startPos, endPos); const range = new vscode.Range(startPos, startPos);
return { return {
range, range,
renderOptions: { renderOptions: {
before: { after: {
contentText: line, contentText: line, // Display the current line
color: '#888888', color: '#888888',
fontStyle: 'italic', fontStyle: 'italic',
} }
@ -135,6 +135,7 @@ async function autocompleteCommand(textEditor: vscode.TextEditor, cancellationTo
// Apply the decorations for multiline preview // Apply the decorations for multiline preview
textEditor.setDecorations(previewDecorationType, previewRanges); textEditor.setDecorations(previewDecorationType, previewRanges);
let completionInserted = false; // Flag to track insertion let completionInserted = false; // Flag to track insertion
const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => { const disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {