Complete words in XML even if there are classes in the completion list (IDEA-50044)
authorpeter <peter.gromov@jetbrains.com>
Mon, 8 Mar 2010 21:53:22 +0000 (21:53 +0000)
committerpeter <peter.gromov@jetbrains.com>
Mon, 8 Mar 2010 21:53:22 +0000 (21:53 +0000)
java/java-impl/src/com/intellij/codeInsight/completion/BasicToClassNameDelegator.java
java/java-tests/testData/codeInsight/completion/word/1_after.properties
java/java-tests/testData/codeInsight/completion/word/1_after.txt
java/java-tests/testData/codeInsight/completion/word/1_after.xml
java/java-tests/testData/codeInsight/completion/word/2_after.xml
java/java-tests/testData/codeInsight/completion/word/4_after.java
java/java-tests/testData/codeInsight/completion/word/DollarsInPrefix_after.txt
java/java-tests/testData/codeInsight/completion/word/TextInComment_after.java
platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java
xml/impl/src/com/intellij/codeInsight/completion/XmlCompletionContributor.java

index 25edbf1ffe77c1e0b74c42298c35ce67197c8fbe..193273af4790d7ccda2e657f659cce59196e6f2a 100644 (file)
@@ -75,6 +75,7 @@ public class BasicToClassNameDelegator extends CompletionContributor{
         if (lookupElement instanceof JavaPsiClassReferenceElement) {
           ((JavaPsiClassReferenceElement)lookupElement).setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
         }
+        lookupElement.putUserData(XmlCompletionContributor.WORD_COMPLETION_COMPATIBLE, Boolean.TRUE); //todo think of a less dirty interaction
         result.addElement(lookupElement);
       }
     });
index d541cbaae542428e833f9e6b28c8becdaa625169..d065e4a88c4b46b243afd08ffbbefc72e984eacb 100644 (file)
@@ -1 +1 @@
-Settings Settings other
\ No newline at end of file
+Settings Settings<caret> other
\ No newline at end of file
index d541cbaae542428e833f9e6b28c8becdaa625169..d065e4a88c4b46b243afd08ffbbefc72e984eacb 100644 (file)
@@ -1 +1 @@
-Settings Settings other
\ No newline at end of file
+Settings Settings<caret> other
\ No newline at end of file
index 0e55fb64166c256eb378cc41423f9e81536595e2..1acc895d753fb16034ef064835d8ab95e32de91e 100644 (file)
@@ -1 +1 @@
-<a>Settings Settings <caret>other</a>
\ No newline at end of file
+<a>Settings Settings<caret> other</a>
\ No newline at end of file
index 2b4fb1785afa0f7cce7e0de74d78b33f7e495ca9..d993a9c51b62ef3cf8b698b2deb456269c31efd5 100644 (file)
@@ -1,4 +1,4 @@
 <root>
 <a value="Settings"/>
-<a value="Settings <caret>"></a>
+<a value="Settings<caret>"></a>
 </root>
\ No newline at end of file
index aad7a3fa2af9c52cbe318332ea2bf35a8023a91f..e5fb98f900a7f97ce3720cc5625474465b38f98b 100644 (file)
@@ -1,4 +1,4 @@
 public class MyClass {
  String b = "My";
-  // public <caret>
+  // public<caret>
 }
\ No newline at end of file
index eb7accf1a5524122fff381baa8b98d23fa0e987b..748e2423bcc5107de40cc89c6128917c521ff9d0 100644 (file)
@@ -1,2 +1,2 @@
 $test
-$test <caret>
\ No newline at end of file
+$test<caret>
\ No newline at end of file
index 5e00229798467b9c03cb84116d548047b1c2ab0c..aa7b8d70a951bdca320539323bdddd32b7301f76 100644 (file)
@@ -1,4 +1,4 @@
 public class MyClass {
 
-  /** comment  MyClass <caret>*/
+  /** comment  MyClass<caret> */
 }
\ No newline at end of file
index 6766998546115183fb34c82aeeeaeeb6dc56a931..906898a8a6afdc310dbee4f586767367e0429ec9 100644 (file)
 package com.intellij.codeInsight.completion;
 
 import com.intellij.codeInsight.lookup.LookupElement;
-import com.intellij.codeInsight.lookup.TailTypeDecorator;
 import com.intellij.codeInsight.lookup.LookupElementBuilder;
-import com.intellij.codeInsight.TailType;
 import com.intellij.lang.ASTNode;
 import com.intellij.lang.LanguageWordCompletion;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.DumbService;
 import com.intellij.openapi.util.Computable;
