Skip to content

Commit

Permalink
add import required proposal for type completions
Browse files Browse the repository at this point in the history
  • Loading branch information
gayanper authored and mickaelistria committed Jul 8, 2024
1 parent d3148e9 commit 4b6de2f
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,12 @@ private String qualifiedTypeName(ITypeBinding typeBinding) {
private CompletionProposal toProposal(IType type) {
// TODO add import if necessary
InternalCompletionProposal res = new InternalCompletionProposal(CompletionProposal.TYPE_REF, this.offset);
res.setName(type.getElementName().toCharArray());
char[] simpleName = type.getElementName().toCharArray();
char[] signature = Signature.createTypeSignature(type.getFullyQualifiedName(), true).toCharArray();

res.setName(simpleName);
res.setCompletion(type.getElementName().toCharArray());
res.setSignature(Signature.createTypeSignature(type.getFullyQualifiedName(), true).toCharArray());
res.setSignature(signature);
res.setReplaceRange(!(this.toComplete instanceof FieldAccess) ? this.toComplete.getStartPosition() : this.offset, this.offset);
try {
res.setFlags(type.getFlags());
Expand All @@ -477,6 +480,16 @@ private CompletionProposal toProposal(IType type) {
res.completionEngine = this.nestedEngine;
res.nameLookup = this.nameEnvironment.nameLookup;
// set defaults for now to avoid error downstream
res.setRequiredProposals(new CompletionProposal[] { toImportProposal(simpleName, signature) });
return res;
}

private CompletionProposal toImportProposal(char[] simpleName, char[] signature) {
InternalCompletionProposal res = new InternalCompletionProposal(CompletionProposal.TYPE_IMPORT, this.offset);
res.setName(simpleName);
res.setSignature(signature);
res.completionEngine = this.nestedEngine;
res.nameLookup = this.nameEnvironment.nameLookup;
res.setRequiredProposals(new CompletionProposal[0]);
return res;
}
Expand Down

0 comments on commit 4b6de2f

Please sign in to comment.