summaryrefslogtreecommitdiff
path: root/platform/lang-impl/src/com/intellij/codeInsight/completion
diff options
context:
space:
mode:
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInsight/completion')
-rw-r--r--platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java7
-rw-r--r--platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java5
-rw-r--r--platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java68
3 files changed, 45 insertions, 35 deletions
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java
index e039cec3a424..e0a3be5f423d 100644
--- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java
@@ -772,11 +772,8 @@ public class CodeCompletionHandlerBase {
if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
final Language language = PsiUtilBase.getLanguageInEditor(editor, project);
if (language != null) {
- final List<SmartEnterProcessor> processors = SmartEnterProcessors.INSTANCE.forKey(language);
- if (processors.size() > 0) {
- for (SmartEnterProcessor processor : processors) {
- processor.process(project, editor, indicator.getParameters().getOriginalFile());
- }
+ for (SmartEnterProcessor processor : SmartEnterProcessors.INSTANCE.forKey(language)) {
+ if (processor.processAfterCompletion(editor, indicator.getParameters().getOriginalFile())) break;
}
}
}
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
index 0143e55a4e98..e25f050c8d7b 100644
--- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java
@@ -17,6 +17,7 @@
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.CodeInsightSettings;
+import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
import com.intellij.codeInsight.completion.impl.CompletionSorterImpl;
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler;
@@ -216,7 +217,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
if (!initContext.getOffsetMap().wasModified(CompletionInitializationContext.IDENTIFIER_END_OFFSET)) {
try {
final int selectionEndOffset = initContext.getSelectionEndOffset();
- final PsiReference reference = initContext.getFile().findReferenceAt(selectionEndOffset);
+ final PsiReference reference = TargetElementUtilBase.findReference(myEditor, selectionEndOffset);
if (reference != null) {
initContext.setReplacementOffset(findReplacementOffset(selectionEndOffset, reference));
}
@@ -252,7 +253,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
}
- return reference.getElement().getTextRange().getStartOffset() + reference.getRangeInElement().getEndOffset();
+ return selectionEndOffset;
}
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java
index f23a7a6f6cca..4a34e9460718 100644
--- a/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java
+++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/FilePathCompletionContributor.java
@@ -48,6 +48,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.ProjectScope;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ProcessingContext;
+import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -71,9 +72,7 @@ public class FilePathCompletionContributor extends CompletionContributor {
final PsiReference psiReference = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
if (getReference(psiReference) != null && parameters.getInvocationCount() == 1) {
final String shortcut = getActionShortcut(IdeActions.ACTION_CODE_COMPLETION);
- if (shortcut != null) {
- result.addLookupAdvertisement(CodeInsightBundle.message("class.completion.file.path", shortcut));
- }
+ result.addLookupAdvertisement(CodeInsightBundle.message("class.completion.file.path", shortcut));
}
}
});
@@ -134,24 +133,30 @@ public class FilePathCompletionContributor extends CompletionContributor {
final PsiFile[] files = FilenameIndex.getFilesByName(project, name, scope);
- if (files.length > 0) {
- for (final PsiFile file : files) {
+ if (files.length <= 0) {
+ continue;
+ }
+ for (final PsiFile file : files) {
+ ProgressManager.checkCanceled();
+
+ final VirtualFile virtualFile = file.getVirtualFile();
+ if (virtualFile == null || !virtualFile.isValid() || Comparing.equal(virtualFile, contextFile)) {
+ continue;
+ }
+ List<FileReferenceHelper> helperList = new ArrayList<FileReferenceHelper>();
+ for (FileReferenceHelper contextHelper : helpers) {
ProgressManager.checkCanceled();
- final VirtualFile virtualFile = file.getVirtualFile();
- if (virtualFile != null && virtualFile.isValid() && !Comparing.equal(virtualFile, contextFile)) {
- for (FileReferenceHelper contextHelper : helpers) {
- ProgressManager.checkCanceled();
-
- if (contextHelper.isMine(project, virtualFile)) {
- if (pathPrefixParts == null ||
- fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts)) {
- __result.addElement(new FilePathLookupItem(file, contextHelper));
- }
- }
+ if (contextHelper.isMine(project, virtualFile)) {
+ if (pathPrefixParts == null ||
+ fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts)) {
+ helperList.add(contextHelper);
}
}
}
+ if (!helperList.isEmpty()) {
+ __result.addElement(new FilePathLookupItem(file, helperList));
+ }
}
}
}
@@ -159,9 +164,7 @@ public class FilePathCompletionContributor extends CompletionContributor {
if (set.getSuitableFileTypes().length > 0 && parameters.getInvocationCount() == 1) {
final String shortcut = getActionShortcut(IdeActions.ACTION_CODE_COMPLETION);
- if (shortcut != null) {
- result.addLookupAdvertisement(CodeInsightBundle.message("class.completion.file.path.all.variants", shortcut));
- }
+ result.addLookupAdvertisement(CodeInsightBundle.message("class.completion.file.path.all.variants", shortcut));
}
if (fileReferencePair.getSecond()) result.stopHere();
@@ -203,7 +206,7 @@ public class FilePathCompletionContributor extends CompletionContributor {
final String path = StringUtil.join(contextParts, "/");
int nextIndex = 0;
- for (final String s : pathPrefix) {
+ for (@NonNls final String s : pathPrefix) {
if ((nextIndex = path.indexOf(s.toLowerCase(), nextIndex)) == -1) return false;
}
@@ -252,19 +255,19 @@ public class FilePathCompletionContributor extends CompletionContributor {
return null;
}
- public class FilePathLookupItem extends LookupElement {
+ public static class FilePathLookupItem extends LookupElement {
private final String myName;
private final String myPath;
private final String myInfo;
private final Icon myIcon;
private final PsiFile myFile;
- private final FileReferenceHelper myReferenceHelper;
+ private final List<FileReferenceHelper> myHelpers;
- public FilePathLookupItem(@NotNull final PsiFile file, @NotNull final FileReferenceHelper referenceHelper) {
+ public FilePathLookupItem(@NotNull final PsiFile file, @NotNull final List<FileReferenceHelper> helpers) {
myName = file.getName();
myPath = file.getVirtualFile().getPath();
- myReferenceHelper = referenceHelper;
+ myHelpers = helpers;
myInfo = FileInfoManager.getFileAdditionalInfo(file);
myIcon = file.getFileType().getIcon();
@@ -306,10 +309,7 @@ public class FilePathCompletionContributor extends CompletionContributor {
@Override
public void renderElement(LookupElementPresentation presentation) {
- final VirtualFile virtualFile = myFile.getVirtualFile();
- LOG.assertTrue(virtualFile != null);
- final PsiFileSystemItem root = myReferenceHelper.findRoot(myFile.getProject(), virtualFile);
- final String relativePath = PsiFileSystemItemUtil.getRelativePath(root, myReferenceHelper.getPsiFileSystemItem(myFile.getProject(), virtualFile));
+ final String relativePath = getRelativePath();
final StringBuilder sb = new StringBuilder();
if (myInfo != null) {
@@ -340,6 +340,18 @@ public class FilePathCompletionContributor extends CompletionContributor {
presentation.setIcon(myIcon);
}
+ @Nullable
+ private String getRelativePath() {
+ final VirtualFile virtualFile = myFile.getVirtualFile();
+ LOG.assertTrue(virtualFile != null);
+ for (FileReferenceHelper helper : myHelpers) {
+ final PsiFileSystemItem root = helper.findRoot(myFile.getProject(), virtualFile);
+ String path = PsiFileSystemItemUtil.getRelativePath(root, helper.getPsiFileSystemItem(myFile.getProject(), virtualFile));
+ if (path != null) return path;
+ }
+ return null;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;