Skip to content

Commit bf957fd

Browse files
authored
Merge pull request #16 from profiq/class-docstrings
Implement better support for documenting classes
2 parents 9d65349 + 007eb4d commit bf957fd

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "com.profiq"
7-
version = "0.1.3"
7+
version = "0.1.4"
88

99
repositories {
1010
mavenCentral()
@@ -19,7 +19,7 @@ dependencies {
1919
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
2020
intellij {
2121
version.set("2023.3")
22-
type.set("IC") // Target IDE Platform
22+
type.set("PC") // Target IDE Platform
2323

2424
plugins.set(listOf(/* Plugin Dependencies */))
2525
}

src/main/java/com/profiq/codexor/GenerateDocumentationAction.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
5656
PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT);
5757

5858
if (element == null) {
59-
showError("Please select a Python function");
59+
showError("Please select a Python function, method or class");
6060
return;
6161
}
6262

@@ -127,7 +127,10 @@ private String parseDocstring(String responseText) {
127127
Pattern pattern = Pattern.compile(":\n(\\s*\"\"\".*\"\"\")", Pattern.DOTALL);
128128
Matcher matcher = pattern.matcher(responseText);
129129
if (matcher.find()) {
130-
return matcher.group(1);
130+
String docstring = matcher.group(1);
131+
String[] docstringSplit = docstring.split("\"\"\"");
132+
docstring = docstringSplit[0] + "\"\"\"" + docstringSplit[1] + "\"\"\"";
133+
return docstring;
131134
} else {
132135
return "";
133136
}
@@ -187,7 +190,6 @@ private void showEditor(AnActionEvent e, String docstring) {
187190
editor.getContentComponent().setPreferredSize(new Dimension(1000, 800));
188191
var confirmBtn = new JButton("Insert");
189192

190-
191193
Editor mainEditor = e.getData(CommonDataKeys.EDITOR);
192194
Document mainDocument = mainEditor.getDocument();
193195
LogicalPosition caretPosition = mainEditor.getCaretModel().getLogicalPosition();
@@ -225,6 +227,7 @@ private String applyIndentation(String docstring, String indentation) {
225227

226228
for (String line : lines) {
227229
unindented.append(indentation);
230+
228231
if (line.length() >= minIndent) {
229232
unindented.append(line.substring(minIndent));
230233
}
@@ -242,7 +245,7 @@ private String determineCorrectIndentation(String code) {
242245
Matcher matcher = pattern.matcher(code);
243246

244247
if(matcher.find()) {
245-
return matcher.group(1);
248+
return matcher.group(1).replace("\n", "");
246249
}
247250

248251
return "";

src/main/java/com/profiq/codexor/SettingsConfigurable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SettingsConfigurable implements Configurable {
1616
public static String MODEL_SETTINGS_KEY = "codexor.model";
1717
public static String MODEL_DEFAULT = "gpt-3.5-turbo";
1818
public static String PROMPT_SETTINGS_KEY = "codexor.prompt";
19-
public static String PROMPT_DEFAULT = "Generate high-quality docstring for the following Python function including function signature: ";
19+
public static String PROMPT_DEFAULT = "Generate high-quality docstring for the following Python class or function. Use the reStructuredText docstring format. Only return the docstring for the top-level element:";
2020

2121
private final JTextField apiKeyField;
2222
private final JTextField modelField;

0 commit comments

Comments
 (0)