Skip to content

Commit

Permalink
fix codelenses for generated prompts, add semantic finder to context …
Browse files Browse the repository at this point in the history
…menu
  • Loading branch information
ili16 committed Mar 18, 2024
1 parent 21ccc6d commit 8b20651
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
5 changes: 5 additions & 0 deletions extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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'"
}
Expand Down Expand Up @@ -87,7 +87,7 @@
"group": "Modernizer"
},
{
"title": "Generate random Prompt",
"title": "Explain me this code",
"command": "modernizer-vscode.randomExplanationPrompt",
"category": "Modernizer",
"group": "Modernizer"
Expand Down
2 changes: 1 addition & 1 deletion extension/src/CodelensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 28 additions & 16 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -171,7 +171,7 @@ async function randomExplanationPrompt() {
instructType: 'explanation'
};

await sendPromptToAPI(promptData);
await sendPromptToAPI(promptData, false);
}

async function generateCustomPrompt() {
Expand Down Expand Up @@ -204,7 +204,7 @@ async function generateCustomPrompt() {
gitURL: gitURL,
};

await sendPromptToAPI(promptData);
await sendPromptToAPI(promptData, true);
}

async function generateCustomPromptbyList() {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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<string | undefined> {
Expand Down Expand Up @@ -392,10 +399,15 @@ async function GetSimilarCode(): Promise<string[]> {
}
}

function displayGitURLs(gitURLs: string[]): void {
async function displayGitURLs(gitURLs: string[]): Promise<void> {
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}`);
});
Expand Down

0 comments on commit 8b20651

Please sign in to comment.