OC-16351 [swift override operator completion] provide caret position for invokeAutoPopup

Consider you want to autopopup completion only if there's a line feed before the caret.
If you're staying on a white space with a line feed inside you have to know the caret position
to make sure that the line feed is before it and not after:

Example:
The whitespace at caret does contain a line feed but it is after the caret position
```
class A { <caret>

}
```
This commit is contained in:
Max Medvedev
2018-07-21 15:00:52 +03:00
parent 94df837999
commit d601157cf4
2 changed files with 10 additions and 1 deletions
@@ -190,11 +190,20 @@ public abstract class CompletionContributor {
/**
* Allow autoPopup to appear after custom symbol
* @deprecated use {@link CompletionContributor#invokeAutoPopup(PsiElement, char, int)}
*/
@Deprecated
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
return false;
}
/**
* Allow autoPopup to appear after custom symbol
*/
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar, int offset) {
return invokeAutoPopup(position, typeChar);
}
/**
* Invoked in a read action in parallel to the completion process. Used to calculate the replacement offset
* (see {@link CompletionInitializationContext#setReplacementOffset(int)})
@@ -289,7 +289,7 @@ public class TypedHandler extends TypedActionHandlerBase {
final PsiElement element = file.findElementAt(offset);
if (element != null) {
for (CompletionContributor contributor : CompletionContributor.forLanguageHonorDumbness(element.getLanguage(), file.getProject())) {
if (contributor.invokeAutoPopup(element, charTyped)) {
if (contributor.invokeAutoPopup(element, charTyped, offset + 1)) {
LOG.debug(contributor + " requested completion autopopup when typing '" + charTyped + "'");
return true;
}