LinkedHashSet<TextRange> (@NotNull TextRange range) { // We use a set here because we encountered a situation when more than one PSI leaf points to the same injected fragment // (at least for sql injected into sql). final LinkedHashSet<TextRange> injectedFileRangesSet = new LinkedHashSet<>(); if (myPsiFile.getProject().isDefault()) return injectedFileRangesSet; List<DocumentWindow> injectedDocuments = InjectedLanguageManager.getInstance(myPsiFile.getProject()).getCachedInjectedDocumentsInRange(myPsiFile, myPsiFile.getTextRange()); if (!injectedDocuments.isEmpty()) { for (DocumentWindow injectedDocument : injectedDocuments) { injectedFileRangesSet.add(TextRange.from(injectedDocument.injectedToHost(0), injectedDocument.getTextLength())); } } else { Collection<PsiLanguageInjectionHost> injectionHosts = collectInjectionHosts(myPsiFile, range); PsiLanguageInjectionHost.InjectedPsiVisitor visitor = (injectedPsi, places) -> { for (PsiLanguageInjectionHost.Shred place : places) { Segment rangeMarker = place.getHostRangeMarker(); if (rangeMarker != null) { injectedFileRangesSet.add(TextRange.create(rangeMarker.getStartOffset(), rangeMarker.getEndOffset())); } } }; for (PsiLanguageInjectionHost host : injectionHosts) { ProgressManager.checkCanceled(); InjectedLanguageManager.getInstance(myPsiFile.getProject()).enumerate(host, visitor); } } return injectedFileRangesSet; }