mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't reparse whole file when document/psi texts are equal
This commit is contained in:
@@ -271,6 +271,8 @@ public class PomModelImpl extends UserDataHolderBase implements PomModel {
|
||||
|
||||
PsiToDocumentSynchronizer synchronizer =((PsiDocumentManagerBase)PsiDocumentManager.getInstance(myProject)).getSynchronizer();
|
||||
TextRange changedPsiRange = DocumentCommitProcessor.getChangedPsiRange(file, oldText, newText);
|
||||
if (changedPsiRange == null) return;
|
||||
|
||||
final DiffLog log = BlockSupport.getInstance(myProject).reparseRange(file, changedPsiRange, newText, new EmptyProgressIndicator());
|
||||
synchronizer.setIgnorePsiEvents(true);
|
||||
try {
|
||||
|
||||
@@ -105,13 +105,17 @@ public abstract class DocumentCommitProcessor {
|
||||
final long startDocModificationTimeStamp = document.getModificationStamp();
|
||||
final FileElement myTreeElementBeingReparsedSoItWontBeCollected = ((PsiFileImpl)file).calcTreeElement();
|
||||
final CharSequence chars = document.getImmutableCharSequence();
|
||||
final CharSequence oldPsiText = myTreeElementBeingReparsedSoItWontBeCollected.getChars();
|
||||
final TextRange changedPsiRange = getChangedPsiRange(file, oldPsiText, chars);
|
||||
if (changedPsiRange == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Boolean data = document.getUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY);
|
||||
if (data != null) {
|
||||
document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, null);
|
||||
file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, data);
|
||||
}
|
||||
final CharSequence oldPsiText = myTreeElementBeingReparsedSoItWontBeCollected.getChars();
|
||||
final TextRange changedPsiRange = getChangedPsiRange(file, oldPsiText, chars);
|
||||
|
||||
BlockSupport blockSupport = BlockSupport.getInstance(file.getProject());
|
||||
final DiffLog diffLog = blockSupport.reparseRange(file, changedPsiRange, chars, task.indicator);
|
||||
@@ -135,6 +139,7 @@ public abstract class DocumentCommitProcessor {
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextRange getChangedPsiRange(@NotNull PsiFile file, @NotNull CharSequence oldPsiText, @NotNull CharSequence newDocumentText) {
|
||||
if (!file.getViewProvider().supportsIncrementalReparse(file.getLanguage())) {
|
||||
return new TextRange(0, newDocumentText.length());
|
||||
@@ -142,7 +147,7 @@ public abstract class DocumentCommitProcessor {
|
||||
|
||||
int commonPrefixLength = StringUtil.commonPrefixLength(oldPsiText, newDocumentText);
|
||||
if (commonPrefixLength == newDocumentText.length() && newDocumentText.length() == oldPsiText.length()) {
|
||||
return new TextRange(0, newDocumentText.length());
|
||||
return null;
|
||||
}
|
||||
|
||||
int commonSuffixLength = StringUtil.commonSuffixLength(oldPsiText, newDocumentText);
|
||||
|
||||
Reference in New Issue
Block a user