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);
}
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)));
}
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;
}
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);
}
}
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);
}
Aggregations