new version number and improved code so that there will be no trigger that often

This commit is contained in:
Falko Victor Habel 2024-10-13 09:35:58 +02:00
parent d1ccb89544
commit ac740e1f89
2 changed files with 7 additions and 44 deletions

View File

@ -1,6 +1,6 @@
{
"name": "fabelous-autocoder",
"version": "0.2.0",
"version": "0.2.1",
"displayName": "Fabelous Autocoder",
"description": "A simple to use Ollama autocompletion Plugin",
"icon": "icon.png",
@ -66,11 +66,6 @@
"default": 2000,
"description": "The size of the prompt in characters. NOT tokens, so can be set about 1.5-2x the max tokens of the model (varies)."
},
"fabelous-autocoder.completion keys": {
"type": "string",
"default": " ",
"description": "Character that the autocompletion item provider appear on. Multiple characters will be treated as different entries. REQUIRES RELOAD"
},
"fabelous-autocoder.response preview": {
"type": "boolean",
"default": true,
@ -123,6 +118,11 @@
"command": "fabelous-autocoder.handleBackspace",
"key": "backspace",
"when": "editorTextFocus"
},
{
"key": "alt+oem_plus",
"command": "fabelous-autocoder.autocomplete",
"when": "editorTextFocus"
}
],
"commands": [

View File

@ -275,54 +275,17 @@ async function handleBackspace() {
}
}
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:}');
item.documentation = new vscode.MarkdownString('Press `Enter` to get an autocompletion from Fabelous Autocoder');
if (config.responsePreview) {
await new Promise(resolve => setTimeout(resolve, config.responsePreviewDelay * 1000));
if (cancellationToken.isCancellationRequested) {
return [item];
}
const context = getContextLines(document, position);
const fimPrompt = createFIMPrompt(context, document.languageId);
try {
const result = await generateCompletion(fimPrompt, cancellationToken);
const preview = (result as any).preview;
if (preview) {
item.detail = preview.split('\n')[0];
}
} catch (error) {
console.error('Error fetching preview:', error);
}
}
if (config.continueInline || !config.responsePreview) {
item.command = {
command: 'fabelous-autocoder.autocomplete',
title: 'Fabelous Autocomplete',
arguments: []
};
}
return [item];
}
export function activate(context: vscode.ExtensionContext) {
updateConfig();
createPreviewDecorationType();
context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(updateConfig),
vscode.languages.registerCompletionItemProvider('*', { provideCompletionItems }, ...config.completionKeys),
vscode.commands.registerTextEditorCommand('fabelous-autocoder.autocomplete', autocompleteCommand),
vscode.commands.registerCommand('fabelous-autocoder.handleTab', handleTab),
vscode.commands.registerCommand('fabelous-autocoder.handleBackspace', handleBackspace) // Add this line
vscode.commands.registerCommand('fabelous-autocoder.handleBackspace', handleBackspace)
);
}
export function deactivate() {}