From 1d57bf409b6957fc363abd1e5a089c9e7ec8a77a Mon Sep 17 00:00:00 2001 From: Alexey Gopachenko Date: Mon, 25 Sep 2017 23:39:37 +0200 Subject: [PATCH] Revert "Do not scan file for changed range if we already know it exactly" until a multiple pending events are taken care of and test coverage added. This reverts commit 42c6cec --- .../intellij/psi/impl/DocumentCommitThread.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java b/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java index f4163dabd73e..f8363da4c267 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java +++ b/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java @@ -23,7 +23,6 @@ import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; @@ -738,7 +737,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi @NotNull final FileASTNode oldFileNode) { Document document = task.getDocument(); final CharSequence newDocumentText = document.getImmutableCharSequence(); - final TextRange changedPsiRange = getChangedPsiRange(file, task.myLastCommittedText, task.reason, newDocumentText); + final TextRange changedPsiRange = getChangedPsiRange(file, task.myLastCommittedText, newDocumentText); if (changedPsiRange == null) { return null; } @@ -837,25 +836,18 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi @Nullable private static TextRange getChangedPsiRange(@NotNull PsiFile file, @NotNull CharSequence oldDocumentText, - Object reason, @NotNull CharSequence newDocumentText) { + @NotNull CharSequence newDocumentText) { int psiLength = oldDocumentText.length(); if (!file.getViewProvider().supportsIncrementalReparse(file.getLanguage())) { return new TextRange(0, psiLength); } - int commonPrefixLength; - commonPrefixLength = reason instanceof DocumentEvent - ? ((DocumentEvent)reason).getOffset() - : StringUtil.commonPrefixLength(oldDocumentText, newDocumentText); + int commonPrefixLength = StringUtil.commonPrefixLength(oldDocumentText, newDocumentText); if (commonPrefixLength == newDocumentText.length() && newDocumentText.length() == psiLength) { return null; } - int commonSuffixLength; - commonSuffixLength = reason instanceof DocumentEvent - ? newDocumentText.length() - commonPrefixLength - ((DocumentEvent)reason).getNewLength() - : StringUtil.commonSuffixLength(oldDocumentText, newDocumentText); - commonSuffixLength = Math.min(commonSuffixLength, psiLength - commonPrefixLength); + int commonSuffixLength = Math.min(StringUtil.commonSuffixLength(oldDocumentText, newDocumentText), psiLength - commonPrefixLength); return new TextRange(commonPrefixLength, psiLength - commonSuffixLength); }