moved command function outside of activate (cleanup)

This commit is contained in:
Nathan Hedge 2023-12-20 16:06:47 -06:00
parent 110ebee3d8
commit fd0f553738
No known key found for this signature in database
GPG Key ID: 1ADBA36D6E304C5C
1 changed files with 92 additions and 89 deletions

View File

@ -11,43 +11,8 @@ if (apiSystemMessage == "DEFAULT") apiSystemMessage = undefined;
const numPredict: number = VSConfig.get("max-tokens-predicted") || 500;
const promptWindowSize: number = VSConfig.get("prompt-window-size") || 2000;
// This method is called when your extension is activated
function activate(context: vscode.ExtensionContext) {
// Register a completion provider for JavaScript files
const provider = vscode.languages.registerCompletionItemProvider("*", {
async provideCompletionItems(document, position, cancellationToken) {
// Get the current prompt
let prompt = document.getText(new vscode.Range(document.lineAt(0).range.start, position));
prompt = prompt.substring(Math.max(0, prompt.length - promptWindowSize), prompt.length);
// Check if the prompt is not empty and ends with a dot
if (prompt) {
// Create a completion item
const item = new vscode.CompletionItem("Autocomplete with Ollama");
// Set the insert text to a placeholder
item.insertText = new vscode.SnippetString('${1:}');
// Set the documentation to a message
item.documentation = new vscode.MarkdownString('Press `Enter` to get a completion from Ollama');
// Set the command to trigger the completion
item.command = {
command: 'ollama-coder.autocomplete',
title: 'Ollama',
arguments: [document, position, prompt, cancellationToken]
};
// Return the completion item
return [item];
}
},
},
"\n", " "
);
// Add the completion provider to the context
context.subscriptions.push(provider);
// Register a command for getting a completion from Ollama
const disposable = vscode.commands.registerCommand(
"ollama-coder.autocomplete",
async function (document: vscode.TextDocument, position: vscode.Position, prompt: string, cancellationToken: vscode.CancellationToken) {
// Function called on ollama-coder.autocomplete
async function autocompleteCommand(document: vscode.TextDocument, position: vscode.Position, prompt: string, cancellationToken: vscode.CancellationToken) {
// Show a progress message
vscode.window.withProgress(
{
@ -136,6 +101,44 @@ function activate(context: vscode.ExtensionContext) {
}
);
}
// This method is called when your extension is activated
function activate(context: vscode.ExtensionContext) {
// Register a completion provider for JavaScript files
const provider = vscode.languages.registerCompletionItemProvider("*", {
async provideCompletionItems(document, position, cancellationToken) {
// Get the current prompt
let prompt = document.getText(new vscode.Range(document.lineAt(0).range.start, position));
prompt = prompt.substring(Math.max(0, prompt.length - promptWindowSize), prompt.length);
// Check if the prompt is not empty and ends with a dot
if (prompt) {
// Create a completion item
const item = new vscode.CompletionItem("Autocomplete with Ollama");
// Set the insert text to a placeholder
item.insertText = new vscode.SnippetString('${1:}');
// Set the documentation to a message
item.documentation = new vscode.MarkdownString('Press `Enter` to get a completion from Ollama');
// Set the command to trigger the completion
item.command = {
command: 'ollama-coder.autocomplete',
title: 'Ollama',
arguments: [document, position, prompt, cancellationToken]
};
// Return the completion item
return [item];
}
},
},
"\n", " "
);
// Add the completion provider to the context
context.subscriptions.push(provider);
// Register a command for getting a completion from Ollama
const disposable = vscode.commands.registerCommand(
"ollama-coder.autocomplete",
autocompleteCommand
);
// Add the command to the context