IDEA-60891 flex: (automatic) code completion should not suggest language keywords inside comments

WI-3734 PhpStorm tries show automplete window inside string in javascript file -> exception and editor became frozen for ~10 seconds
This commit is contained in:
Maxim.Mossienko
2010-11-11 20:06:11 +03:00
parent 581ac31dee
commit 576ac2eac6
2 changed files with 23 additions and 1 deletions
@@ -15,6 +15,8 @@
*/
package com.intellij.codeInsight.completion;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -26,5 +28,8 @@ public abstract class CompletionConfidence {
@Nullable
public abstract Boolean shouldFocusLookup(@NotNull CompletionParameters parameters);
@Nullable
public Boolean shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
return null;
}
}
@@ -193,6 +193,23 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
};
if (autopopup) {
CommandProcessor.getInstance().runUndoTransparentAction(initCmd);
int offset = editor.getCaretModel().getOffset();
PsiElement elementAt = InjectedLanguageUtil.findInjectedElementNoCommit(psiFile, offset);
if (elementAt == null) {
elementAt = psiFile.findElementAt(offset);
if (elementAt == null && offset > 0) {
elementAt = psiFile.findElementAt(offset - 1);
}
}
Language language = elementAt != null ? PsiUtilBase.findLanguageFromElement(elementAt):psiFile.getLanguage();
for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
final Boolean result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset); // TODO: Peter Lazy API
if (result == Boolean.TRUE) return;
}
} else {
CommandProcessor.getInstance().executeCommand(project, initCmd, null, null);
}