From a9ba9a8772724a085b0bdfb301c1d4a01967cd54 Mon Sep 17 00:00:00 2001 From: yaad96 Date: Mon, 1 Apr 2024 22:05:56 -0400 Subject: [PATCH] Added new command: "RECEIVE_LLM_SNIPPET_MSG" functionality --- src/FollowAndAuthorRulesProcessor.ts | 16 +++++++++++++++- src/WebSocketConstants.ts | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/FollowAndAuthorRulesProcessor.ts b/src/FollowAndAuthorRulesProcessor.ts index 6b57096..a975d61 100644 --- a/src/FollowAndAuthorRulesProcessor.ts +++ b/src/FollowAndAuthorRulesProcessor.ts @@ -26,6 +26,7 @@ export class FollowAndAuthorRulesProcessor { private tagTable: Tag[]; private currentProjectPath: string; public readonly wsMessages: string[] = [ + WebSocketConstants.RECEIVE_LLM_SNIPPET_MSG, WebSocketConstants.RECEIVE_SNIPPET_XML_MSG, WebSocketConstants.RECEIVE_MODIFIED_RULE_MSG, WebSocketConstants.RECEIVE_MODIFIED_TAG_MSG, @@ -92,10 +93,23 @@ export class FollowAndAuthorRulesProcessor { const command = jsonData.command; switch (command) { + + case WebSocketConstants.RECEIVE_LLM_SNIPPET_MSG: + console.log("CAME HERE"); + const code = jsonData.data.code; + // Format the explanation as a multiline comment + const explanationAsComment = `/*\n * ${jsonData.data.explanation.replace(/\n/g, '\n * ')}\n */\n\n`; + + // Create a new split window with the explanation comment at the top and the code below + vscode.workspace.openTextDocument({ content: explanationAsComment + code, language: 'java' }) // Adjust the language as necessary + .then(document => { + vscode.window.showTextDocument(document, { preview: false, viewColumn: vscode.ViewColumn.Beside }); + }); + case WebSocketConstants.RECEIVE_SNIPPET_XML_MSG: // Handle RECEIVE_SNIPPET_XML_MSG const xmlString = jsonData.data.xml; - + const tempXmlFilePath = path.join(this.currentProjectPath, Constants.TEMP_XML_FILE); const xmlHeader = Constants.XML_HEADER; diff --git a/src/WebSocketConstants.ts b/src/WebSocketConstants.ts index 0d249d7..7a1b134 100644 --- a/src/WebSocketConstants.ts +++ b/src/WebSocketConstants.ts @@ -2,6 +2,7 @@ export class WebSocketConstants { static readonly MESSAGE_KEY_COMMAND: string = "command"; static readonly MESSAGE_KEY_DATA: string = "data"; + static readonly RECEIVE_LLM_SNIPPET_MSG:string= "LLM_SNIPPET"; static readonly RECEIVE_MODIFIED_RULE_MSG: string = "MODIFIED_RULE"; static readonly RECEIVE_MODIFIED_TAG_MSG: string = "MODIFIED_TAG"; static readonly RECEIVE_SNIPPET_XML_MSG: string = "XML_RESULT";