Java Code Examples for com.intellij.lang.injection.InjectedLanguageManager#isInjectedFragment()
The following examples show how to use
com.intellij.lang.injection.InjectedLanguageManager#isInjectedFragment() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BladeInjectTypeProvider.java From idea-php-laravel-plugin with MIT License | 6 votes |
/** * Resolve PHP language injection in Blade * * @see BladeVariableTypeProvider#getHostPhpFileForInjectedIfExists */ @Nullable private static BladeFileImpl getHostBladeFileForInjectionIfExists(PsiElement element) { PsiFile file = element.getContainingFile(); InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(element.getProject()); if (injectedLanguageManager.isInjectedFragment(file)) { PsiLanguageInjectionHost host = injectedLanguageManager.getInjectionHost(element); if (host instanceof BladePsiLanguageInjectionHost && host.isValidHost()) { PsiFile bladeFile = host.getContainingFile(); if (bladeFile instanceof BladeFileImpl) { return (BladeFileImpl) bladeFile; } } } return null; }
Example 2
Source File: TemplateLanguageErrorFilter.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean shouldHighlightErrorElement(@Nonnull PsiErrorElement element) { if (isKnownSubLanguage(element.getParent().getLanguage())) { // // Immediately discard filters with non-matching template class if already known // Class templateClass = element.getUserData(TEMPLATE_VIEW_PROVIDER_CLASS_KEY); if (templateClass != null && (templateClass != myTemplateFileViewProviderClass)) return true; PsiFile psiFile = element.getContainingFile(); int offset = element.getTextOffset(); InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(element.getProject()); if (injectedLanguageManager.isInjectedFragment(psiFile)) { PsiElement host = injectedLanguageManager.getInjectionHost(element); if (host != null) { psiFile = host.getContainingFile(); offset = injectedLanguageManager.injectedToHost(element, offset); } } final FileViewProvider viewProvider = psiFile.getViewProvider(); element.putUserData(TEMPLATE_VIEW_PROVIDER_CLASS_KEY, viewProvider.getClass()); if (!(viewProvider.getClass() == myTemplateFileViewProviderClass)) { return true; } // // An error can occur at template element or before it. Check both. // if (shouldIgnoreErrorAt(viewProvider, offset) || shouldIgnoreErrorAt(viewProvider, offset + 1)) return false; } return true; }
Example 3
Source File: LineMarkersPass.java From consulo with Apache License 2.0 | 5 votes |
private static void queryLineMarkersForInjected(@Nonnull PsiElement element, @Nonnull final PsiFile containingFile, @Nonnull Set<? super PsiFile> visitedInjectedFiles, @Nonnull final PairConsumer<? super PsiElement, ? super LineMarkerInfo<PsiElement>> consumer) { final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(containingFile.getProject()); if (manager.isInjectedFragment(containingFile)) return; InjectedLanguageManager.getInstance(containingFile.getProject()).enumerateEx(element, containingFile, false, (injectedPsi, places) -> { if (!visitedInjectedFiles.add(injectedPsi)) return; // there may be several concatenated literals making the one injected file final Project project = injectedPsi.getProject(); Document document = PsiDocumentManager.getInstance(project).getCachedDocument(injectedPsi); if (!(document instanceof DocumentWindow)) return; List<PsiElement> injElements = CollectHighlightsUtil.getElementsInRange(injectedPsi, 0, injectedPsi.getTextLength()); final List<LineMarkerProvider> providers = getMarkerProviders(injectedPsi.getLanguage(), project); queryProviders(injElements, injectedPsi, providers, (injectedElement, injectedMarker) -> { GutterIconRenderer gutterRenderer = injectedMarker.createGutterRenderer(); TextRange injectedRange = new TextRange(injectedMarker.startOffset, injectedMarker.endOffset); List<TextRange> editables = manager.intersectWithAllEditableFragments(injectedPsi, injectedRange); for (TextRange editable : editables) { TextRange hostRange = manager.injectedToHost(injectedPsi, editable); Image icon = gutterRenderer == null ? null : gutterRenderer.getIcon(); GutterIconNavigationHandler<PsiElement> navigationHandler = injectedMarker.getNavigationHandler(); LineMarkerInfo<PsiElement> converted = new LineMarkerInfo<>(injectedElement, hostRange, icon, injectedMarker.updatePass, e -> injectedMarker.getLineMarkerTooltip(), navigationHandler, GutterIconRenderer.Alignment.RIGHT); consumer.consume(injectedElement, converted); } }); }); }
Example 4
Source File: EditorFoldingInfo.java From consulo with Apache License 2.0 | 5 votes |
@Nullable TextRange getPsiElementRange(@Nonnull FoldRegion region) { PsiElement element = getPsiElement(region); if (element == null) return null; PsiFile containingFile = element.getContainingFile(); InjectedLanguageManager injectedManager = InjectedLanguageManager.getInstance(containingFile.getProject()); boolean isInjected = injectedManager.isInjectedFragment(containingFile); TextRange range = element.getTextRange(); if (isInjected) { range = injectedManager.injectedToHost(element, range); } return range; }
Example 5
Source File: InjectedLanguageUtil.java From consulo with Apache License 2.0 | 5 votes |
public static boolean isInInjectedLanguagePrefixSuffix(@Nonnull final PsiElement element) { PsiFile injectedFile = element.getContainingFile(); if (injectedFile == null) return false; Project project = injectedFile.getProject(); InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(project); if (!languageManager.isInjectedFragment(injectedFile)) return false; TextRange elementRange = element.getTextRange(); List<TextRange> edibles = languageManager.intersectWithAllEditableFragments(injectedFile, elementRange); int combinedEdiblesLength = edibles.stream().mapToInt(TextRange::getLength).sum(); return combinedEdiblesLength != elementRange.getLength(); }
Example 6
Source File: BashPsiUtils.java From BashSupport with Apache License 2.0 | 4 votes |
public static boolean isInjectedElement(@NotNull PsiElement element) { InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(element.getProject()); return languageManager.isInjectedFragment(element.getContainingFile()) || hasInjectionHostParent(element); }