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
This commit is contained in:
Alexey Gopachenko
2017-09-25 23:42:26 +02:00
parent e3826e6872
commit 1d57bf409b
@@ -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);
}