Compare commits

..

No commits in common. "remove_compeltion_items" and "main" have entirely different histories.

3 changed files with 47 additions and 9 deletions

View File

@ -12,7 +12,7 @@ Fabelous Autocoder is a powerful VS Code extension that provides intelligent cod
## How It Works ## How It Works
1. Trigger the autocompletion by typing the completion key (alt+oem_plus). 1. Trigger the autocompletion by typing a completion key (configurable, default is space).
2. The extension sends your current code context to the configured API. 2. The extension sends your current code context to the configured API.
3. A code completion is generated and displayed as a preview. 3. A code completion is generated and displayed as a preview.
4. Accept the completion with `Tab` or decline it with `Backspace`. 4. Accept the completion with `Tab` or decline it with `Backspace`.
@ -21,7 +21,7 @@ Fabelous Autocoder is a powerful VS Code extension that provides intelligent cod
![Fabelous Autocoder Showcase](demo.gif) ![Fabelous Autocoder Showcase](demo.gif)
1. **Trigger Completion**: Type normally and hit the completion key (alt+oem_plus). 1. **Trigger Completion**: Type normally and hit the completion key (space by default).
2. **Preview**: The suggested completion appears in light gray text. 2. **Preview**: The suggested completion appears in light gray text.
3. **Accept**: Press `Tab` to accept the entire suggestion. 3. **Accept**: Press `Tab` to accept the entire suggestion.
4. **Decline**: Press `Backspace` to remove the preview and decline the suggestion. 4. **Decline**: Press `Backspace` to remove the preview and decline the suggestion.
@ -36,6 +36,7 @@ Customize Fabelous Autocoder through VS Code settings:
- `fabelous-autocoder.temperature`: Control the randomness of completions. - `fabelous-autocoder.temperature`: Control the randomness of completions.
- `fabelous-autocoder.max tokens predicted`: Set the maximum length of completions. - `fabelous-autocoder.max tokens predicted`: Set the maximum length of completions.
- `fabelous-autocoder.prompt window size`: Adjust the context window size. - `fabelous-autocoder.prompt window size`: Adjust the context window size.
- `fabelous-autocoder.completion keys`: Set custom completion trigger keys.
- `fabelous-autocoder.response preview`: Toggle preview functionality. - `fabelous-autocoder.response preview`: Toggle preview functionality.
- `fabelous-autocoder.preview max tokens`: Limit preview length. - `fabelous-autocoder.preview max tokens`: Limit preview length.
- `fabelous-autocoder.preview delay`: Add delay before showing preview. - `fabelous-autocoder.preview delay`: Add delay before showing preview.

View File

@ -1,6 +1,6 @@
{ {
"name": "fabelous-autocoder", "name": "fabelous-autocoder",
"version": "0.2.1", "version": "0.2.0",
"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,6 +66,11 @@
"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,
@ -118,11 +123,6 @@
"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,17 +275,54 @@ 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) vscode.commands.registerCommand('fabelous-autocoder.handleBackspace', handleBackspace) // Add this line
); );
} }
export function deactivate() {} export function deactivate() {}