From d601157cf4c79f32b727476ade0a245674c0774b Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Sat, 21 Jul 2018 14:35:50 +0300 Subject: [PATCH] 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 { } ``` --- .../codeInsight/completion/CompletionContributor.java | 9 +++++++++ .../intellij/codeInsight/editorActions/TypedHandler.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java index 1b3ac51b9cca..b15b9575ea1b 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java @@ -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)}) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java index 90a16444bc3a..fe2823b72892 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java @@ -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; }