use of com.perl5.lang.htmlmason.parser.psi.references.HTMLMasonMethodReference in project Perl5-IDEA by Camelcade.
the class HTMLMasonComponentCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
PsiFile file = position.getContainingFile();
if (parent instanceof PerlString && file instanceof HTMLMasonFileImpl) {
PsiReference[] references = parent.getReferences();
for (PsiReference reference : references) {
TextRange refRange = reference.getRangeInElement();
if (refRange.contains(position.getStartOffsetInParent())) {
Project project = position.getProject();
String fullPrefix = refRange.substring(parent.getText()).replace(CompletionInitializationContext.DUMMY_IDENTIFIER, "").replace(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED, "");
final CompletionResultSet finalResultSet = result.withPrefixMatcher(fullPrefix);
;
if (reference instanceof HTMLMasonMethodReference) {
PsiElement firstReferenceTarget = references[0].resolve();
if (firstReferenceTarget instanceof HTMLMasonFileImpl) {
HTMLMasonCompletionUtil.fillWithMethods(finalResultSet, (HTMLMasonFileImpl) firstReferenceTarget);
}
} else {
HTMLMasonCompletionUtil.fillWithComponentSlugs(finalResultSet);
HTMLMasonCompletionUtil.fillWithSubcomponents(finalResultSet, (HTMLMasonFileImpl) file);
if (!StringUtil.startsWith(fullPrefix, "/")) {
HTMLMasonCompletionUtil.fillWithRelativeSubcomponents(finalResultSet, project, (HTMLMasonFileImpl) file);
} else {
HTMLMasonCompletionUtil.fillWithAbsoluteSubcomponents(finalResultSet, project);
}
}
result.stopHere();
break;
}
}
}
}
use of com.perl5.lang.htmlmason.parser.psi.references.HTMLMasonMethodReference in project Perl5-IDEA by Camelcade.
the class HTMLMasonComponentReferencesProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
if (element.getChildren().length == 0) {
assert element instanceof PerlString;
String content = ElementManipulators.getValueText(element);
if (StringUtil.isNotEmpty(content)) {
Matcher m;
TextRange range = ElementManipulators.getValueTextRange(element);
List<PsiReference> result = new ArrayList<>();
if (// method call
(m = METHOD_CALL_PATTERN.matcher(content)).matches()) {
String fileOrSlug = m.group(1);
String methodName = m.group(2);
if (methodName == null) {
methodName = "";
}
TextRange componentRange = new TextRange(range.getStartOffset(), range.getStartOffset() + fileOrSlug.length());
TextRange methodRange = new TextRange(range.getEndOffset() - methodName.length(), range.getEndOffset());
if (StringUtil.equals(fileOrSlug, COMPONENT_SLUG_SELF)) {
result.add(new HTMLMasonComponentSimpleReference((PerlString) element, componentRange));
} else if (StringUtil.equals(fileOrSlug, COMPONENT_SLUG_PARENT)) {
result.add(new HTMLMasonComponentParentReference((PerlString) element, componentRange));
} else if (StringUtil.equals(fileOrSlug, COMPONENT_SLUG_REQUEST)) {
result.add(new HTMLMasonComponentSimpleReference((PerlString) element, componentRange));
} else // component or subcomponent
{
result.add(new HTMLMasonComponentReference((PerlString) element, componentRange));
}
if (methodRange.getLength() > 0) {
result.add(new HTMLMasonMethodReference((PerlString) element, methodRange));
}
} else // it's subcomponent or other component
{
result.add(new HTMLMasonComponentReference((PerlString) element, range));
}
return result.toArray(new PsiReference[result.size()]);
}
}
return PsiReference.EMPTY_ARRAY;
}
Aggregations