Skip to content

Commit 598ae89

Browse files
authoredOct 5, 2024··
Merge pull request #13 from jeddict/dev
Show description in smart code suggestion
2 parents 3f1c93f + 66083a0 commit 598ae89

File tree

8 files changed

+136
-63
lines changed

8 files changed

+136
-63
lines changed
 

‎src/main/java/io/github/jeddict/ai/JeddictChatModel.java

+32-43
Original file line numberDiff line numberDiff line change
@@ -390,31 +390,22 @@ public List<Snippet> suggestNextLineCode(String classDatas, String classContent,
390390
+ "Based on the provided Java source file content, suggest relevant code to be added at the placeholder location ${SUGGEST_CODE_LIST}. "
391391
+ "Suggest additional classes, interfaces, enums, or other top-level constructs. "
392392
+ "Ensure that the suggestions fit the context of the entire file. "
393-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
394-
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
395-
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
396-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
393+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
397394
+ "Java Source File Content:\n" + classContent;
398395
} else if (path.getLeaf().getKind() == Tree.Kind.COMPILATION_UNIT) {
399396
prompt = "You are an API server that suggests Java code for the outermost context of a Java source file, outside of any existing class. "
400397
+ "Based on the provided Java source file content, suggest relevant code to be added at the placeholder location ${SUGGEST_CODE_LIST}. "
401398
+ "Suggest package declarations, import statements, comments, or annotations for public class. "
402399
+ "Ensure that the suggestions fit the context of the entire file. "
403-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
404-
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
405-
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
406-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
400+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
407401
+ "Java Source File Content:\n" + classContent;
408402
} else if (path.getLeaf().getKind() == Tree.Kind.MODIFIERS
409403
&& path.getParentPath() != null
410404
&& path.getParentPath().getLeaf().getKind() == Tree.Kind.CLASS) {
411405
prompt = "You are an API server that suggests Java code modifications for a class. "
412406
+ "At the placeholder location ${SUGGEST_CODE_LIST}, suggest either a class-level modifier such as 'public', 'protected', 'private', 'abstract', 'final', or a relevant class-level annotation. "
413407
+ "Ensure that the suggestions are appropriate for the class context provided. "
414-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
415-
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
416-
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
417-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
408+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
418409
+ "Java Class Content:\n" + classContent;
419410
} else if (path.getLeaf().getKind() == Tree.Kind.MODIFIERS
420411
&& path.getParentPath() != null
@@ -423,52 +414,37 @@ public List<Snippet> suggestNextLineCode(String classDatas, String classContent,
423414
+ "At the placeholder location ${SUGGEST_CODE_LIST}, suggest method-level modifiers such as 'public', 'protected', 'private', 'abstract', 'static', 'final', 'synchronized', or relevant method-level annotations. "
424415
+ "Additionally, you may suggest method-specific annotations like '@Override', '@Deprecated', '@Transactional', etc. "
425416
+ "Ensure that the suggestions are appropriate for the method context provided. "
426-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
427-
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
428-
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
429-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
417+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
430418
+ "Java Method Content:\n" + classContent;
431419
} else if (path.getLeaf().getKind() == Tree.Kind.CLASS
432420
&& path.getParentPath() != null
433421
&& path.getParentPath().getLeaf().getKind() == Tree.Kind.CLASS) {
434422
prompt = "You are an API server that suggests Java code for an inner class at the placeholder location ${SUGGEST_CODE_LIST}. "
435423
+ "Based on the provided Java class content, suggest either relevant inner class modifiers such as 'public', 'private', 'protected', 'static', 'abstract', 'final', or a full inner class definition. "
436424
+ "Additionally, you may suggest class-level annotations for the inner class. Ensure that the suggestions are contextually appropriate for an inner class. "
437-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
438-
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
439-
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
440-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
425+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
441426
+ "Java Class Content:\n" + classContent;
442-
} else if (path.getLeaf().getKind() == Tree.Kind.CLASS
427+
} else if (path.getLeaf().getKind() == Tree.Kind.CLASS
443428
&& path.getParentPath() != null
444429
&& path.getParentPath().getLeaf().getKind() == Tree.Kind.COMPILATION_UNIT) {
445430
prompt = "You are an API server that suggests Java code for an class at the placeholder location ${SUGGEST_CODE_LIST}. "
446431
+ "Based on the provided Java class content, suggest either relevant class level members, attributes, constants, methods or blocks. "
447432
+ "Ensure that the suggestions are contextually appropriate for an class. "
448-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
449-
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
450-
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
451-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
433+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
452434
+ "Java Class Content:\n" + classContent;
453435
} else if (path.getLeaf().getKind() == Tree.Kind.PARENTHESIZED
454436
&& path.getParentPath() != null
455437
&& path.getParentPath().getLeaf().getKind() == Tree.Kind.IF) {
456438
prompt = "You are an API server that suggests Java code to enhance an if-statement. "
457439
+ "At the placeholder location ${SUGGEST_IF_CONDITIONS}, suggest additional conditional checks or actions within the if-statement. "
458440
+ "Ensure that the suggestions are contextually appropriate for the condition. "
459-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
460-
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
461-
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
462-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
441+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
463442
+ "Java If Statement Content:\n" + classContent;
464443
} else {
465444
prompt = "You are an API server that suggests Java code for a specific context in a given Java class at the placeholder location ${SUGGEST_CODE_LIST}. "
466445
+ "Based on the provided Java class content and the line of code: \"" + lineText + "\", suggest a relevant single line of code or a multi-line code block as appropriate for the context represented by the placeholder ${SUGGEST_CODE_LIST} in the Java class. "
467446
+ "Ensure that the suggestions are relevant to the context. "
468-
+ "Return a JSON array with few best suggestions without any additional text or explanation where each element is an object containing two fields: 'imports' and 'snippet'. "
469-
+ "'imports' should be an array of required Java import statements for the suggested code (if no imports are required, return an empty array). "
470-
+ "'snippet' should contain the suggested code as text block, which may include multiple lines formatted as a single string using \\n for line breaks. \n\n"
471-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
447+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
472448
+ "Java Class Content:\n" + classContent;
473449
}
474450

@@ -511,14 +487,23 @@ public List<String> suggestJavadocOrComment(String classDatas, String classConte
511487
return comments;
512488
}
513489

514-
public List<Snippet> suggestAnnotations(String classDatas, String classContent, String lineText) {
515-
String prompt = "You are an API server that suggests Java annotations for a specific context in a given Java class at the placeholder location ${SUGGEST_ANNOTATION_LIST}. "
516-
+ "Based on the provided Java class content and the line of code: \"" + lineText + "\", suggest relevant annotations that can be applied at the placeholder location represented by ${SUGGEST_ANNOTATION_LIST} in the Java Class. "
517-
+ "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
490+
String jsonRequest = "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing two fields: 'imports' and 'snippet'. "
518491
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
519492
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. "
520-
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n"
521-
+ "Ensure that the suggestions are appropriate for the given Java Class Content:\n\n" + classContent;
493+
+ "Make sure to escape any double quotes within the snippet using a backslash (\\) so that the JSON remains valid. \n\n";
494+
495+
496+
String jsonRequestWithDescription = "Return a JSON array with a few best suggestions without any additional text or explanation. Each element should be an object containing three fields: 'imports', 'snippet', and 'description'. "
497+
+ "'imports' should be an array of required Java import statements (if no imports are required, return an empty array). "
498+
+ "'snippet' should contain the suggested code as a text block, which may include multiple lines formatted as a single string using \\n for line breaks. "
499+
+ "'description' should be a very short explanation of what the snippet does and why it might be appropriate in this context, formatted with <b>, <\br> and optionally if required then include any imporant link with <a href=''> tags. "
500+
+ "Make sure to escape any double quotes within the snippet and description using a backslash (\\) so that the JSON remains valid. \n\n";
501+
502+
public List<Snippet> suggestAnnotations(String classDatas, String classContent, String lineText) {
503+
String prompt = "You are an API server that suggests Java annotations for a specific context in a given Java class at the placeholder location ${SUGGEST_ANNOTATION_LIST}. "
504+
+ "Based on the provided Java class content and the line of code: \"" + lineText + "\", suggest relevant annotations that can be applied at the placeholder location represented by ${SUGGEST_ANNOTATION_LIST} in the Java Class. "
505+
+ (preferencesManager.isDescriptionEnabled() ? jsonRequestWithDescription : jsonRequest)
506+
+ "Ensure that the suggestions are appropriate for the given Java Class Content:\n\n" + classContent;
522507

523508
// Generate the list of suggested annotations
524509
String jsonResponse = generate(prompt);
@@ -553,10 +538,14 @@ public List<Snippet> parseJsonToSnippets(String jsonResponse) {
553538

554539
// Extract the "snippet" field
555540
String snippet = jsonObject.getString("snippet");
556-
557-
// Create a new Snippet object and add it to the list
558-
Snippet snippetObj = new Snippet(snippet, importsList);
559-
snippets.add(snippetObj);
541+
if(jsonObject.has("description")){
542+
String descripion = jsonObject.getString("description");
543+
Snippet snippetObj = new Snippet(snippet, descripion, importsList);
544+
snippets.add(snippetObj);
545+
} else {
546+
Snippet snippetObj = new Snippet(snippet, importsList);
547+
snippets.add(snippetObj);
548+
}
560549
}
561550

562551
return snippets;

‎src/main/java/io/github/jeddict/ai/JeddictCompletionProvider.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private JeddictItem createItem(Snippet varName, String line, String lineTextBefo
312312
caretToEndLength = trimTrailingSpaces(textAfterCaret).length();
313313
}
314314
System.out.println("varName.getSnippet(), "+ varName.getSnippet() + caretOffset + " " + newcaretOffset);
315-
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getImports(), newcaretOffset, caretToEndLength, true, false, -1);
315+
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getDescription(), varName.getImports(), newcaretOffset, caretToEndLength, true, false, -1);
316316
return var;
317317
}
318318

