Search in sources :

Example 6 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class ExtendWordSelectionHandlerBase method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    final TextRange originalRange = e.getTextRange();
    if (originalRange.getEndOffset() > editorText.length()) {
        throw new LogEventException("Invalid element range in " + getClass(), "element=" + e + "; range=" + originalRange + "; text length=" + editorText.length() + "; editor=" + editor + "; committed=" + PsiDocumentManager.getInstance(e.getProject()).isCommitted(editor.getDocument()), new Attachment("editor_text.txt", editorText.toString()), new Attachment("psi_text.txt", e.getText()));
    }
    List<TextRange> ranges = expandToWholeLine(editorText, originalRange, true);
    if (ranges.size() == 1 && ranges.contains(originalRange)) {
        return expandToWholeLine(editorText, originalRange, false);
    }
    return ranges;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Attachment(com.intellij.openapi.diagnostic.Attachment) LogEventException(com.intellij.diagnostic.LogEventException)

Example 7 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class UpToDateStubIndexMismatch method stubTreeAndIndexDoNotMatch.

@NotNull
public RuntimeException stubTreeAndIndexDoNotMatch(@NotNull String _message, @NotNull ObjectStubTree stubTree, @NotNull PsiFileWithStubSupport psiFile) {
    VirtualFile file = psiFile.getViewProvider().getVirtualFile();
    StubTree stubTreeFromIndex = (StubTree) readFromVFile(psiFile.getProject(), file);
    Document document = FileDocumentManager.getInstance().getDocument(file);
    IndexingStampInfo indexingStampInfo = getIndexingStampInfo(file);
    boolean upToDate = indexingStampInfo != null && indexingStampInfo.isUpToDate(document, file, psiFile);
    String msg = _message + "\nPlease report the problem to JetBrains with the files attached\n";
    if (upToDate) {
        msg += "INDEXED VERSION IS THE CURRENT ONE";
    }
    msg += " file=" + psiFile;
    msg += ", file.class=" + psiFile.getClass();
    msg += ", file.lang=" + psiFile.getLanguage();
    msg += ", modStamp=" + psiFile.getModificationStamp();
    if (!(psiFile instanceof PsiCompiledElement)) {
        String text = psiFile.getText();
        PsiFile fromText = PsiFileFactory.getInstance(psiFile.getProject()).createFileFromText(psiFile.getName(), psiFile.getFileType(), text);
        if (fromText.getLanguage().equals(psiFile.getLanguage())) {
            boolean consistent = DebugUtil.psiToString(psiFile, true).equals(DebugUtil.psiToString(fromText, true));
            if (consistent) {
                msg += "\n tree consistent";
            } else {
                msg += "\n AST INCONSISTENT, perhaps after incremental reparse; " + fromText;
            }
        }
    }
    msg += "\n stub debugInfo=" + stubTree.getDebugInfo();
    msg += "\nlatestIndexedStub=" + stubTreeFromIndex;
    if (stubTreeFromIndex != null) {
        msg += "\n   same size=" + (stubTree.getPlainList().size() == stubTreeFromIndex.getPlainList().size());
        msg += "\n   debugInfo=" + stubTreeFromIndex.getDebugInfo();
    }
    FileViewProvider viewProvider = psiFile.getViewProvider();
    msg += "\n viewProvider=" + viewProvider;
    msg += "\n viewProvider stamp: " + viewProvider.getModificationStamp();
    msg += "; file stamp: " + file.getModificationStamp();
    msg += "; file modCount: " + file.getModificationCount();
    msg += "; file length: " + file.getLength();
    if (document != null) {
        msg += "\n doc saved: " + !FileDocumentManager.getInstance().isDocumentUnsaved(document);
        msg += "; doc stamp: " + document.getModificationStamp();
        msg += "; doc size: " + document.getTextLength();
        msg += "; committed: " + PsiDocumentManager.getInstance(psiFile.getProject()).isCommitted(document);
    }
    msg += "\nin many projects: " + hasPsiInManyProjects(file);
    msg += "\nindexing info: " + indexingStampInfo;
    Attachment[] attachments = createAttachments(stubTree, psiFile, file, stubTreeFromIndex);
    // separate methods and separate exception classes for EA to treat these situations differently
    return upToDate ? handleUpToDateMismatch(msg, attachments) : new RuntimeExceptionWithAttachments(msg, attachments);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RuntimeExceptionWithAttachments(com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class SingleRootFileViewProvider method checkLengthConsistency.

private void checkLengthConsistency() {
    Document document = getCachedDocument();
    if (document instanceof DocumentWindow) {
        return;
    }
    if (document != null && ((PsiDocumentManagerBase) PsiDocumentManager.getInstance(myManager.getProject())).getSynchronizer().isInSynchronization(document)) {
        return;
    }
    List<FileElement> knownTreeRoots = getKnownTreeRoots();
    if (knownTreeRoots.isEmpty())
        return;
    int fileLength = myContent.getTextLength();
    for (FileElement fileElement : knownTreeRoots) {
        int nodeLength = fileElement.getTextLength();
        if (nodeLength != fileLength) {
            PsiUtilCore.ensureValid(fileElement.getPsi());
            List<Attachment> attachments = ContainerUtil.newArrayList(new Attachment(myVirtualFile.getNameWithoutExtension() + ".tree.txt", fileElement.getText()), new Attachment(myVirtualFile.getNameWithoutExtension() + ".file.txt", myContent.toString()));
            if (document != null) {
                attachments.add(new Attachment(myVirtualFile.getNameWithoutExtension() + ".document.txt", document.getText()));
            }
            // exceptions here should be assigned to peter
            LOG.error("Inconsistent " + fileElement.getElementType() + " tree in " + this + "; nodeLength=" + nodeLength + "; fileLength=" + fileLength, attachments.toArray(Attachment.EMPTY_ARRAY));
        }
    }
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) FileElement(com.intellij.psi.impl.source.tree.FileElement) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document)

Example 9 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class TextLayoutCache method documentChanged.

@Override
public void documentChanged(DocumentEvent event) {
    int startLine = myDocument.getLineNumber(event.getOffset());
    int newEndLine = getAdjustedLineNumber(event.getOffset() + event.getNewLength());
    invalidateLines(startLine, myDocumentChangeOldEndLine, newEndLine, true, LineLayout.isBidiLayoutRequired(event.getNewFragment()));
    if (myLines.size() != myDocument.getLineCount()) {
        LOG.error("Error updating text layout cache after " + event, new Attachment("editorState.txt", myView.getEditor().dumpState()));
        resetToDocumentSize(true);
    }
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment)

Example 10 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class TextLayoutCache method resetToDocumentSize.

void resetToDocumentSize(boolean documentChangedWithoutNotification) {
    checkDisposed();
    invalidateLines(0, myLines.size() - 1, myDocument.getLineCount() - 1, documentChangedWithoutNotification, documentChangedWithoutNotification);
    if (myLines.size() != myDocument.getLineCount()) {
        LOG.error("Error resetting text layout cache", new Attachment("editorState.txt", myView.getEditor().dumpState()));
    }
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment)

Aggregations

Attachment (com.intellij.openapi.diagnostic.Attachment)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)10 Project (com.intellij.openapi.project.Project)6 ArrayList (java.util.ArrayList)6 Document (com.intellij.openapi.editor.Document)5 TextRange (com.intellij.openapi.util.TextRange)4 LogEventException (com.intellij.diagnostic.LogEventException)3 Logger (com.intellij.openapi.diagnostic.Logger)3 PsiElement (com.intellij.psi.PsiElement)3 PsiFile (com.intellij.psi.PsiFile)3 LogMessageEx (com.intellij.diagnostic.LogMessageEx)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2 Pair (com.intellij.openapi.util.Pair)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 List (java.util.List)2 NonNls (org.jetbrains.annotations.NonNls)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1