use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class DocumentMarkupModel method forDocument.
/**
* Returns the markup model for the specified project. A document can have multiple markup
* models for different projects if the file to which it corresponds belongs to multiple projects
* opened in different IDEA frames at the same time.
*
* @param document the document for which the markup model is requested.
* @param project the project for which the markup model is requested, or null if the default markup
* model is requested.
* @return the markup model instance.
* @see com.intellij.openapi.editor.Editor#getMarkupModel()
*/
public static MarkupModel forDocument(@NotNull Document document, @Nullable Project project, boolean create) {
if (document instanceof DocumentWindow) {
final Document delegate = ((DocumentWindow) document).getDelegate();
final MarkupModelEx baseMarkupModel = (MarkupModelEx) forDocument(delegate, project, true);
return new MarkupModelWindow(baseMarkupModel, (DocumentWindow) document);
}
if (project == null) {
MarkupModelEx markupModel = document.getUserData(MARKUP_MODEL_KEY);
if (create && markupModel == null) {
MarkupModelEx newModel = new MarkupModelImpl((DocumentEx) document);
if ((markupModel = ((UserDataHolderEx) document).putUserDataIfAbsent(MARKUP_MODEL_KEY, newModel)) != newModel) {
newModel.dispose();
}
}
return markupModel;
}
final DocumentMarkupModelManager documentMarkupModelManager = project.isDisposed() ? null : DocumentMarkupModelManager.getInstance(project);
if (documentMarkupModelManager == null || documentMarkupModelManager.isDisposed() || project.isDisposed()) {
return new EmptyMarkupModel(document);
}
ConcurrentMap<Project, MarkupModelImpl> markupModelMap = getMarkupModelMap(document);
MarkupModelImpl model = markupModelMap.get(project);
if (create && model == null) {
MarkupModelImpl newModel = new MarkupModelImpl((DocumentEx) document);
if ((model = ConcurrencyUtil.cacheOrGet(markupModelMap, project, newModel)) == newModel) {
documentMarkupModelManager.registerDocument(document);
} else {
newModel.dispose();
}
}
return model;
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method getLastCommittedDocument.
@NotNull
public DocumentEx getLastCommittedDocument(@NotNull Document document) {
if (document instanceof FrozenDocument)
return (DocumentEx) document;
if (document instanceof DocumentWindow) {
DocumentWindow window = (DocumentWindow) document;
Document delegate = window.getDelegate();
if (delegate instanceof FrozenDocument)
return (DocumentEx) window;
if (!window.isValid()) {
throw new AssertionError("host committed: " + isCommitted(delegate) + ", window=" + window);
}
UncommittedInfo info = myUncommittedInfos.get(delegate);
DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(document);
if (answer == null)
answer = freezeWindow(window);
if (info != null)
answer = ConcurrencyUtil.cacheOrGet(info.myFrozenWindows, window, answer);
return (DocumentEx) answer;
}
assert document instanceof DocumentImpl;
UncommittedInfo info = myUncommittedInfos.get(document);
return info != null ? info.myFrozen : ((DocumentImpl) document).freeze();
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method documentChanged.
@Override
public void documentChanged(DocumentEvent event) {
if (myStopTrackingDocuments || myProject.isDisposed())
return;
final Document document = event.getDocument();
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
boolean isRelevant = virtualFile != null && isRelevant(virtualFile);
final FileViewProvider viewProvider = getCachedViewProvider(document);
if (viewProvider == null) {
handleCommitWithoutPsi(document);
return;
}
boolean inMyProject = viewProvider.getManager() == myPsiManager;
if (!isRelevant || !inMyProject) {
clearUncommittedInfo(document);
return;
}
List<PsiFile> files = viewProvider.getAllFiles();
boolean commitNecessary = files.stream().noneMatch(file -> PsiToDocumentSynchronizer.isInsideAtomicChange(file) || !(file instanceof PsiFileImpl));
boolean forceCommit = ApplicationManager.getApplication().hasWriteAction(ExternalChangeAction.class) && (SystemProperties.getBooleanProperty("idea.force.commit.on.external.change", false) || ApplicationManager.getApplication().isHeadlessEnvironment() && !ApplicationManager.getApplication().isUnitTestMode());
// for the huge file (that causes the whole document to be reloaded and 'merge' way takes a while to complete).
if (event.isWholeTextReplaced() && document.getTextLength() > 100000) {
document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE);
}
if (commitNecessary) {
assert !(document instanceof DocumentWindow);
myUncommittedDocuments.add(document);
if (forceCommit) {
commitDocument(document);
} else if (!((DocumentEx) document).isInBulkUpdate() && myPerformBackgroundCommit) {
myDocumentCommitProcessor.commitAsynchronously(myProject, document, event, TransactionGuard.getInstance().getContextTransaction());
}
} else {
clearUncommittedInfo(document);
}
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class FileManagerImpl method getFromInjected.
@Nullable
private FileViewProvider getFromInjected(@NotNull VirtualFile file) {
if (file instanceof VirtualFileWindow) {
DocumentWindow document = ((VirtualFileWindow) file).getDocumentWindow();
PsiFile psiFile = PsiDocumentManager.getInstance(myManager.getProject()).getCachedPsiFile(document);
if (psiFile == null)
return null;
return psiFile.getViewProvider();
}
return null;
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class InjectedSelfElementInfo method hostToInjected.
@Nullable
private static ProperTextRange hostToInjected(boolean psi, Segment hostRange, @Nullable PsiFile injectedFile, @Nullable AffixOffsets affixOffsets) {
VirtualFile virtualFile = injectedFile == null ? null : injectedFile.getVirtualFile();
if (virtualFile instanceof VirtualFileWindow) {
Project project = injectedFile.getProject();
DocumentWindow documentWindow = ((VirtualFileWindow) virtualFile).getDocumentWindow();
if (psi) {
documentWindow = (DocumentWindow) ((PsiDocumentManagerBase) PsiDocumentManager.getInstance(project)).getLastCommittedDocument(documentWindow);
}
int start = documentWindow.hostToInjected(hostRange.getStartOffset());
int end = documentWindow.hostToInjected(hostRange.getEndOffset());
if (affixOffsets != null) {
return affixOffsets.expandRangeToAffixes(start, end, InjectedLanguageManager.getInstance(project).getNonEditableFragments(documentWindow));
}
return ProperTextRange.create(start, end);
}
return null;
}
Aggregations