Completion preselection depends on context
authorAndrey Vokin <andrey.vokin@jetbrains.com>
Wed, 25 Feb 2015 13:24:29 +0000 (16:24 +0300)
committerAndrey Vokin <andrey.vokin@jetbrains.com>
Wed, 25 Feb 2015 13:51:28 +0000 (16:51 +0300)
platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPreselectionBehaviourProvider.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
platform/platform-resources/src/META-INF/LangExtensionPoints.xml
platform/util/resources/misc/registry.properties

diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPreselectionBehaviourProvider.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPreselectionBehaviourProvider.java
new file mode 100644 (file)
index 0000000..f6cd174
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInsight.completion;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class CompletionPreselectionBehaviourProvider {
+  public static ExtensionPointName<CompletionPreselectionBehaviourProvider> EP_NAME = ExtensionPointName.create("com.intellij.completion.completionBehaviourProvider");
+
+  public boolean shouldPreselectFirstSuggestion(@NotNull CompletionParameters parameters) {
+    return true;
+  }
+}
index 5daf8d4801977f9951bb7d1ccdb58145c681473b..8f96ed1bf0e8a2fd9903e6a6967205081cf9b22e 100644 (file)
@@ -41,6 +41,7 @@ import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Caret;
 import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.progress.ProcessCanceledException;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.util.ProgressIndicatorBase;
@@ -727,6 +728,14 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
       return false;
     }
 
+    if (Registry.is("ide.completion.lookup.element.preselect.depends.on.context")) {
+      for (CompletionPreselectionBehaviourProvider provider : Extensions.getExtensions(CompletionPreselectionBehaviourProvider.EP_NAME)) {
+        if (!provider.shouldPreselectFirstSuggestion(parameters)) {
+          return false;
+        }
+      }
+    }
+
     if (!ApplicationManager.getApplication().isUnitTestMode()) {
       return true;
     }
index 17f7ca8c11d01bfb9082d16b0f272c7ac8509dbb..421905911dbd57802853e53d39f379117158427b 100644 (file)
       <with attribute="implementationClass" implements="com.intellij.codeInsight.completion.CompletionConfidence"/>
     </extensionPoint>
 
+    <extensionPoint name="completion.completionBehaviourProvider"
+                    interface="com.intellij.codeInsight.completion.CompletionPreselectionBehaviourProvider"/>
+
     <extensionPoint name="completion.skip" interface="com.intellij.codeInsight.completion.CompletionPreselectSkipper"/>
     <extensionPoint name="lookup.charFilter" interface="com.intellij.codeInsight.lookup.CharFilter"/>
     <extensionPoint name="lookup.actionProvider" interface="com.intellij.codeInsight.lookup.LookupActionProvider"/>
index 114892b0266ecbed936185da101d79c27bead421..d923bebb4649070723385ce313609d1ab41b80d9 100644 (file)
@@ -275,6 +275,10 @@ ide.completion.delay.autopopup.until.completed.description=Controls if completio
 
 ide.completion.middle.matching=true
 ide.completion.middle.matching.description=Suggest items in completion that contain the entered string somewhere in the middle.
+
+ide.completion.lookup.element.preselect.depends.on.context=true
+ide.completion.lookup.element.preselect.depends.on.context.description=Preselection of the first element in completion list depends on context
+
 ide.goto.middle.matching=true
 ide.goto.middle.matching.description=Suggest items in goto actions that contain the entered string somewhere in the middle.
 ide.goto.rebuild.delay=0