Skip to content

Commit bf04800

Browse files
author
nickchecan
committed
refactor: pass editor content as argument to chat function
1 parent aba7a8a commit bf04800

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/chat/ChatOrchestrator.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.ArrayList;
55
import java.util.List;
66

7-
import com.developer.nefarious.zjoule.plugin.chat.utils.EditorContentReader;
87
import com.developer.nefarious.zjoule.plugin.models.Role;
98

109
/**
@@ -18,8 +17,7 @@ public class ChatOrchestrator implements IChatOrchestrator {
1817
* {@inheritDoc}
1918
*/
2019
@Override
21-
public String getAnswer(final String userPrompt) {
22-
20+
public String getAnswer(final String userPrompt, final String editorContent) {
2321
List<IChatMessage> messages = new ArrayList<>();
2422

2523
// 0. Define which AI Client should be used
@@ -32,10 +30,8 @@ public String getAnswer(final String userPrompt) {
3230
List<IChatMessage> messageHistory = aiClient.getMessageHistory();
3331
messages.addAll(messageHistory);
3432

35-
// 2. Get content of the active window
33+
// 2. Get context
3634
String baseInstructions = Instruction.getMessage();
37-
String editorContent = EditorContentReader.readActiveEditorContent();
38-
3935
String systemInstructions = editorContent != null
4036
? baseInstructions + " Consider the following code as context: " + editorContent
4137
: baseInstructions;

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/chat/IChatOrchestrator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public interface IChatOrchestrator {
1919
* <li>Returning the response message as a string.</li>
2020
* </ol>
2121
*
22-
* @param userPrompt the prompt or query provided by the user.
22+
* @param userPrompt the prompt or query provided by the user
23+
* @param editorContent the editor content to be provided as context
2324
* @return the AI-generated response as a {@link String}.
2425
*/
25-
String getAnswer(final String userPrompt);
26+
String getAnswer(final String userPrompt, final String editorContent);
2627

2728
}

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/core/functions/PromptHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.eclipse.swt.widgets.Display;
88

99
import com.developer.nefarious.zjoule.plugin.chat.ChatOrchestrator;
10+
import com.developer.nefarious.zjoule.plugin.chat.utils.EditorContentReader;
1011

1112
/**
1213
* Handles user prompts from the browser and communicates with the chat orchestrator to generate responses.
@@ -49,9 +50,9 @@ public PromptHandler(final Browser browser, final String name) {
4950
* Handles a user prompt from the browser and initiates asynchronous processing to generate an AI response.
5051
*
5152
* <p>This method is invoked via the {@link BrowserFunction} interface when a corresponding JavaScript
52-
* function is called in the browser widget. It processes the first argument as a user prompt, retrieves
53-
* an AI-generated response asynchronously using the {@link ChatOrchestrator}, and delivers the response
54-
* back to the browser environment through the JavaScript function {@code receiveMessage}.</p>
53+
* function is called in the browser widget. It processes the first argument as a user prompt, read the editor
54+
* content, retrieves an AI-generated response asynchronously using the {@link ChatOrchestrator}, and delivers
55+
* the response back to the browser environment through the JavaScript function {@code receiveMessage}.</p>
5556
*
5657
* <p>The response is escaped to ensure it is safe for inclusion in JavaScript code, avoiding issues
5758
* caused by special characters.</p>
@@ -65,8 +66,10 @@ public PromptHandler(final Browser browser, final String name) {
6566
@Override
6667
public Object function(final Object[] arguments) {
6768
String userPrompt = arguments[0].toString();
69+
String editorContent = EditorContentReader.readActiveEditorContent();
6870

69-
CompletableFuture<String> futureResponse = CompletableFuture.supplyAsync(() -> chatOrchestrator.getAnswer(userPrompt));
71+
CompletableFuture<String> futureResponse = CompletableFuture.supplyAsync(
72+
() -> chatOrchestrator.getAnswer(userPrompt, editorContent));
7073

7174
futureResponse.thenAccept(response -> {
7275
Display.getDefault().asyncExec(new Runnable() {

0 commit comments

Comments
 (0)