@@ -392,22 +392,22 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
392392
String updateddoc = insertPlaceholderAtCaret(doc, caretOffset, "${SUGGEST_CODE_LIST}");
393393
List<Snippet> sugs = getJeddictChatModel(fileObject).suggestNextLineCode(classDataContent, updateddoc, line, path);
394394
for (Snippet varName : sugs) {
395-
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getImports(), caretOffset, true, false, -1);
395+
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getDescription(), varName.getImports(), caretOffset, true, false, -1);
396396
resultSet.addItem(var);
397397
}
398398
} else if (kind == Tree.Kind.BLOCK) {
399399
String updateddoc = insertPlaceholderAtCaret(doc, caretOffset, "${SUGGEST_CODE_LIST}");
400400
List<Snippet> sugs = getJeddictChatModel(fileObject).suggestNextLineCode(classDataContent, updateddoc, line, path);
401401
for (Snippet varName : sugs) {
402-
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getImports(), caretOffset, true, false, -1);
402+
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getDescription(), varName.getImports(), caretOffset, true, false, -1);
403403
resultSet.addItem(var);
404404
}
405405
} else if (kind == Tree.Kind.VARIABLE) {
406406
String updateddoc = insertPlaceholderAtCaret(doc, caretOffset, "${SUGGEST_VAR_NAMES_LIST}");
407407
String currentVarName = getVariableNameAtCaret(doc, caretOffset);
408408
List<String> sugs = getJeddictChatModel(fileObject).suggestVariableNames(classDataContent, updateddoc, line);
409409
for (String varName : sugs) {
410-
JeddictItem var = new JeddictItem(null, null, varName, Collections.emptyList(), caretOffset - currentVarName.length(), true, false, -1);
410+
JeddictItem var = new JeddictItem(null, null, varName, "", Collections.emptyList(), caretOffset - currentVarName.length(), true, false, -1);
411411
resultSet.addItem(var);
412412

413413
}
@@ -416,7 +416,7 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
416416
String currentVarName = getVariableNameAtCaret(doc, caretOffset);
417417
List<String> sugs = getJeddictChatModel(fileObject).suggestMethodNames(classDataContent, updateddoc, line);
418418
for (String varName : sugs) {
419-
JeddictItem var = new JeddictItem(null, null, varName, Collections.emptyList(), caretOffset - currentVarName.length(), true, false, -1);
419+
JeddictItem var = new JeddictItem(null, null, varName, "", Collections.emptyList(), caretOffset - currentVarName.length(), true, false, -1);
420420
resultSet.addItem(var);
421421
}
422422
} else if (kind == Tree.Kind.METHOD_INVOCATION) {
@@ -425,7 +425,7 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
425425
List<String> sugs = getJeddictChatModel(fileObject).suggestMethodInvocations(classDataContent, updateddoc, line);
426426
for (String varName : sugs) {
427427
varName = varName.replace("<", "&lt;").replace(">", "&gt;");
428-
JeddictItem var = new JeddictItem(null, null, varName, Collections.emptyList(), caretOffset - currentVarName.length(), true, false, -1);
428+
JeddictItem var = new JeddictItem(null, null, varName, "", Collections.emptyList(), caretOffset - currentVarName.length(), true, false, -1);
429429
resultSet.addItem(var);
430430

431431
}
@@ -441,7 +441,7 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
441441
String updateddoc = insertPlaceholderAtCaret(doc, caretOffset, "${SUGGEST_IF_CONDITIONS}");
442442
List<Snippet> sugs = getJeddictChatModel(fileObject).suggestNextLineCode(classDataContent, updateddoc, line, path);
443443
for (Snippet varName : sugs) {
444-
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getImports(), caretOffset, true, false, -1);
444+
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), varName.getDescription(), varName.getImports(), caretOffset, true, false, -1);
445445
resultSet.addItem(var);
446446
}
447447
} else {
@@ -470,7 +470,7 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
470470
} else if (varName.startsWith("//")) {
471471
varName = varName.substring(3);
472472
}
473-
JeddictItem var = new JeddictItem(null, null, varName, Collections.emptyList(), newcaretOffset, true, false, -1);
473+
JeddictItem var = new JeddictItem(null, null, varName, "", Collections.emptyList(), newcaretOffset, true, false, -1);
474474
resultSet.addItem(var);
475475

