Search in sources :

Example 11 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class PsiDocumentManagerImpl method doPostponedOperationsAndUnblockDocument.

@Override
public void doPostponedOperationsAndUnblockDocument(@NotNull Document doc) {
    if (doc instanceof DocumentWindow)
        doc = ((DocumentWindow) doc).getDelegate();
    final PostprocessReformattingAspect component = myProject.getComponent(PostprocessReformattingAspect.class);
    final FileViewProvider viewProvider = getCachedViewProvider(doc);
    if (viewProvider != null && component != null)
        component.doPostponedFormatting(viewProvider);
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) FileViewProvider(com.intellij.psi.FileViewProvider)

Example 12 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class MoverWrapper method indentLinesIn.

private static void indentLinesIn(final Editor editor, final PsiFile file, final Document document, final Project project, RangeMarker range) {
    final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
    int line1 = editor.offsetToLogicalPosition(range.getStartOffset()).line;
    int line2 = editor.offsetToLogicalPosition(range.getEndOffset()).line;
    while (!lineContainsNonSpaces(document, line1) && line1 < line2) line1++;
    while (!lineContainsNonSpaces(document, line2) && line1 < line2) line2--;
    final FileViewProvider provider = file.getViewProvider();
    PsiFile rootToAdjustIndentIn = provider.getPsi(provider.getBaseLanguage());
    codeStyleManager.adjustLineIndent(rootToAdjustIndentIn, new TextRange(document.getLineStartOffset(line1), document.getLineStartOffset(line2)));
}
Also used : CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) FileViewProvider(com.intellij.psi.FileViewProvider) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange)

Example 13 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class TrafficLightRenderer method getDaemonCodeAnalyzerStatus.

