use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.
the class PodLinkToFileReference method resolveInner.
@Override
@NotNull
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PodFormatterL podLink = getElement();
PodLinkDescriptor descriptor = podLink.getLinkDescriptor();
if (descriptor != null && !descriptor.isUrl() && descriptor.getName() != null) {
PsiFile targetFile = PodFileUtil.getPodOrPackagePsiByDescriptor(podLink.getProject(), descriptor);
if (targetFile != null) {
return new ResolveResult[] { new PsiElementResolveResult(targetFile) };
}
}
return ResolveResult.EMPTY_ARRAY;
}
use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.
the class PodLinkCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition();
PsiElement linkPart = element.getParent();
PodFormatterL linkElement = PsiTreeUtil.getParentOfType(element, PodFormatterL.class);
if (linkElement == null) {
return;
}
IElementType parentType = PsiUtilCore.getElementType(linkPart);
PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, linkElement);
if (parentType == LINK_TEXT && element.getPrevSibling() == null) {
processFilesCompletions(completionProcessor);
}
if (parentType == LINK_NAME) {
processFilesCompletions(completionProcessor);
}
if (parentType == LINK_SECTION) {
addSectionsCompletions(linkElement.getTargetFile(), completionProcessor);
}
completionProcessor.logStatus(getClass());
}
use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.
the class PodLinkToSectionReference method resolveInner.
@Override
@NotNull
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PodFormatterL podLink = getElement();
PodLinkDescriptor descriptor = podLink.getLinkDescriptor();
String sectionTitle = descriptor == null ? null : descriptor.getSection();
if (sectionTitle == null || descriptor.isUrl()) {
return ResolveResult.EMPTY_ARRAY;
}
List<PsiFile> targetFiles = new ArrayList<>();
if (descriptor.getName() != null && !descriptor.isSameFile()) {
for (PsiReference reference : podLink.getReferences()) {
if (reference instanceof PodLinkToFileReference) {
for (ResolveResult resolveResult : ((PodLinkToFileReference) reference).multiResolve(false)) {
targetFiles.add((PsiFile) resolveResult.getElement());
}
}
}
} else {
targetFiles.add(podLink.getContainingFile());
}
if (targetFiles.isEmpty()) {
return ResolveResult.EMPTY_ARRAY;
}
List<PsiElement> results = new ArrayList<>();
for (PsiFile file : targetFiles) {
file.accept(new PodStubsAwareRecursiveVisitor() {
@Override
public void visitTargetableSection(PodTitledSection o) {
if (StringUtil.equals(sectionTitle, o.getTitleText())) {
results.add(o);
}
super.visitTargetableSection(o);
}
});
if (!results.isEmpty()) {
break;
}
}
return PsiElementResolveResult.createResults(results);
}
use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.
the class PodLegacySectionLinkInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PodVisitor() {
@Override
public void visitPodFormatLink(@NotNull PsiPodFormatLink o) {
assert o instanceof PodFormatterL;
PodFormatterL link = (PodFormatterL) o;
PsiLinkSection sectionelement = link.getLinkSectionElement();
if (link.getLinkNameElement() == null && isSectionLegacy(sectionelement)) {
holder.registerProblem(sectionelement, "Section \"" + PodRenderUtil.renderPsiElementAsText(sectionelement) + "\" should have a slash before it", ProblemHighlightType.LIKE_DEPRECATED);
}
super.visitPodFormatLink(o);
}
@Contract("null -> false")
private boolean isSectionLegacy(@Nullable PsiLinkSection linkSection) {
if (linkSection == null) {
return false;
}
PsiElement run = linkSection.getPrevSibling();
IElementType elementType = PsiUtilCore.getElementType(run);
return elementType != POD_DIV && !(elementType == POD_QUOTE_DOUBLE && PsiUtilCore.getElementType(run.getPrevSibling()) == POD_DIV);
}
};
}
use of com.perl5.lang.pod.parser.psi.mixin.PodFormatterL in project Perl5-IDEA by Camelcade.
the class PodUnresolvableLinkInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PodVisitor() {
@Override
public void visitPodFormatLink(@NotNull PsiPodFormatLink o) {
assert o instanceof PodFormatterL;
PodFormatterL link = (PodFormatterL) o;
for (PsiReference reference : link.getReferences()) {
if (reference instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) reference).multiResolve(false).length == 0) {
String error;
if (reference instanceof PodLinkToFileReference) {
String fileName = "UNKNONW";
PodLinkDescriptor descriptor = link.getLinkDescriptor();
if (descriptor != null && descriptor.getName() != null) {
fileName = descriptor.getName();
}
error = "Can't find POD or PM file by: " + fileName;
} else if (reference instanceof PodLinkToSectionReference) {
String fileName = "UNKNONW";
PodLinkDescriptor descriptor = link.getLinkDescriptor();
if (descriptor != null && descriptor.getSection() != null) {
fileName = descriptor.getSection();
}
error = "Can't find POD section: " + fileName;
} else {
error = "Can't find reference target";
}
holder.registerProblem(reference, error, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
super.visitPodFormatLink(o);
}
};
}
Aggregations