mirror of
https://github.com/SilasMarvin/lsp-ai.git
synced 2025-12-18 06:54:28 +01:00
Added tests and vscode extension is working
This commit is contained in:
@@ -22,12 +22,62 @@
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"title": "Configuration",
|
||||
"title": "LSP-AI",
|
||||
"properties": {
|
||||
"configuration.json": {
|
||||
"type": "json",
|
||||
"default": "{}",
|
||||
"description": "JSON configuration for LSP AI"
|
||||
"lsp-ai.serverConfiguration": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"memory": {
|
||||
"file_store": {}
|
||||
},
|
||||
"models": {
|
||||
"model1": {
|
||||
"type": "openai",
|
||||
"chat_endpoint": "https://api.openai.com/v1/chat/completions",
|
||||
"model": "gpt-4o",
|
||||
"auth_token_env_var_name": "OPENAI_API_KEY"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "JSON configuration for LSP-AI language server"
|
||||
},
|
||||
"lsp-ai.generationConfiguration": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"model": "model1",
|
||||
"parameters": {
|
||||
"max_tokens": 128,
|
||||
"max_context": 1024,
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a code completion tool. Use the [CONTEXT] and [CURRENT_CODE] provided to replace the <CURSOR> with the correct code. Do not reply with anything but valid code"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "[CONTEXT]\nprint(\"hello\")\n\n[CURRENT_CODE]\ndef print_to_screen(a): pri<CURSOR>\n\nprint_to_screen(\"test\")"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "nt_to_screen(a)"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "[CONTEXT]\ndef mul_two_nums(a, b):\n return a * b\n\n[CURRENT_CODE]\n# Test 5 * 25\nass<CURSOR>"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "ert mul_two_nums(5, 25) == 125"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "[CONTENT]\n{CONTENT}\n\n[CURRENT_CODE]\n{CODE}"
|
||||
}
|
||||
],
|
||||
"max_new_tokens": 32
|
||||
}
|
||||
},
|
||||
"description": "JSON configuration for LSP-AI generation"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,16 @@ let client: LanguageClient;
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// Configure the server options
|
||||
let serverOptions: ServerOptions = {
|
||||
const serverOptions: ServerOptions = {
|
||||
command: "lsp-ai",
|
||||
transport: TransportKind.stdio,
|
||||
};
|
||||
|
||||
// Options to control the language client
|
||||
let clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ pattern: "**" }]
|
||||
const config = vscode.workspace.getConfiguration("lsp-ai");
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ pattern: "**" }],
|
||||
initializationOptions: config.serverConfiguration
|
||||
};
|
||||
|
||||
// Create the language client and start the client
|
||||
@@ -35,11 +37,15 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// Register generate function
|
||||
const generateCommand = 'lsp-ai.generation';
|
||||
const generateCommandHandler = (editor: vscode.TextEditor) => {
|
||||
console.log("THE GENERATION CONFIGURATION");
|
||||
console.log(config.generationConfiguration);
|
||||
let params = {
|
||||
textDocument: {
|
||||
uri: editor.document.uri.toString(),
|
||||
},
|
||||
position: editor.selection.active
|
||||
position: editor.selection.active,
|
||||
model: config.generationConfiguration.model,
|
||||
parameters: config.generationConfiguration.parameters
|
||||
};
|
||||
client.sendRequest("textDocument/generation", params).then(result => {
|
||||
editor.edit((edit) => {
|
||||
@@ -51,6 +57,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
};
|
||||
context.subscriptions.push(vscode.commands.registerTextEditorCommand(generateCommand, generateCommandHandler));
|
||||
|
||||
// Register as an inline completion provider
|
||||
vscode.languages.registerInlineCompletionItemProvider({ pattern: '**' },
|
||||
{
|
||||
provideInlineCompletionItems: async (document: vscode.TextDocument, position: vscode.Position) => {
|
||||
@@ -58,7 +65,9 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
textDocument: {
|
||||
uri: document.uri.toString(),
|
||||
},
|
||||
position: position
|
||||
position: position,
|
||||
model: config.generationConfiguration.model,
|
||||
parameters: config.generationConfiguration.parameters
|
||||
};
|
||||
const result = await client.sendRequest("textDocument/generation", params);
|
||||
return [new vscode.InlineCompletionItem(result["generatedText"])];
|
||||
|
||||
Reference in New Issue
Block a user