use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class LightPlatformCodeInsightTestCase method bringRealEditorBack.
protected static void bringRealEditorBack() {
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
if (myEditor instanceof EditorWindow) {
Document document = ((DocumentWindow) myEditor.getDocument()).getDelegate();
myFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(document);
myEditor = ((EditorWindow) myEditor).getDelegate();
myVFile = myFile.getVirtualFile();
}
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-plugins by JetBrains.
the class CssWriter method write.
@Nullable
private byte[] write(@NotNull StylesheetFile stylesheetFile, @NotNull Document document, @NotNull Module module) {
CssStylesheet stylesheet = stylesheetFile.getStylesheet();
if (stylesheet == null) {
LOG.warn("Stylesheet is null for " + stylesheetFile.getName());
return null;
}
rulesetVectorWriter.prepareIteration();
DocumentWindow documentWindow = document instanceof DocumentWindow ? (DocumentWindow) document : null;
for (CssRuleset ruleset : stylesheet.getRulesets()) {
CssBlock block = ruleset.getBlock();
if (block == null) {
continue;
}
PrimitiveAmfOutputStream rulesetOut = rulesetVectorWriter.getOutputForIteration();
int textOffset = ruleset.getTextOffset();
if (documentWindow == null) {
rulesetOut.writeUInt29(document.getLineNumber(textOffset) + 1);
} else {
rulesetOut.writeUInt29(documentWindow.injectedToHostLine(document.getLineNumber(textOffset)) + 1);
textOffset = documentWindow.injectedToHost(textOffset);
}
rulesetOut.writeUInt29(textOffset);
writeSelectors(ruleset, rulesetOut, module);
declarationVectorWriter.prepareIteration();
for (CssDeclaration declaration : block.getDeclarations()) {
CssTermList value = declaration.getValue();
if (value == null || PsiTreeUtil.getChildOfType(value, PsiErrorElement.class) != null) {
continue;
}
propertyOut = declarationVectorWriter.getOutputForIteration();
try {
stringWriter.write(declaration.getPropertyName(), propertyOut);
textOffset = declaration.getTextOffset();
propertyOut.writeUInt29(documentWindow == null ? textOffset : documentWindow.injectedToHost(textOffset));
CssPropertyDescriptor propertyDescriptor = ContainerUtil.getFirstItem(declaration.getDescriptors());
writePropertyValue(value, propertyDescriptor != null && propertyDescriptor instanceof FlexCssPropertyDescriptor ? ((FlexCssPropertyDescriptor) propertyDescriptor).getStyleInfo() : null);
continue;
} catch (RuntimeException e) {
problemsHolder.add(declaration, e, declaration.getPropertyName());
} catch (Throwable e) {
problemsHolder.add(e);
}
declarationVectorWriter.rollbackLastIteration();
}
// must be written in any case, IDEA-86219, ruleset without rules
declarationVectorWriter.writeTo(rulesetOut);
}
PrimitiveAmfOutputStream outputForCustomData = rulesetVectorWriter.getOutputForCustomData();
CssNamespace[] namespaces = stylesheet.getNamespaces();
outputForCustomData.write(namespaces.length);
if (namespaces.length > 0) {
for (CssNamespace cssNamespace : namespaces) {
stringWriter.writeNullable(cssNamespace.getPrefix(), outputForCustomData);
stringWriter.writeNullable(cssNamespace.getUri(), outputForCustomData);
}
}
return IOUtil.getBytes(rulesetVectorWriter);
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class InjectedGeneralHighlightingPass method getInjectedPsiFiles.
@NotNull
private Set<PsiFile> getInjectedPsiFiles(@NotNull final List<PsiElement> elements1, @NotNull final List<PsiElement> elements2, @NotNull final ProgressIndicator progress) {
ApplicationManager.getApplication().assertReadAccessAllowed();
List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(myFile);
final Collection<PsiElement> hosts = new THashSet<>(elements1.size() + elements2.size() + injected.size());
//since change in one place can lead to invalidation of injected PSI in (completely) other place.
for (DocumentWindow documentRange : injected) {
progress.checkCanceled();
if (!documentRange.isValid())
continue;
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(documentRange);
if (file == null)
continue;
PsiElement context = InjectedLanguageManager.getInstance(file.getProject()).getInjectionHost(file);
if (context != null && context.isValid() && !file.getProject().isDisposed() && (myUpdateAll || myRestrictRange.intersects(context.getTextRange()))) {
hosts.add(context);
}
}
InjectedLanguageManagerImpl injectedLanguageManager = InjectedLanguageManagerImpl.getInstanceImpl(myProject);
Processor<PsiElement> collectInjectableProcessor = Processors.cancelableCollectProcessor(hosts);
injectedLanguageManager.processInjectableElements(elements1, collectInjectableProcessor);
injectedLanguageManager.processInjectableElements(elements2, collectInjectableProcessor);
final Set<PsiFile> outInjected = new THashSet<>();
final PsiLanguageInjectionHost.InjectedPsiVisitor visitor = new PsiLanguageInjectionHost.InjectedPsiVisitor() {
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
synchronized (outInjected) {
outInjected.add(injectedPsi);
}
}
};
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(hosts), progress, true, element -> {
ApplicationManager.getApplication().assertReadAccessAllowed();
progress.checkCanceled();
InjectedLanguageUtil.enumerate(element, myFile, false, visitor);
return true;
})) {
throw new ProcessCanceledException();
}
synchronized (outInjected) {
return outInjected;
}
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class LocalInspectionsPass method addDescriptorsFromInjectedResults.
private void addDescriptorsFromInjectedResults(@NotNull InspectionManager iManager, @NotNull GlobalInspectionContextImpl context) {
InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
for (Map.Entry<PsiFile, List<InspectionResult>> entry : result.entrySet()) {
PsiFile file = entry.getKey();
// not injected
if (file == getFile())
continue;
DocumentWindow documentRange = (DocumentWindow) documentManager.getDocument(file);
List<InspectionResult> resultList = entry.getValue();
for (InspectionResult inspectionResult : resultList) {
LocalInspectionToolWrapper toolWrapper = inspectionResult.tool;
for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null)
continue;
if (SuppressionUtil.inspectionResultSuppressed(psiElement, toolWrapper.getTool()))
continue;
List<TextRange> editables = ilManager.intersectWithAllEditableFragments(file, ((ProblemDescriptorBase) descriptor).getTextRange());
for (TextRange editable : editables) {
TextRange hostRange = documentRange.injectedToHost(editable);
QuickFix[] fixes = descriptor.getFixes();
LocalQuickFix[] localFixes = null;
if (fixes != null) {
localFixes = new LocalQuickFix[fixes.length];
for (int k = 0; k < fixes.length; k++) {
QuickFix fix = fixes[k];
localFixes[k] = (LocalQuickFix) fix;
}
}
ProblemDescriptor patchedDescriptor = iManager.createProblemDescriptor(getFile(), hostRange, descriptor.getDescriptionTemplate(), descriptor.getHighlightType(), true, localFixes);
addDescriptors(toolWrapper, patchedDescriptor, context);
}
}
}
}
}
use of com.intellij.injected.editor.DocumentWindow in project intellij-community by JetBrains.
the class LocalInspectionsPass method createHighlightsForDescriptor.
private void createHighlightsForDescriptor(@NotNull List<HighlightInfo> outInfos, @NotNull Set<Pair<TextRange, String>> emptyActionRegistered, @NotNull InjectedLanguageManager ilManager, @NotNull PsiFile file, @NotNull Document documentRange, @NotNull LocalInspectionToolWrapper toolWrapper, @NotNull HighlightSeverity severity, @NotNull ProblemDescriptor descriptor, @NotNull PsiElement element) {
LocalInspectionTool tool = toolWrapper.getTool();
if (myIgnoreSuppressed && SuppressionUtil.inspectionResultSuppressed(element, tool))
return;
HighlightInfoType level = ProblemDescriptorUtil.highlightTypeFromDescriptor(descriptor, severity, mySeverityRegistrar);
HighlightInfo info = createHighlightInfo(descriptor, toolWrapper, level, emptyActionRegistered, element);
if (info == null)
return;
PsiFile context = getTopLevelFileInBaseLanguage(element);
PsiFile myContext = getTopLevelFileInBaseLanguage(getFile());
if (context != getFile()) {
LOG.error("Reported element " + element + " is not from the file '" + file + "' the inspection '" + toolWrapper + "' (" + tool.getClass() + ") " + "was invoked for. Message: '" + descriptor + "'.\n" + "Element' containing file: " + context + "\n" + "Inspection invoked for file: " + myContext + "\n");
}
boolean isInjected = file != getFile();
if (!isInjected) {
outInfos.add(info);
return;
}
// todo we got to separate our "internal" prefixes/suffixes from user-defined ones
// todo in the latter case the errors should be highlighted, otherwise not
List<TextRange> editables = ilManager.intersectWithAllEditableFragments(file, new TextRange(info.startOffset, info.endOffset));
for (TextRange editable : editables) {
TextRange hostRange = ((DocumentWindow) documentRange).injectedToHost(editable);
int start = hostRange.getStartOffset();
int end = hostRange.getEndOffset();
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(info.type).range(element, start, end);
String description = info.getDescription();
if (description != null) {
builder.description(description);
}
String toolTip = info.getToolTip();
if (toolTip != null) {
builder.escapedToolTip(toolTip);
}
HighlightInfo patched = builder.createUnconditionally();
if (patched.startOffset != patched.endOffset || info.startOffset == info.endOffset) {
patched.setFromInjection(true);
registerQuickFixes(toolWrapper, descriptor, patched, emptyActionRegistered);
outInfos.add(patched);
}
}
}
Aggregations