@NotNull
protected DaemonCodeAnalyzerStatus getDaemonCodeAnalyzerStatus(@NotNull SeverityRegistrar severityRegistrar) {
    DaemonCodeAnalyzerStatus status = new DaemonCodeAnalyzerStatus();
    if (myFile == null) {
        status.reasonWhyDisabled = "No file";
        status.errorAnalyzingFinished = true;
        return status;
    }
    if (myProject != null && myProject.isDisposed()) {
        status.reasonWhyDisabled = "Project is disposed";
        status.errorAnalyzingFinished = true;
        return status;
    }
    if (!myDaemonCodeAnalyzer.isHighlightingAvailable(myFile)) {
        if (!myFile.isPhysical()) {
            status.reasonWhyDisabled = "File is generated";
            status.errorAnalyzingFinished = true;
            return status;
        } else if (myFile instanceof PsiCompiledElement) {
            status.reasonWhyDisabled = "File is decompiled";
            status.errorAnalyzingFinished = true;
            return status;
        }
        final FileType fileType = myFile.getFileType();
        if (fileType.isBinary()) {
            status.reasonWhyDisabled = "File is binary";
            status.errorAnalyzingFinished = true;
            return status;
        }
        status.reasonWhyDisabled = "Highlighting is disabled for this file";
        status.errorAnalyzingFinished = true;
        return status;
    }
    FileViewProvider provider = myFile.getViewProvider();
    Set<Language> languages = provider.getLanguages();
    HighlightingSettingsPerFile levelSettings = HighlightingSettingsPerFile.getInstance(myProject);
    boolean shouldHighlight = languages.isEmpty();
    for (Language language : languages) {
        PsiFile root = provider.getPsi(language);
        FileHighlightingSetting level = levelSettings.getHighlightingSettingForRoot(root);
        shouldHighlight |= level != FileHighlightingSetting.SKIP_HIGHLIGHTING;
    }
    if (!shouldHighlight) {
        status.reasonWhyDisabled = "Highlighting level is None";
        status.errorAnalyzingFinished = true;
        return status;
    }
    if (HeavyProcessLatch.INSTANCE.isRunning()) {
        status.reasonWhySuspended = StringUtil.defaultIfEmpty(HeavyProcessLatch.INSTANCE.getRunningOperationName(), "Heavy operation is running");
        status.errorAnalyzingFinished = true;
        return status;
    }
    status.errorCount = errorCount.clone();
    List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument);
    status.passStati = passes.isEmpty() ? Collections.emptyList() : new ArrayList<>(passes.size());
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < passes.size(); i++) {
        TextEditorHighlightingPass tepass = passes.get(i);
        if (!(tepass instanceof ProgressableTextEditorHighlightingPass))
            continue;
        ProgressableTextEditorHighlightingPass pass = (ProgressableTextEditorHighlightingPass) tepass;
        if (pass.getProgress() < 0)
            continue;
        status.passStati.add(pass);
    }
    status.errorAnalyzingFinished = myDaemonCodeAnalyzer.isAllAnalysisFinished(myFile);
    status.reasonWhySuspended = myDaemonCodeAnalyzer.isUpdateByTimerEnabled() ? null : "Highlighting is paused temporarily";
    fillDaemonCodeAnalyzerErrorsStatus(status, severityRegistrar);
    return status;
}
Also used : HighlightingSettingsPerFile(com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile) TIntArrayList(gnu.trove.TIntArrayList) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) FileHighlightingSetting(com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class SelectWordUtil method processRanges.

public static void processRanges(@Nullable PsiElement element, CharSequence text, int cursorOffset, Editor editor, Processor<TextRange> consumer) {
    if (element == null)
        return;
    PsiFile file = element.getContainingFile();
    FileViewProvider viewProvider = file.getViewProvider();
    processInFile(element, consumer, text, cursorOffset, editor);
    for (PsiFile psiFile : viewProvider.getAllFiles()) {
        if (psiFile == file)
            continue;
        FileASTNode fileNode = psiFile.getNode();
        if (fileNode == null)
            continue;
        ASTNode nodeAt = fileNode.findLeafElementAt(element.getTextOffset());
        if (nodeAt == null)
            continue;
        PsiElement elementAt = nodeAt.getPsi();
        while (!(elementAt instanceof PsiFile) && elementAt != null) {
            if (elementAt.getTextRange().contains(element.getTextRange()))
                break;
            elementAt = elementAt.getParent();
        }
        if (elementAt == null)
            continue;
        processInFile(elementAt, consumer, text, cursorOffset, editor);
    }
}
Also used : FileASTNode(com.intellij.lang.FileASTNode) FileViewProvider(com.intellij.psi.FileViewProvider) ASTNode(com.intellij.lang.ASTNode) FileASTNode(com.intellij.lang.FileASTNode) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 15 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class HighlightingSettingsPerFile method getRootIndex.

private static int getRootIndex(PsiFile file) {
    FileViewProvider provider = file.getViewProvider();
    Set<Language> languages = provider.getLanguages();
    if (languages.size() == 1) {
        return 0;
    }
    List<Language> array = new ArrayList<>(languages);
    Collections.sort(array, PsiUtilBase.LANGUAGE_COMPARATOR);
    for (int i = 0; i < array.size(); i++) {
        Language language = array.get(i);
        if (provider.getPsi(language) == file)
            return i;
    }
    throw new RuntimeException("Cannot find root for: " + file);
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) SingleRootFileViewProvider(com.intellij.psi.SingleRootFileViewProvider) Language(com.intellij.lang.Language)

Aggregations

FileViewProvider (com.intellij.psi.FileViewProvider)41 PsiFile (com.intellij.psi.PsiFile)22 Language (com.intellij.lang.Language)21 PsiElement (com.intellij.psi.PsiElement)15 NotNull (org.jetbrains.annotations.NotNull)12 TextRange (com.intellij.openapi.util.TextRange)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)5 Project (com.intellij.openapi.project.Project)4 ASTNode (com.intellij.lang.ASTNode)3 Document (com.intellij.openapi.editor.Document)3 Pair (com.intellij.openapi.util.Pair)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingLevelManager (com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager)2 FileASTNode (com.intellij.lang.FileASTNode)2 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)2 XMLLanguage (com.intellij.lang.xml.XMLLanguage)2 FileType (com.intellij.openapi.fileTypes.FileType)2 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)2 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)2