From 0ad20487a2ec32d9a54a9619eb1609217f52b07b Mon Sep 17 00:00:00 2001 From: Gayan Perera Date: Sun, 7 Jul 2024 21:47:37 +0200 Subject: [PATCH] Improve type completion inside expressions --- .../codeassist/DOMCompletionEngine.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java index 31d6933a370..99fc18b512e 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/DOMCompletionEngine.java @@ -49,6 +49,7 @@ import org.eclipse.jdt.core.dom.PrimitiveType; import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.dom.Statement; +import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.VariableDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; @@ -284,13 +285,17 @@ public void acceptConstructor(int modifiers, char[] simpleTypeName, int paramete } var suitableBinding = this.recoveredNodeScanner.findClosestSuitableBinding(context, scope); if (suitableBinding != null) { - processMembers(suitableBinding, scope); - scope.stream() - .filter(binding -> this.pattern.matchesName(this.prefix.toCharArray(), - binding.getName().toCharArray())) - .map(binding -> toProposal(binding)).forEach(this.requestor::accept); - this.requestor.endReporting(); - return; + // this handle where we complete inside a expressions like + // Type type = new Type(); where complete after "Typ", since completion should support all type completions + // we should not return from this block at the end. + if (!(this.toComplete.getParent() instanceof Type)) { + processMembers(suitableBinding, scope); + scope.stream().filter( + binding -> this.pattern.matchesName(this.prefix.toCharArray(), binding.getName().toCharArray())) + .map(binding -> toProposal(binding)).forEach(this.requestor::accept); + this.requestor.endReporting(); + return; + } } ASTNode parent = this.toComplete;