Skip to content

Commit 4f18c15

Browse files
Fixing #308 without touching interative mode (#319)
1 parent 7076bc8 commit 4f18c15

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/main/java/io/github/jeddict/ai/util/ContextHelper.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Base64;
2727
import java.util.List;
2828
import java.util.Set;
29+
import java.util.logging.Logger;
2930
import java.util.stream.Collectors;
3031
import org.netbeans.api.project.Project;
3132
import org.openide.filesystems.FileObject;
@@ -37,6 +38,8 @@
3738
*/
3839
public class ContextHelper {
3940

41+
final static Logger LOG = Logger.getLogger(ContextHelper.class.getName());
42+
4043
public static String getProjectContext(
4144
final Set<FileObject> projectContext,
4245
final Project project,
@@ -113,10 +116,17 @@ public static String getTextFilesContext(
113116
inputForAI.append(relativePath)
114117
.append("\n");
115118
} else {
119+
LOG.finest(() -> "including file " + file + " in context");
116120
try {
117121
final String mimeType = Files.probeContentType(Path.of(file.toURI()));
118122

119-
if (!mimeType.startsWith("image")) {
123+
//
124+
// mimeType can be null if probeContentType() is not able
125+
// to determine the mime type; it should not happen often though
126+
// as getFilesContextList() returnes files with a controlled
127+
// list of extensions (via configuration)
128+
//
129+
if (mimeType != null && !mimeType.startsWith("image")) {
120130
String text = getLatestContent(file);
121131
if (text != null) {
122132
if ("java".equals(file.getExt()) && excludeJavadoc) {
@@ -128,8 +138,11 @@ public static String getTextFilesContext(
128138
.append(text)
129139
.append("\n\n");
130140
}
141+
} else {
142+
LOG.finest(() -> file + " discarted due to mime type " + mimeType);
131143
}
132144
} catch (Exception ex) {
145+
LOG.finest(() -> "ups, error " + ex + " in including files in context");
133146
Exceptions.printStackTrace(ex);
134147
}
135148
}

0 commit comments

Comments
 (0)