Skip to content

Fixes #168 Diff not done on real text provided by the AI#172

Merged
jGauravGupta merged 10 commits into
mainfrom
feature
Sep 7, 2025
Merged

Fixes #168 Diff not done on real text provided by the AI#172
jGauravGupta merged 10 commits into
mainfrom
feature

Conversation

@jGauravGupta

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
@jGauravGupta jGauravGupta added this to the 3.3 milestone Sep 5, 2025
Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
.map(param -> param.getType().asString())
.collect(Collectors.joining(",")) + ")";
String signature = buildMethodSignature(method);
fileMethodSignatures.put(signature, method.toString().length());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually wondering why we cache the length; in any case, is the use of the parsed text correct here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By comparing the method body length, it detects whether any changes were suggested by the AI, so the method itself can be compared in the Diff panel instead of the entire class.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it. shouldn't a hash be more accurate? Of course anyway not on the parsed text.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it. shouldn't a hash be more accurate? Of course anyway not on the parsed text.

Length is just a quick heuristic, but a hash would be more accurate for detecting actual changes.

Map<String, Long> fileMethods = new HashMap<>();
for (MethodDeclaration method : methods) {
if (method.getParentNode().isPresent() && method.getParentNode().get() instanceof ObjectCreationExpr) {
if (isAnonymousInnerMethod(method)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've realised now we are not counting and saving the counter, but saving the position. Can you please update the comment too?

Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
if (edCu.getTypes().isNonEmpty()) {
methodSignatures.put(edCu.getType(0).getNameAsString(), edCu.toString());
} catch (Exception e2) {
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this case for? Maybe you can add a comment to explain the purpose. However please review how it can be refactored taking into account the try..catch above: if

CompilationUnit aiCu = StaticJavaParser.parse(editorText);
extractClasses(aiCu, editorText, lines, snippetSignatures);

failed above, it would fail here too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check was added to handle inner classes or partial code snippets. Anyway, my next focus will be on the patch-based way of suggesting code, so it can auto applied and reverted, specifically #159

Comment thread src/main/java/io/github/jeddict/ai/components/AssistantChat.java Outdated
.map(param -> param.getType().asString())
.collect(Collectors.joining(",")) + ")";
String signature = buildMethodSignature(method);
fileMethodSignatures.put(signature, method.toString().length());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it. shouldn't a hash be more accurate? Of course anyway not on the parsed text.

int classesCount = classDecls.size();

for (ClassOrInterfaceDeclaration classDecl : classDecls) {
if (classesCount == 1 || classDecl.isPublic()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be outside the loop and then you loop only if classesCount is >1? or at least break from the loop?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break isn’t needed since only one public class is allowed, and we still need to process other non-public top-level classes.

@jGauravGupta jGauravGupta merged commit b850533 into main Sep 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants