Completion contributor hard-coded trims '@'

Answered

Hello again,
hopefully last question for some time, but with CompletionContributor I've run into another issue, that I cannot use it for elements starting with a '@' char.

I've found that reason is within:

com.intellij.codeInsight.completion.CompletionData

public static String findPrefixStatic(final PsiElement insertedElement, final int offsetInFile) {
  return findPrefixStatic(insertedElement, offsetInFile, NOT_JAVA_ID);
}

That "NOT_JAVA_ID" has a CharacterPattern, that @ are trimmed from the beggining of completion element.

I've noticed, that this whole class is marked to be removed, but I'm not even sure, if after change this will remain or how can I override this, since it's not added from my Contributor, but set in place.

Is there some way to avoid this right now, or should I wait for new release?

Thanks again.

4 comments
Comment actions Permalink

Hi,

Please share the full context.

What is your completion implementation?

How to reproduce the issue? What do you type, and what do you expect to be completed/inserted?

0
Comment actions Permalink
class GdRootContributor : CompletionContributor() {
  override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
result.addElement(LookupElementBuilder.create("@export"));
result.addElement(LookupElementBuilder.create("@export1"));
result.addElement(LookupElementBuilder.create("@export12"));
}
}

Contributor adds an elements with "@export" value.
Then on empty line I have "@ex" as a single element.

After pressing ctrl+space It offers completion, but even in preview it shows, that "@" char is not matched, only "ex"

Even after accepting the completion, it duplicates unmatched "@" resulting in

All that is caused at some inner class mentioned in first post: 

com.intellij.codeInsight.completion.CompletionData

Which I'm not sure where comes from / how is handled, but it takes the existing element "@ex" and runs trim operation on it with that "NOT_JAVA_ID" pattern, that removes "@" from completion match -> then after accepting completion doe to "@" not being matched it duplicates it.

What I'd expect is to include "@" as part of completed string (so not having that NOT_JAVA_ID pattern used), so the whole "@ex" is matched (blue in pop-up) and only adds "port" to finish the string into "@export"

0
Comment actions Permalink

Hi,

Does the issue occurs when you implement the completion providers and use CompletionContributor.extend() approach?

0
Comment actions Permalink

Even like that

class GdRootContributor : CompletionContributor {
constructor() {
extend(
CompletionType.BASIC, psiElement(),
object : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
parameters: CompletionParameters,
context: ProcessingContext,
resultSet: CompletionResultSet,
) {
resultSet.addElement(LookupElementBuilder.create("@export"))
}
}
)
}
}

The result is unfortunately the same -> completion internaly removes '@' prefix in match and after accepting  completion duplicates it.

I've managed to get it around it, kind of, by making 2 different sets of completions
-> one for empty element with the whole text '@export'
-> second in element that already has '@' and adding only 'export'

But it's not a proper solution.

0

Please sign in to leave a comment.