remove_compeltion_items #8

Merged
Fabel merged 7 commits from remove_compeltion_items into develop 2024-10-13 11:59:25 +00:00
2 changed files with 7 additions and 44 deletions
Showing only changes of commit ac740e1f89 - Show all commits

View File

@ -1,6 +1,6 @@
{ {
"name": "fabelous-autocoder", "name": "fabelous-autocoder",
"version": "0.2.0", "version": "0.2.1",
"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",
@ -66,11 +66,6 @@
"default": 2000, "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)." "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": { "fabelous-autocoder.response preview": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
@ -123,6 +118,11 @@
"command": "fabelous-autocoder.handleBackspace", "command": "fabelous-autocoder.handleBackspace",
"key": "backspace", "key": "backspace",
"when": "editorTextFocus" "when": "editorTextFocus"
},
{
"key": "alt+oem_plus",
"command": "fabelous-autocoder.autocomplete",
"when": "editorTextFocus"
} }
], ],
"commands": [ "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) { export function activate(context: vscode.ExtensionContext) {
updateConfig(); updateConfig();
createPreviewDecorationType(); createPreviewDecorationType();
context.subscriptions.push( context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(updateConfig), vscode.workspace.onDidChangeConfiguration(updateConfig),
vscode.languages.registerCompletionItemProvider('*', { provideCompletionItems }, ...config.completionKeys),
vscode.commands.registerTextEditorCommand('fabelous-autocoder.autocomplete', autocompleteCommand), vscode.commands.registerTextEditorCommand('fabelous-autocoder.autocomplete', autocompleteCommand),
vscode.commands.registerCommand('fabelous-autocoder.handleTab', handleTab), 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() {} export function deactivate() {}