Search in sources :

Example 6 with DocumentWindowImpl

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

the class InjectedFileViewProvider method rootChanged.

@Override
public void rootChanged(@NotNull PsiFile psiFile) {
    super.rootChanged(psiFile);
    // injected PSI change happened inside reparse; ignore
    if (!isPhysical())
        return;
    if (myPatchingLeaves)
        return;
    DocumentWindowImpl documentWindow = myDocumentWindow;
    List<PsiLanguageInjectionHost.Shred> shreds = documentWindow.getShreds();
    assert documentWindow.getHostRanges().length == shreds.size();
    String[] changes = documentWindow.calculateMinEditSequence(psiFile.getNode().getText());
    assert changes.length == shreds.size();
    for (int i = 0; i < changes.length; i++) {
        String change = changes[i];
        if (change != null) {
            PsiLanguageInjectionHost.Shred shred = shreds.get(i);
            PsiLanguageInjectionHost host = shred.getHost();
            TextRange rangeInsideHost = shred.getRangeInsideHost();
            String newHostText = StringUtil.replaceSubstring(host.getText(), rangeInsideHost, change);
            //shred.host =
            host.updateText(newHostText);
        }
    }
}
Also used : DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) TextRange(com.intellij.openapi.util.TextRange)

Example 7 with DocumentWindowImpl

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

the class InjectedLanguageManagerImpl method injectedToHost.

@Override
public int injectedToHost(@NotNull PsiElement element, int offset) {
    PsiFile file = element.getContainingFile();
    if (file == null)
        return offset;
    Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
    if (!(document instanceof DocumentWindowImpl))
        return offset;
    DocumentWindowImpl documentWindow = (DocumentWindowImpl) document;
    return documentWindow.injectedToHost(offset);
}
Also used : DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) Document(com.intellij.openapi.editor.Document)

Example 8 with DocumentWindowImpl

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

the class InjectedLanguageManagerImpl method getNonEditableFragments.

@NotNull
@Override
public List<TextRange> getNonEditableFragments(@NotNull DocumentWindow window) {
    List<TextRange> result = ContainerUtil.newArrayList();
    int offset = 0;
    for (PsiLanguageInjectionHost.Shred shred : ((DocumentWindowImpl) window).getShreds()) {
        Segment hostRange = shred.getHostRangeMarker();
        if (hostRange == null)
            continue;
        offset = appendRange(result, offset, shred.getPrefix().length());
        offset += hostRange.getEndOffset() - hostRange.getStartOffset();
        offset = appendRange(result, offset, shred.getSuffix().length());
    }
    return result;
}
Also used : DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) TextRange(com.intellij.openapi.util.TextRange) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) Segment(com.intellij.openapi.util.Segment) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DocumentWindowImpl

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

the class InjectedLanguageManagerImpl method injectedToHost.

@Override
@NotNull
public TextRange injectedToHost(@NotNull PsiElement injectedContext, @NotNull TextRange injectedTextRange) {
    PsiFile file = injectedContext.getContainingFile();
    if (file == null)
        return injectedTextRange;
    Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
    if (!(document instanceof DocumentWindowImpl))
        return injectedTextRange;
    DocumentWindowImpl documentWindow = (DocumentWindowImpl) document;
    return documentWindow.injectedToHost(injectedTextRange);
}
Also used : DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)9 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)4 DocumentWindow (com.intellij.injected.editor.DocumentWindow)3 ASTNode (com.intellij.lang.ASTNode)3 Language (com.intellij.lang.Language)3 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)2 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)2 VirtualFileWindowImpl (com.intellij.injected.editor.VirtualFileWindowImpl)2 ParserDefinition (com.intellij.lang.ParserDefinition)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Segment (com.intellij.openapi.util.Segment)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiDocumentManagerBase (com.intellij.psi.impl.PsiDocumentManagerBase)2 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)2 DiffLog (com.intellij.psi.impl.source.text.DiffLog)2 FileElement (com.intellij.psi.impl.source.tree.FileElement)2 List (java.util.List)2 LiveTemplateBuilder (com.intellij.codeInsight.template.LiveTemplateBuilder)1 SingleLineEmmetFilter (com.intellij.codeInsight.template.emmet.filters.SingleLineEmmetFilter)1