Search in sources :

Example 21 with DocumentWindow

use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.

the class PsiDocumentManagerBase method finishCommitInWriteAction.

protected boolean finishCommitInWriteAction(@NotNull final Document document, @NotNull final List<Processor<Document>> finishProcessors, final boolean synchronously) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myProject.isDisposed())
        return false;
    assert !(document instanceof DocumentWindow);
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    if (virtualFile != null) {
        getSmartPointerManager().fastenBelts(virtualFile);
    }
    FileViewProvider viewProvider = getCachedViewProvider(document);
    myIsCommitInProgress = true;
    boolean success = true;
    try {
        if (viewProvider != null) {
            success = commitToExistingPsi(document, finishProcessors, synchronously, virtualFile, viewProvider);
        } else {
            handleCommitWithoutPsi(document);
        }
    } catch (Throwable e) {
        forceReload(virtualFile, viewProvider);
        LOG.error(e);
    } finally {
        if (success) {
            myUncommittedDocuments.remove(document);
        }
        myIsCommitInProgress = false;
    }
    return success;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 22 with DocumentWindow

use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.

the class SingleRootFileViewProvider method checkLengthConsistency.

private void checkLengthConsistency() {
    Document document = getCachedDocument();
    if (document instanceof DocumentWindow) {
        return;
    }
    if (document != null && ((PsiDocumentManagerBase) PsiDocumentManager.getInstance(myManager.getProject())).getSynchronizer().isInSynchronization(document)) {
        return;
    }
    List<FileElement> knownTreeRoots = getKnownTreeRoots();
    if (knownTreeRoots.isEmpty())
        return;
    int fileLength = myContent.getTextLength();
    for (FileElement fileElement : knownTreeRoots) {
        int nodeLength = fileElement.getTextLength();
        if (nodeLength != fileLength) {
            PsiUtilCore.ensureValid(fileElement.getPsi());
            List<Attachment> attachments = ContainerUtil.newArrayList(new Attachment(myVirtualFile.getNameWithoutExtension() + ".tree.txt", fileElement.getText()), new Attachment(myVirtualFile.getNameWithoutExtension() + ".file.txt", myContent.toString()));
            if (document != null) {
                attachments.add(new Attachment(myVirtualFile.getNameWithoutExtension() + ".document.txt", document.getText()));
            }
            // exceptions here should be assigned to peter
            LOG.error("Inconsistent " + fileElement.getElementType() + " tree in " + this + "; nodeLength=" + nodeLength + "; fileLength=" + fileLength, attachments.toArray(Attachment.EMPTY_ARRAY));
        }
    }
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) FileElement(com.intellij.psi.impl.source.tree.FileElement) Attachment(com.intellij.openapi.diagnostic.Attachment) Document(com.intellij.openapi.editor.Document)

Example 23 with DocumentWindow

use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.

the class SelectInEditorManagerImpl method selectInEditor.

@Override
public void selectInEditor(VirtualFile file, final int startOffset, final int endOffset, final boolean toSelectLine, final boolean toUseNormalSelection) {
    releaseAll();
    final TextRange textRange;
    if (file instanceof VirtualFileWindow) {
        DocumentWindow documentWindow = ((VirtualFileWindow) file).getDocumentWindow();
        textRange = documentWindow.injectedToHost(new TextRange(startOffset, endOffset));
        file = ((VirtualFileWindow) file).getDelegate();
    } else {
        textRange = new ProperTextRange(startOffset, endOffset);
    }
    openEditor(file, endOffset);
    final Editor editor = openEditor(file, textRange.getStartOffset());
    SwingUtilities.invokeLater(() -> {
        if (editor != null && !editor.isDisposed()) {
            doSelect(toUseNormalSelection, editor, toSelectLine, textRange);
        }
    });
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor)

Example 24 with DocumentWindow

use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.

the class EditorActionManagerImpl method getReadonlyFragmentModificationHandler.

@Override
public ReadonlyFragmentModificationHandler getReadonlyFragmentModificationHandler(@NotNull final Document document) {
    final Document doc = document instanceof DocumentWindow ? ((DocumentWindow) document).getDelegate() : document;
    final ReadonlyFragmentModificationHandler docHandler = doc instanceof DocumentImpl ? ((DocumentImpl) doc).getReadonlyFragmentModificationHandler() : null;
    return docHandler == null ? myReadonlyFragmentsHandler : docHandler;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) Document(com.intellij.openapi.editor.Document)

Example 25 with DocumentWindow

use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.

the class EditorFactoryImpl method createEditor.

private Editor createEditor(@NotNull Document document, boolean isViewer, Project project) {
    Document hostDocument = document instanceof DocumentWindow ? ((DocumentWindow) document).getDelegate() : document;
    EditorImpl editor = new EditorImpl(hostDocument, isViewer, project);
    myEditors.add(editor);
    myEditorEventMulticaster.registerEditor(editor);
    myEditorFactoryEventDispatcher.getMulticaster().editorCreated(new EditorFactoryEvent(this, editor));
    if (LOG.isDebugEnabled()) {
        LOG.debug("number of Editors after create: " + myEditors.size());
    }
    return editor;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) EditorFactoryEvent(com.intellij.openapi.editor.event.EditorFactoryEvent) Document(com.intellij.openapi.editor.Document)

Aggregations

DocumentWindow (com.intellij.injected.editor.DocumentWindow)42 TextRange (com.intellij.openapi.util.TextRange)18 Document (com.intellij.openapi.editor.Document)17 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)9 Project (com.intellij.openapi.project.Project)8 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 PsiFile (com.intellij.psi.PsiFile)6 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)5 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)4 Language (com.intellij.lang.Language)4 Editor (com.intellij.openapi.editor.Editor)4 Segment (com.intellij.openapi.util.Segment)4 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)4 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)3 ASTNode (com.intellij.lang.ASTNode)3 com.intellij.psi (com.intellij.psi)3 PsiElement (com.intellij.psi.PsiElement)3 PsiDocumentManagerBase (com.intellij.psi.impl.PsiDocumentManagerBase)3