Search in sources :

Example 6 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog in project intellij-community by JetBrains.

the class PomModelImpl method reparseFile.

@Nullable
private Runnable reparseFile(@NotNull final PsiFile file, @NotNull FileElement treeElement, @NotNull CharSequence newText) {
    TextRange changedPsiRange = DocumentCommitThread.getChangedPsiRange(file, treeElement, newText);
    if (changedPsiRange == null)
        return null;
    Runnable reparseLeaf = tryReparseOneLeaf(treeElement, newText, changedPsiRange);
    if (reparseLeaf != null)
        return reparseLeaf;
    final DiffLog log = BlockSupport.getInstance(myProject).reparseRange(file, treeElement, changedPsiRange, newText, new EmptyProgressIndicator(), treeElement.getText());
    return () -> runTransaction(new PomTransactionBase(file, getModelAspect(TreeAspect.class)) {

        @Nullable
        @Override
        public PomModelEvent runInner() throws IncorrectOperationException {
            return new TreeAspectEvent(PomModelImpl.this, log.performActualPsiChange(file));
        }
    });
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ThrowableRunnable(com.intellij.util.ThrowableRunnable) TextRange(com.intellij.openapi.util.TextRange) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PomModelEvent(com.intellij.pom.event.PomModelEvent) TreeAspectEvent(com.intellij.pom.tree.TreeAspectEvent) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog in project intellij-community by JetBrains.

the class DocumentCommitThread method assertAfterCommit.

private void assertAfterCommit(@NotNull Document document, @NotNull final PsiFile file, @NotNull FileElement oldFileNode) {
    if (oldFileNode.getTextLength() != document.getTextLength()) {
        final String documentText = document.getText();
        String fileText = file.getText();
        boolean sameText = Comparing.equal(fileText, documentText);
        LOG.error("commitDocument() left PSI inconsistent: " + DebugUtil.diagnosePsiDocumentInconsistency(file, document) + "; node.length=" + oldFileNode.getTextLength() + "; doc.text" + (sameText ? "==" : "!=") + "file.text" + "; file name:" + file.getName() + "; type:" + file.getFileType() + "; lang:" + file.getLanguage());
        file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE);
        try {
            BlockSupport blockSupport = BlockSupport.getInstance(file.getProject());
            final DiffLog diffLog = blockSupport.reparseRange(file, file.getNode(), new TextRange(0, documentText.length()), documentText, createProgressIndicator(), oldFileNode.getText());
            doActualPsiChange(file, diffLog);
            if (oldFileNode.getTextLength() != document.getTextLength()) {
                LOG.error("PSI is broken beyond repair in: " + file);
            }
        } finally {
            file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, null);
        }
    }
}
Also used : BlockSupport(com.intellij.psi.text.BlockSupport) DiffLog(com.intellij.psi.impl.source.text.DiffLog)

Example 8 with DiffLog

use of com.intellij.psi.impl.source.text.DiffLog in project intellij-community by JetBrains.

the class ParsingTestCase method ensureCorrectReparse.

public static void ensureCorrectReparse(@NotNull final PsiFile file) {
    final String psiToStringDefault = DebugUtil.psiToString(file, false, false);
    final String fileText = file.getText();
    final DiffLog diffLog = new BlockSupportImpl(file.getProject()).reparseRange(file, file.getNode(), TextRange.allOf(fileText), fileText, new EmptyProgressIndicator(), fileText);
    diffLog.performActualPsiChange(file);
    TestCase.assertEquals(psiToStringDefault, DebugUtil.psiToString(file, false, false));
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) BlockSupportImpl(com.intellij.psi.impl.source.text.BlockSupportImpl) DiffLog(com.intellij.psi.impl.source.text.DiffLog)

Aggregations

DiffLog (com.intellij.psi.impl.source.text.DiffLog)8 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)4 NotNull (org.jetbrains.annotations.NotNull)3 ASTNode (com.intellij.lang.ASTNode)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 PomModelEvent (com.intellij.pom.event.PomModelEvent)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 TreeAspectEvent (com.intellij.pom.tree.TreeAspectEvent)2 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)2 BlockSupportImpl (com.intellij.psi.impl.source.text.BlockSupportImpl)2 BlockSupport (com.intellij.psi.text.BlockSupport)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)1 FileASTNode (com.intellij.lang.FileASTNode)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.application (com.intellij.openapi.application)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1