-import static com.intellij.patterns.StandardPatterns.character;
 import com.intellij.psi.PlainTextTokenTypes;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
@@ -33,9 +30,12 @@ import com.intellij.psi.PsiReference;
 import com.intellij.psi.filters.getters.AllWordsGetter;
 import com.intellij.psi.tree.IElementType;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import static com.intellij.patterns.StandardPatterns.character;
+
 /**
  * @author peter
  */
@@ -44,11 +44,11 @@ public class WordCompletionContributor extends CompletionContributor implements
   @Override
   public void fillCompletionVariants(final CompletionParameters parameters, final CompletionResultSet result) {
     if (parameters.getCompletionType() == CompletionType.BASIC && shouldPerformWordCompletion(parameters)) {
-      addWordCompletionWariants(result, parameters);
+      addWordCompletionVariants(result, parameters, Collections.<String>emptySet());
     }
   }
 
-  public static void addWordCompletionWariants(CompletionResultSet result, CompletionParameters parameters) {
+  public static void addWordCompletionVariants(CompletionResultSet result, CompletionParameters parameters, Set<String> excludes) {
     int startOffset = parameters.getOffset();
     PsiElement insertedElement = parameters.getPosition();
     final CompletionResultSet javaResultSet = result.withPrefixMatcher(CompletionUtil.findJavaIdentifierPrefix(insertedElement, startOffset));
@@ -57,9 +57,11 @@ public class WordCompletionContributor extends CompletionContributor implements
                                                                                                             character().javaIdentifierPart().andNot(character().equalTo('$')),
                                                                                                             character().javaIdentifierStart()));
     for (final String word : AllWordsGetter.getAllWords(insertedElement, startOffset)) {
-      final LookupElement item = TailTypeDecorator.withTail(LookupElementBuilder.create(word), TailType.SPACE);
-      javaResultSet.addElement(item);
-      plainResultSet.addElement(item);
+      if (!excludes.contains(word)) {
+        final LookupElement item = LookupElementBuilder.create(word);
+        javaResultSet.addElement(item);
+        plainResultSet.addElement(item);
+      }
     }
   }
 
index 53fe5b0c3685163013b7b733c36379f7cc6d279c..715b6860860083596776c2d0c71a7a075cd5a3ee 100644 (file)
@@ -26,6 +26,7 @@ import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.util.Computable;
+import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.util.text.StringUtil;
@@ -37,12 +38,13 @@ import com.intellij.psi.xml.XmlAttributeValue;
 import com.intellij.psi.xml.XmlFile;
 import com.intellij.psi.xml.XmlTag;
 import com.intellij.psi.xml.XmlTokenType;
-import com.intellij.util.ProcessingContext;
 import com.intellij.util.Consumer;
+import com.intellij.util.ProcessingContext;
 import com.intellij.xml.XmlBundle;
 import com.intellij.xml.XmlElementDescriptor;
 import com.intellij.xml.XmlExtension;
 import com.intellij.xml.impl.schema.AnyXmlElementDescriptor;
+import gnu.trove.THashSet;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 
@@ -54,6 +56,7 @@ import java.util.Set;
  * @author Dmitry Avdeev
  */
 public class XmlCompletionContributor extends CompletionContributor {
+  public static final Key<Boolean> WORD_COMPLETION_COMPATIBLE = Key.create("WORD_COMPLETION_COMPATIBLE");
 
   @NonNls public static final String TAG_NAME_COMPLETION_FEATURE = "tag.name.completion";
   private static final InsertHandlerDecorator<LookupElement> QUOTE_EATER = new InsertHandlerDecorator<LookupElement>() {
@@ -92,10 +95,14 @@ public class XmlCompletionContributor extends CompletionContributor {
                  return;
                }
 
+               final Set<String> usedWords = new THashSet<String>();
                final Ref<Boolean> addWordVariants = Ref.create(true);
                result.runRemainingContributors(parameters, new Consumer<LookupElement>() {
                  public void consume(LookupElement element) {
-                   addWordVariants.set(false);
+                   if (element.getUserData(WORD_COMPLETION_COMPATIBLE) == null) {
+                     addWordVariants.set(false);
+                   }
+                   usedWords.add(element.getLookupString());
                    result.addElement(LookupElementDecorator.withInsertHandler(element, QUOTE_EATER));
                  }
                });
@@ -108,7 +115,7 @@ public class XmlCompletionContributor extends CompletionContributor {
                }
 
                if (addWordVariants.get().booleanValue()) {
-                 WordCompletionContributor.addWordCompletionWariants(result, parameters);
+                 WordCompletionContributor.addWordCompletionVariants(result, parameters, usedWords);
                }
              }
            });