From 8b20651421440e2de1207bac0fe125fbdc202fe8 Mon Sep 17 00:00:00 2001 From: ili16 Date: Mon, 18 Mar 2024 23:07:53 +0100 Subject: [PATCH] fix codelenses for generated prompts, add semantic finder to context menu --- extension/CHANGELOG.md | 5 ++++ extension/README.md | 2 ++ extension/package.json | 12 ++++----- extension/src/CodelensProvider.ts | 2 +- extension/src/extension.ts | 44 ++++++++++++++++++++----------- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/extension/CHANGELOG.md b/extension/CHANGELOG.md index f7bb68f..4e39923 100644 --- a/extension/CHANGELOG.md +++ b/extension/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the "vscode-modernizer-extension" extension will be documented in this file. +## [v1.3.0] + +- save custom prompts to local settings.json +- find semantically similar functions via vector comparison + ## [v1.1.0] - add functionality to show next responses in output window diff --git a/extension/README.md b/extension/README.md index bfb90e6..0b81d9d 100644 --- a/extension/README.md +++ b/extension/README.md @@ -8,6 +8,8 @@ A VSCode extension for displaying and ranking most frequently asked prompts - Up- or Downvote the Response - Display the current Promptcount - Retrieve a random or the highest-ranked* prompt +- Save custom instructs locally +- find semantically similar functions via vector comparison ## Requirements diff --git a/extension/package.json b/extension/package.json index ee54c5a..cd86de6 100644 --- a/extension/package.json +++ b/extension/package.json @@ -2,7 +2,7 @@ "name": "modernizer-vscode", "displayName": "Modernizer", "description": "A VSCode extension for displaying and ranking most frequently asked prompts", - "version": "1.2.0", + "version": "1.3.0", "publisher": "IlijaKovacevic", "author": "Ilija Kovacevic", "icon": "resources/modernizer-logo.jpg", @@ -36,22 +36,22 @@ "when": "editorHasSelection && resourceScheme == 'file'" }, { - "command": "modernizer-vscode.showRandomResponse", + "command": "modernizer-vscode.randomExplanationPrompt", "group": "navigation", "when": "editorHasSelection && resourceScheme == 'file'" }, { - "command": "modernizer-vscode.randomExplanationPrompt", + "command": "modernizer-vscode.customPrompt", "group": "navigation", "when": "editorHasSelection && resourceScheme == 'file'" }, { - "command": "modernizer-vscode.customPrompt", + "command": "modernizer-vscode.PromptByList", "group": "navigation", "when": "editorHasSelection && resourceScheme == 'file'" }, { - "command": "modernizer-vscode.PromptByList", + "command": "modernizer-vscode.getSimilarCode", "group": "navigation", "when": "editorHasSelection && resourceScheme == 'file'" } @@ -87,7 +87,7 @@ "group": "Modernizer" }, { - "title": "Generate random Prompt", + "title": "Explain me this code", "command": "modernizer-vscode.randomExplanationPrompt", "category": "Modernizer", "group": "Modernizer" diff --git a/extension/src/CodelensProvider.ts b/extension/src/CodelensProvider.ts index ec9528c..cac4434 100644 --- a/extension/src/CodelensProvider.ts +++ b/extension/src/CodelensProvider.ts @@ -118,7 +118,7 @@ export class CodelensProvider implements vscode.CodeLensProvider { const codeLenses: vscode.CodeLens[] = []; const text = document.getText(); - const regex = /Generated new response with the instruct: /g; + const regex = /Generated new response with the custom instruct: /g; let match; while ((match = regex.exec(text))) { const line = document.lineAt(document.positionAt(match.index).line); diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 7181831..7423d99 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -131,7 +131,7 @@ let disposableSavePrompt = vscode.commands.registerCommand('modernizer-vscode.sa const outputWindowContent = editor.document.getText(); // Extract the instruct from the output window content - const instructRegex = /Generated new response with the instruct: (.*)/g; + const instructRegex = /Generated new response with the custom instruct: (.*)/g; const match = instructRegex.exec(outputWindowContent); if (!match || !match[1]) { vscode.window.showErrorMessage('No instruct found in the output window.'); @@ -171,7 +171,7 @@ async function randomExplanationPrompt() { instructType: 'explanation' }; - await sendPromptToAPI(promptData); + await sendPromptToAPI(promptData, false); } async function generateCustomPrompt() { @@ -204,7 +204,7 @@ async function generateCustomPrompt() { gitURL: gitURL, }; - await sendPromptToAPI(promptData); + await sendPromptToAPI(promptData, true); } async function generateCustomPromptbyList() { @@ -238,10 +238,10 @@ async function generateCustomPromptbyList() { }; - await sendPromptToAPI(promptData); + await sendPromptToAPI(promptData, false); } -async function sendPromptToAPI(promptData: any) { +async function sendPromptToAPI(promptData: any, custom: boolean){ const baseUrl: string = vscode.workspace.getConfiguration("modernizer-vscode").get("baseURL", "https://modernizer.milki-psy.dbis.rwth-aachen.de"); const generateRoute: string = "/generate"; @@ -273,23 +273,30 @@ async function sendPromptToAPI(promptData: any) { const responseBody = await response.json(); const responseText = responseBody.response || "No response field found"; - const outputWindow = vscode.window.createOutputChannel("Ollama Response"); - outputWindow.show(true); + OutputWindowGeneratedResponse(responseBody.instruct, responseText, responseBody.promptID, custom); - outputWindow.append(`Generated new response with the instruct: ${responseBody.instruct}\n\n`); - outputWindow.append(responseText + "\n"); - - if (responseBody.promptID) { - DisplayVoting(responseBody.promptID); - } else { - vscode.window.showWarningMessage("No promptId field found"); - } } catch (error: any) { vscode.window.showErrorMessage(`Error: ${error.message}`); } }); } +async function OutputWindowGeneratedResponse(instruct: string, response: string, ID: string, custom: boolean) { + + const outputWindow = vscode.window.createOutputChannel("Ollama Response", "plaintext"); + outputWindow.show(true); + + if (custom) { + outputWindow.append(`Generated new response with the custom instruct: ${instruct}\n\n`); + } else { + outputWindow.append(`Generated new response with the instruct: ${instruct}\n\n`); + } + outputWindow.append(response + "\n"); + + + DisplayVoting(ID); +} + async function showInstructTemplates(): Promise { @@ -392,10 +399,15 @@ async function GetSimilarCode(): Promise { } } -function displayGitURLs(gitURLs: string[]): void { +async function displayGitURLs(gitURLs: string[]): Promise { const outputChannel = vscode.window.createOutputChannel('Similar Git URLs'); outputChannel.show(); + outputChannel.appendLine('Similar Code can be found in the following Git URLs:\n\n'); + + let URL = await calculateURL(); + gitURLs = gitURLs.filter(gitURL => gitURL !== URL); + gitURLs.forEach((gitURL, index) => { outputChannel.appendLine(`URL ${index + 1}: ${gitURL}`); });