Compare commits

..

8 Commits

5 changed files with 50 additions and 104 deletions

1
2exe.txt Normal file
View File

@ -0,0 +1 @@
vsce package --baseContentUrl https://gitea.fabelous.app/fabel/Fabelous-Autocoder/src/branch/main --baseImagesUrl https://gitea.fabelous.app/fabel/Fabelous-Autocoder/src/branch/main

102
README.md
View File

@ -1,76 +1,58 @@
# Fabelous Autocoder # Fabelous Autocoder
Fabelous Autocoder is a Visual Studio Code extension that provides an easy-to-use interface for Ollama autocompletion. This extension allows developers to use Ollama's powerful language models to generate code completions as they type. It is highly customizable, allowing users to configure various settings to fit their needs. Fabelous Autocoder is a powerful VS Code extension that provides intelligent code completion using advanced language models. It offers seamless integration with your development workflow, allowing you to generate and preview code suggestions with ease.
![Fabelous Autocoder in Action](demo.gif)
## Features ## Features
- Autocompletion using Ollama language models - **Intelligent Code Completion**: Leverages advanced language models to provide context-aware code suggestions.
- Customizable completion keys - **Preview Functionality**: View generated code completions before accepting them.
- Inline preview of generated completions - **Easy Accept/Decline**: Use simple keyboard shortcuts to accept or decline suggestions.
- Configurable maximum tokens predicted - **Customizable**: Configure various parameters like API endpoint, model, and response behavior.
- Configurable prompt window size - **Language Agnostic**: Works with multiple programming languages.
- Configurable response preview delay
- Configurable temperature for the model
## Installation ## How It Works
You can also download the extension from the release tab of the following Git repository:
[Fabelous-Autocoder Git Repository](https://gitea.fabelous.app/fabel/Fabelous-Autocoder.git) 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.
To do so, follow these steps: 3. A code completion is generated and displayed as a preview.
4. Accept the completion with `Tab` or decline it with `Backspace`.
1. Visit the repository link.
2. Click on the "Releases" tab.
3. Look for the latest release and click on it.
4. Download the extension file compatible with your operating system.
5. Install the extension manually in Visual Studio Code.
After installation, you'll be able to use the Fabelous Autocoder extension in your Visual Studio Code environment.
## Configuration
Fabelous Autocoder is highly customizable, allowing users to configure various settings to fit their needs. To access the configuration settings, follow these steps:
1. Open Visual Studio Code
2. Click on the Settings icon on the sidebar (or press `Ctrl+,`)
3. Search for "Fabelous Autocoder" in the search bar
4. Configure the desired settings
Here are some of the available configuration options:
- `fabelous-autocoder.endpoint`: The endpoint of the Ollama REST API
- `fabelous-autocoder.authentication`: The authentication token for Ollama
- `fabelous-autocoder.model`: The model to use for generating completions
- `fabelous-autocoder.max tokens predicted`: The maximum number of tokens generated by the model
- `fabelous-autocoder.prompt window size`: The size of the prompt in characters
- `fabelous-autocoder.completion keys`: The characters that trigger the autocompletion item provider
- `fabelous-autocoder.response preview`: Whether to show a preview of the generated completion inline
- `fabelous-autocoder.preview max tokens`: The maximum number of tokens generated for the response preview
- `fabelous-autocoder.preview delay`: The time to wait before starting inline preview generation
- `fabelous-autocoder.continue inline`: Whether to continue autocompletion after the inline preview
- `fabelous-autocoder.temperature`: The temperature of the model
- `fabelous-autocoder.keep alive`: The time in minutes before Ollama unloads the model
Note that changing the `completion keys` setting requires a reload of Visual Studio Code.
## Usage ## Usage
To use Fabelous Autocoder, simply start typing in the editor. When the configured completion keys are pressed, the extension will generate a completion using the configured Ollama model. The completion will be displayed inline with a preview of the generated code. If the `continue inline` setting is enabled, the extension will continue generating completions after the inline preview. ![Fabelous Autocoder Showcase](demo.gif)
To generate a multi-line completion, press `Enter` after the inline preview. This will open a new editor with the generated completion. 1. **Trigger Completion**: Type normally and hit the completion key (space by default).
2. **Preview**: The suggested completion appears in light gray text.
3. **Accept**: Press `Tab` to accept the entire suggestion.
4. **Decline**: Press `Backspace` to remove the preview and decline the suggestion.
5. **Partial Accept**: You can continue typing to partially accept the suggestion.
To customize the behavior of the extension, see the Configuration section above. ## Configuration
## License Customize Fabelous Autocoder through VS Code settings:
Fabelous Autocoder is licensed under the CC BY-ND 4.0 license. See the [LICENSE](https://gitea.fabelous.app/fabel/Fabelous-Autocoder/src/branch/main/LICENSE) file for more information. - `fabelous-autocoder.endpoint`: API endpoint for the language model.
- `fabelous-autocoder.model`: Specify the model to use.
- `fabelous-autocoder.temperature`: Control the randomness 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.completion keys`: Set custom completion trigger keys.
- `fabelous-autocoder.response preview`: Toggle preview functionality.
- `fabelous-autocoder.preview max tokens`: Limit preview length.
- `fabelous-autocoder.preview delay`: Add delay before showing preview.
- `fabelous-autocoder.continue inline`: Control inline continuation behavior.
## Acknowledgments ## Installation
Fabelous Autocoder was created by [Falko Habel](https://gitea.fabelous.app/fabel). It was inspired by the [Ollama](https://ollama.ai) project.
1. [Click here to download the latest version](https://gitea.fabelous.app/Fabel/Fabelous-Autocoder/releases/download/latest/fabelous-autocoder-0.2.0.vsix)
2. Open Visual Studio Code
3. Go to Extensions (Ctrl+Shift+X)
4. Click on the three dots in the upper-right corner and select "Install from VSIX..."
5. Navigate to the location where you extracted Fabelous Autocoder and select the .vsix file
6. Click "Install" to install the extension
## Requirements
- VS Code version 1.89.0 or higher
- Internet connection for API calls

BIN
demo.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 1.3 MiB

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() {}