Search in sources :

Example 26 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class CompletionAssertions method assertCommitSuccessful.

static void assertCommitSuccessful(Editor editor, PsiFile psiFile) {
    Document document = editor.getDocument();
    int docLength = document.getTextLength();
    int psiLength = psiFile.getTextLength();
    PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
    boolean committed = !manager.isUncommited(document);
    if (docLength == psiLength && committed) {
        return;
    }
    FileViewProvider viewProvider = psiFile.getViewProvider();
    String message = "unsuccessful commit:";
    message += "\nmatching=" + (psiFile == manager.getPsiFile(document));
    message += "\ninjectedEditor=" + (editor instanceof EditorWindow);
    message += "\ninjectedFile=" + InjectedLanguageManager.getInstance(psiFile.getProject()).isInjectedFragment(psiFile);
    message += "\ncommitted=" + committed;
    message += "\nfile=" + psiFile.getName();
    message += "\nfile class=" + psiFile.getClass();
    message += "\nfile.valid=" + psiFile.isValid();
    message += "\nfile.physical=" + psiFile.isPhysical();
    message += "\nfile.eventSystemEnabled=" + viewProvider.isEventSystemEnabled();
    message += "\nlanguage=" + psiFile.getLanguage();
    message += "\ndoc.length=" + docLength;
    message += "\npsiFile.length=" + psiLength;
    String fileText = psiFile.getText();
    if (fileText != null) {
        message += "\npsiFile.text.length=" + fileText.length();
    }
    FileASTNode node = psiFile.getNode();
    if (node != null) {
        message += "\nnode.length=" + node.getTextLength();
        String nodeText = node.getText();
        if (nodeText != null) {
            message += "\nnode.text.length=" + nodeText.length();
        }
    }
    VirtualFile virtualFile = viewProvider.getVirtualFile();
    message += "\nvirtualFile=" + virtualFile;
    message += "\nvirtualFile.class=" + virtualFile.getClass();
    message += "\n" + DebugUtil.currentStackTrace();
    throw new LogEventException("Commit unsuccessful", message, new Attachment(virtualFile.getPath() + "_file.txt", fileText), createAstAttachment(psiFile, psiFile), new Attachment("docText.txt", document.getText()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileASTNode(com.intellij.lang.FileASTNode) FileViewProvider(com.intellij.psi.FileViewProvider) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document) LogEventException(com.intellij.diagnostic.LogEventException) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 27 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class LookupUi method refreshUi.

void refreshUi(boolean selectionVisible, boolean itemsChanged, boolean reused, boolean onExplicitAction) {
    Editor editor = myLookup.getTopLevelEditor();
    if (editor.getComponent().getRootPane() == null || editor instanceof EditorWindow && !((EditorWindow) editor).isValid()) {
        return;
    }
    updateScrollbarVisibility();
    if (myLookup.myResizePending || itemsChanged) {
        myMaximumHeight = Integer.MAX_VALUE;
    }
    Rectangle rectangle = calculatePosition();
    myMaximumHeight = rectangle.height;
    if (myLookup.myResizePending || itemsChanged) {
        myLookup.myResizePending = false;
        myLookup.pack();
    }
    HintManagerImpl.updateLocation(myLookup, editor, rectangle.getLocation());
    if (reused || selectionVisible || onExplicitAction) {
        myLookup.ensureSelectionVisible(false);
    }
}
Also used : Editor(com.intellij.openapi.editor.Editor) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 28 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class LookupImpl method getPsiElement.

@Override
public PsiElement getPsiElement() {
    PsiFile file = getPsiFile();
    if (file == null)
        return null;
    int offset = getLookupStart();
    Editor editor = getEditor();
    if (editor instanceof EditorWindow) {
        offset = editor.logicalPositionToOffset(((EditorWindow) editor).hostToInjected(myEditor.offsetToLogicalPosition(offset)));
    }
    if (offset > 0)
        return file.findElementAt(offset - 1);
    return file.findElementAt(0);
}
Also used : PsiFile(com.intellij.psi.PsiFile) RelativePoint(com.intellij.ui.awt.RelativePoint) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 29 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class ShowIntentionActionsHandler method availableFor.

public static boolean availableFor(@NotNull PsiFile psiFile, @NotNull Editor editor, @NotNull IntentionAction action) {
    if (!psiFile.isValid())
        return false;
    int offset = editor.getCaretModel().getOffset();
    PsiElement psiElement = psiFile.findElementAt(offset);
    boolean inProject = psiFile.getManager().isInProject(psiFile);
    try {
        Project project = psiFile.getProject();
        if (action instanceof SuppressIntentionActionFromFix) {
            final ThreeState shouldBeAppliedToInjectionHost = ((SuppressIntentionActionFromFix) action).isShouldBeAppliedToInjectionHost();
            if (editor instanceof EditorWindow && shouldBeAppliedToInjectionHost == ThreeState.YES) {
                return false;
            }
            if (!(editor instanceof EditorWindow) && shouldBeAppliedToInjectionHost == ThreeState.NO) {
                return false;
            }
        }
        if (action instanceof PsiElementBaseIntentionAction) {
            if (!inProject || psiElement == null || !((PsiElementBaseIntentionAction) action).isAvailable(project, editor, psiElement))
                return false;
        } else if (!action.isAvailable(project, editor, psiFile)) {
            return false;
        }
    } catch (IndexNotReadyException e) {
        return false;
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) SuppressIntentionActionFromFix(com.intellij.codeInspection.SuppressIntentionActionFromFix) ThreeState(com.intellij.util.ThreeState) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiElementBaseIntentionAction(com.intellij.codeInsight.intention.PsiElementBaseIntentionAction) PsiElement(com.intellij.psi.PsiElement) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 30 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class GotoDeclarationAction method findTargetElementsNoVS.

@Nullable
public static PsiElement[] findTargetElementsNoVS(Project project, Editor editor, int offset, boolean lookupAccepted) {
    Document document = editor.getDocument();
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (file == null)
        return null;
    PsiElement elementAt = file.findElementAt(TargetElementUtil.adjustOffset(file, document, offset));
    for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
        try {
            PsiElement[] result = handler.getGotoDeclarationTargets(elementAt, offset, editor);
            if (result != null && result.length > 0) {
                for (PsiElement element : result) {
                    if (element == null) {
                        LOG.error("Null target element is returned by " + handler.getClass().getName());
                        return null;
                    }
                }
                return result;
            }
        } catch (AbstractMethodError e) {
            LOG.error(new ExtensionException(handler.getClass()));
        }
    }
    int flags = TargetElementUtil.getInstance().getAllAccepted() & ~TargetElementUtil.ELEMENT_NAME_ACCEPTED;
    if (!lookupAccepted) {
        flags &= ~TargetElementUtil.LOOKUP_ITEM_ACCEPTED;
    }
    PsiElement element = TargetElementUtil.getInstance().findTargetElement(editor, flags, offset);
    if (element != null) {
        return new PsiElement[] { element };
    }
    // if no references found in injected fragment, try outer document
    if (editor instanceof EditorWindow) {
        EditorWindow window = (EditorWindow) editor;
        return findTargetElementsNoVS(project, window.getDelegate(), window.getDocument().injectedToHost(offset), lookupAccepted);
    }
    return null;
}
Also used : PsiFile(com.intellij.psi.PsiFile) ExtensionException(com.intellij.openapi.extensions.ExtensionException) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) RelativePoint(com.intellij.ui.awt.RelativePoint) EditorWindow(com.intellij.injected.editor.EditorWindow) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

EditorWindow (com.intellij.injected.editor.EditorWindow)44 Editor (com.intellij.openapi.editor.Editor)15 TextRange (com.intellij.openapi.util.TextRange)10 Project (com.intellij.openapi.project.Project)9 Document (com.intellij.openapi.editor.Document)8 PsiFile (com.intellij.psi.PsiFile)8 NotNull (org.jetbrains.annotations.NotNull)8 PsiElement (com.intellij.psi.PsiElement)7 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)5 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)4 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)3 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)3 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)3 ArrayList (java.util.ArrayList)3 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)2 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 InjectedCaret (com.intellij.injected.editor.InjectedCaret)2 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2