Search in sources :

Example 1 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow 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 2 with VirtualFileWindow

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

the class UsageInfo2UsageAdapter method getDescriptor.

private OpenFileDescriptor getDescriptor() {
    VirtualFile file = getFile();
    if (file == null)
        return null;
    Segment range = getNavigationRange();
    if (range != null && file instanceof VirtualFileWindow && range.getStartOffset() >= 0) {
        // have to use injectedToHost(TextRange) to calculate right offset in case of multiple shreds
        range = ((VirtualFileWindow) file).getDocumentWindow().injectedToHost(TextRange.create(range));
        file = ((VirtualFileWindow) file).getDelegate();
    }
    return new OpenFileDescriptor(getProject(), file, range == null ? getNavigationOffset() : range.getStartOffset());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow)

Example 3 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow 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;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow 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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentWindow(com.intellij.injected.editor.DocumentWindow) Project(com.intellij.openapi.project.Project) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) PsiDocumentManagerBase(com.intellij.psi.impl.PsiDocumentManagerBase) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with VirtualFileWindow

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

the class InspectionResultsView method getSelectedNavigatable.

@Nullable
private Navigatable getSelectedNavigatable(final CommonProblemDescriptor descriptor, final PsiElement psiElement) {
    if (descriptor instanceof ProblemDescriptorBase) {
        Navigatable navigatable = ((ProblemDescriptorBase) descriptor).getNavigatable();
        if (navigatable != null) {
            return navigatable;
        }
    }
    if (psiElement == null || !psiElement.isValid())
        return null;
    PsiFile containingFile = psiElement.getContainingFile();
    VirtualFile virtualFile = containingFile == null ? null : containingFile.getVirtualFile();
    if (virtualFile != null) {
        int startOffset = psiElement.getTextOffset();
        if (descriptor instanceof ProblemDescriptorBase) {
            final TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRangeForNavigation();
            if (textRange != null) {
                if (virtualFile instanceof VirtualFileWindow) {
                    virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
                }
                startOffset = textRange.getStartOffset();
            }
        }
        return new OpenFileDescriptor(myProject, virtualFile, startOffset);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) TextRange(com.intellij.openapi.util.TextRange) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Nullable (org.jetbrains.annotations.Nullable)7 NotNull (org.jetbrains.annotations.NotNull)5 DocumentWindow (com.intellij.injected.editor.DocumentWindow)4 Project (com.intellij.openapi.project.Project)4 Document (com.intellij.openapi.editor.Document)3 Module (com.intellij.openapi.module.Module)3 TextRange (com.intellij.openapi.util.TextRange)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Language (com.intellij.lang.Language)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 SmartList (com.intellij.util.SmartList)2 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)1 ASTNode (com.intellij.lang.ASTNode)1 Editor (com.intellij.openapi.editor.Editor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Pair (com.intellij.openapi.util.Pair)1