moved command function outside of activate (cleanup)
This commit is contained in:
parent
110ebee3d8
commit
fd0f553738
|
@ -11,43 +11,8 @@ if (apiSystemMessage == "DEFAULT") apiSystemMessage = undefined;
|
||||||
const numPredict: number = VSConfig.get("max-tokens-predicted") || 500;
|
const numPredict: number = VSConfig.get("max-tokens-predicted") || 500;
|
||||||
const promptWindowSize: number = VSConfig.get("prompt-window-size") || 2000;
|
const promptWindowSize: number = VSConfig.get("prompt-window-size") || 2000;
|
||||||
|
|
||||||
// This method is called when your extension is activated
|
// Function called on ollama-coder.autocomplete
|
||||||
function activate(context: vscode.ExtensionContext) {
|
async function autocompleteCommand(document: vscode.TextDocument, position: vscode.Position, prompt: string, cancellationToken: vscode.CancellationToken) {
|
||||||
// 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) {
|
|
||||||
// Show a progress message
|
// Show a progress message
|
||||||
vscode.window.withProgress(
|
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
|
// Add the command to the context
|
||||||
|
|
Loading…
Reference in New Issue