476476
}
@@ -484,7 +484,7 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
484484
} else if (varName.startsWith("* ")) {
485485
varName = varName.substring(2);
486486
}
487-
JeddictItem var = new JeddictItem(null, null, varName, Collections.emptyList(), newcaretOffset, true, false, -1);
487+
JeddictItem var = new JeddictItem(null, null, varName, "", Collections.emptyList(), newcaretOffset, true, false, -1);
488488
resultSet.addItem(var);
489489
}
490490
}
@@ -494,7 +494,7 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
494494
String updateddoc = insertPlaceholderAtCaret(doc, caretOffset, "${SUGGEST_CODE_LIST}");
495495
List<Snippet> sugs = getJeddictChatModel(fileObject).suggestNextLineCode(updateddoc, currentLine, mimeType);
496496
for (Snippet varName : sugs) {
497-
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(), Collections.emptyList(), caretOffset, true, false, -1);
497+
JeddictItem var = new JeddictItem(null, null, varName.getSnippet(),"", Collections.emptyList(), caretOffset, true, false, -1);
498498
resultSet.addItem(var);
499499
}
500500
}

‎src/main/java/io/github/jeddict/ai/JeddictItem.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class JeddictItem extends JavaCompletionItem {
3636
private static ImageIcon icon;
3737

3838
private String varName;
39+
private String description;
3940
private List<String> imports;
4041
private boolean newVarName;
4142
private boolean smartType;
@@ -46,10 +47,11 @@ public class JeddictItem extends JavaCompletionItem {
4647
private CharSequence assignToVarText;
4748
int caretToEndLength;
4849

49-
public JeddictItem(CompilationInfo info, TypeMirror type, String varName, List<String> imports, int substitutionOffset, int caretToEndLength, boolean newVarName, boolean smartType, int assignToVarOffset) {
50+
public JeddictItem(CompilationInfo info, TypeMirror type, String varName,String description, List<String> imports, int substitutionOffset, int caretToEndLength, boolean newVarName, boolean smartType, int assignToVarOffset) {
5051
super(substitutionOffset);
5152
this.varName = varName;
5253
this.imports = imports;
54+
this.description = description;
5355
this.caretToEndLength = caretToEndLength;
5456
this.newVarName = newVarName;
5557
this.smartType = true;
@@ -58,9 +60,10 @@ public JeddictItem(CompilationInfo info, TypeMirror type, String varName, List<S
5860
this.assignToVarText = assignToVarOffset < 0 ? null : createAssignToVarText(info, type, varName);
5961
}
6062

61-
public JeddictItem(CompilationInfo info, TypeMirror type, String varName, List<String> imports, int substitutionOffset, boolean newVarName, boolean smartType, int assignToVarOffset) {
63+
public JeddictItem(CompilationInfo info, TypeMirror type, String varName, String description,List<String> imports, int substitutionOffset, boolean newVarName, boolean smartType, int assignToVarOffset) {
6264
super(substitutionOffset);
6365
this.varName = varName;
66+
this.description = description;
6467
this.imports = imports;
6568
this.caretToEndLength = -1;
6669
this.newVarName = newVarName;
@@ -180,8 +183,22 @@ public String getText() {
180183
.replace("<", "&lt;")
181184
.replace(">", "&gt;");
182185

183-
String htmlFormattedString = "<html><body><pre>" + escapedString + "</pre></body></html>";
184-
return htmlFormattedString;
186+
String keywordsPattern = "\\b("
187+
+ "public|private|protected|static|final|abstract|synchronized|native|strictfp|transient|volatile|"
188+
+ "boolean|byte|char|short|int|long|float|double|void|"
189+
+ "if|else|switch|case|default|break|continue|return|for|while|do|"
190+
+ "try|catch|finally|throw|throws|assert|"
191+
+ "class|interface|extends|implements|new|this|super|"
192+
+ "import|package|enum|instanceof"
193+
+ ")\\b|[{}]";
194+
escapedString = escapedString.replaceAll(keywordsPattern, "<b>$0</b>");
195+
escapedString = escapedString.replaceAll("System\\.out\\.println", "<i>System.out.println</i>");
196+
197+
if (description != null && !description.isEmpty()) {
198+
return "<html><body><pre>" + escapedString + "\n\n\n" + description.replaceAll("<\br>", "\n") + "</pre></body></html>";
199+
} else {
200+
return "<html><body><pre>" + escapedString + "</pre></body></html>";
201+
}
185202
}
186203

187204
@Override

‎src/main/java/io/github/jeddict/ai/Snippet.java

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ public class Snippet {
1616
List<String> imports = new ArrayList<>();
1717

1818
String snippet;
19+
20+
String description;
21+
22+
public Snippet(String snippet, String description, List<String> imports) {
23+
this.snippet = snippet;
24+
this.description = description;
25+
this.imports = imports;
26+
}
1927

2028
public Snippet(String snippet, List<String> imports) {
2129
this.snippet = snippet;
@@ -34,4 +42,8 @@ public String getSnippet() {
3442
return snippet;
3543
}
3644

45+
public String getDescription() {
46+
return description;
47+
}
48+
3749
}

‎src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form

+22-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<Group type="103" groupAlignment="0" attributes="0">
4040
<Group type="102" alignment="0" attributes="0">
4141
<EmptySpace max="-2" attributes="0"/>
42-
<Component id="jLayeredPane1" pref="613" max="32767" attributes="0"/>
42+
<Component id="jLayeredPane1" pref="592" max="32767" attributes="0"/>
4343
<EmptySpace max="-2" attributes="0"/>
4444
</Group>
4545
</Group>
@@ -201,6 +201,14 @@
201201
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="enableHintCheckBoxActionPerformed"/>
202202
</Events>
203203
</Component>
204+
</SubComponents>
205+
</Container>
206+
<Container class="javax.swing.JLayeredPane" name="jLayeredPane9">
207+
208+
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
209+
<Property name="alignment" type="int" value="0"/>
210+
</Layout>
211+
<SubComponents>
204212
<Component class="javax.swing.JCheckBox" name="enableSmartCodeCheckBox">
205213
<Properties>
206214
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
@@ -211,6 +219,19 @@
211219
</Property>
212220
</Properties>
213221
</Component>
222+
<Component class="javax.swing.JCheckBox" name="showDescriptionCheckBox">
223+
<Properties>
224+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
225+
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.showDescriptionCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
226+
</Property>
227+
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
228+
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.showDescriptionCheckBox.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
229+
</Property>
230+
</Properties>
231+
<Events>
232+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="showDescriptionCheckBoxActionPerformed"/>
233+
</Events>
234+
</Component>
214235
</SubComponents>
215236
</Container>
216237
<Container class="javax.swing.JLayeredPane" name="jLayeredPane3">

‎src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ private void initComponents() {
3838
jLayeredPane4 = new javax.swing.JLayeredPane();
3939
aiAssistantActivationCheckBox = new javax.swing.JCheckBox();
4040
enableHintCheckBox = new javax.swing.JCheckBox();
41+
jLayeredPane9 = new javax.swing.JLayeredPane();
4142
enableSmartCodeCheckBox = new javax.swing.JCheckBox();
43+
showDescriptionCheckBox = new javax.swing.JCheckBox();
4244
jLayeredPane3 = new javax.swing.JLayeredPane();
4345
resetKeyButton = new javax.swing.JButton();
4446
cleanDataButton = new javax.swing.JButton();
@@ -116,11 +118,24 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
116118
});
117119
jLayeredPane4.add(enableHintCheckBox);
118120

121+
jLayeredPane1.add(jLayeredPane4);
122+
123+
jLayeredPane9.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
124+
119125
org.openide.awt.Mnemonics.setLocalizedText(enableSmartCodeCheckBox, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.enableSmartCodeCheckBox.text")); // NOI18N
120126
enableSmartCodeCheckBox.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.enableSmartCodeCheckBox.toolTipText")); // NOI18N
121-
jLayeredPane4.add(enableSmartCodeCheckBox);
127+
jLayeredPane9.add(enableSmartCodeCheckBox);
122128

123-
jLayeredPane1.add(jLayeredPane4);
129+
org.openide.awt.Mnemonics.setLocalizedText(showDescriptionCheckBox, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.showDescriptionCheckBox.text")); // NOI18N
130+
showDescriptionCheckBox.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.showDescriptionCheckBox.toolTipText")); // NOI18N
131+
showDescriptionCheckBox.addActionListener(new java.awt.event.ActionListener() {
132+
public void actionPerformed(java.awt.event.ActionEvent evt) {
133+
showDescriptionCheckBoxActionPerformed(evt);
134+
}
135+
});
136+
jLayeredPane9.add(showDescriptionCheckBox);
137+
138+
jLayeredPane1.add(jLayeredPane9);
124139

125140
jLayeredPane3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
126141

@@ -162,7 +177,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
162177
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163178
.addGroup(layout.createSequentialGroup()
164179
.addContainerGap()
165-
.addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 613, Short.MAX_VALUE)
180+
.addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 592, Short.MAX_VALUE)
166181
.addContainerGap())
167182
);
168183
layout.setVerticalGroup(
@@ -213,6 +228,10 @@ private void cleanDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//G
213228
JOptionPane.showMessageDialog(this, "Cache has been cleared successfully!", "Information", JOptionPane.INFORMATION_MESSAGE);
214229
}//GEN-LAST:event_cleanDataButtonActionPerformed
215230

231+
private void showDescriptionCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showDescriptionCheckBoxActionPerformed
232+
// TODO add your handling code here:
233+
}//GEN-LAST:event_showDescriptionCheckBoxActionPerformed
234+
216235
private final PreferencesManager preferencesManager = PreferencesManager.getInstance();
217236

218237
void load() {
@@ -229,6 +248,8 @@ void load() {
229248
enableHintCheckBox.setEnabled(true);
230249
enableSmartCodeCheckBox.setEnabled(true);
231250
}
251+
252+
showDescriptionCheckBox.setSelected(preferencesManager.isDescriptionEnabled());
232253
}
233254

234255
void store() {
@@ -237,6 +258,7 @@ void store() {
237258
preferencesManager.setGptModel((GPTModel) gptModelComboBox.getSelectedItem());
238259
preferencesManager.setHintsEnabled(enableHintCheckBox.isSelected());
239260
preferencesManager.setSmartCodeEnabled(enableSmartCodeCheckBox.isSelected());
261+
preferencesManager.setDescriptionEnabled(showDescriptionCheckBox.isSelected());
240262
}
241263

242264
boolean valid() {
@@ -262,6 +284,8 @@ boolean valid() {
262284
private javax.swing.JLayeredPane jLayeredPane6;
263285
private javax.swing.JLayeredPane jLayeredPane7;
264286
private javax.swing.JLayeredPane jLayeredPane8;
287+
private javax.swing.JLayeredPane jLayeredPane9;
265288
private javax.swing.JButton resetKeyButton;
289+
private javax.swing.JCheckBox showDescriptionCheckBox;
266290
// End of variables declaration//GEN-END:variables
267291
}

‎src/main/java/io/github/jeddict/ai/settings/PreferencesManager.java

+8
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,12 @@ public boolean isSmartCodeEnabled() {
146146
public void setSmartCodeEnabled(boolean enabled) {
147147
preferences.putBoolean("enableSmartCode", enabled);
148148
}
149+
150+
public boolean isDescriptionEnabled() {
151+
return preferences.getBoolean("showDecription", true);
152+
}
153+
154+
public void setDescriptionEnabled(boolean enabled) {
155+
preferences.putBoolean("showDecription", enabled);
156+
}
149157
}

‎src/main/resources/io/github/jeddict/ai/settings/Bundle.properties

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ AIAssistancePanel.cleanDataButton.text=Clean cache
1111
AIAssistancePanel.gptModelHelp.text=
1212
AIAssistancePanel.resetKeyButton.text=Reset OpenAI API Key
1313
AIAssistancePanel.gptModelLabel.text=GPT Model:
14-
AIAssistancePanel.enableSmartCodeCheckBox.text=Enable Smart Code Suggestion
1514
AIAssistancePanel.enableHintCheckBox.text=Enable Hints
1615
AIAssistancePanel.gptModelComboBox.toolTipText=Choose the GPT model for AI assistance. Different models may offer varied levels of complexity and speed.
1716
AIAssistancePanel.aiAssistantActivationCheckBox.toolTipText=Enable or disable the AI assistant for smart code completion and suggestions.
1817
AIAssistancePanel.enableHintCheckBox.toolTipText=Enable this option to receive hints and suggestions as you work.
19-
AIAssistancePanel.enableSmartCodeCheckBox.toolTipText=Enable AI-powered smart code suggestions for improved development experience.
2018
AIAssistancePanel.resetKeyButton.toolTipText=Click to reset the API key for AI assistant integration.
19+
AIAssistancePanel.enableSmartCodeCheckBox.toolTipText=Enable AI-powered smart code suggestions for improved development experience.
20+
AIAssistancePanel.enableSmartCodeCheckBox.text=Enable Smart Code Suggestion
21+
AIAssistancePanel.showDescriptionCheckBox.toolTipText=Enable AI-powered smart code suggestions for improved development experience.
22+
AIAssistancePanel.showDescriptionCheckBox.text=Show Snippet with Description

0 commit comments

Comments
 (0)
Please sign in to comment.