use of com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl 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.impl.HTMLMasonFileImpl in project Perl5-IDEA by Camelcade.
the class HTMLMasonFileImpl method getChildComponents.
@NotNull
public List<HTMLMasonFileImpl> getChildComponents() {
final List<HTMLMasonFileImpl> result = new ArrayList<>();
VirtualFile containingFile = getComponentVirtualFile();
if (containingFile != null) {
VirtualFile componentRoot = getComponentRoot();
if (componentRoot != null) {
final String relativePath = VfsUtil.VFS_SEPARATOR_CHAR + VfsUtil.getRelativePath(containingFile, componentRoot);
final Project project = getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final HTMLMasonFileImpl currentFile = this;
HTMLMasonSettings settings = HTMLMasonSettings.getInstance(project);
// indexed children
for (String parentPath : StubIndex.getInstance().getAllKeys(HTMLMasonFlagsStubIndex.KEY, project)) {
boolean isEquals = StringUtil.equals(relativePath, parentPath);
boolean isRelative = parentPath.length() == 0 || parentPath.charAt(0) != VfsUtil.VFS_SEPARATOR_CHAR;
for (HTMLMasonFlagsStatement statement : StubIndex.getElements(HTMLMasonFlagsStubIndex.KEY, parentPath, project, scope, HTMLMasonFlagsStatement.class)) {
PsiFile file = statement.getContainingFile();
if (file instanceof HTMLMasonFileImpl) {
if (isEquals || isRelative && currentFile.equals(((HTMLMasonFileImpl) file).getParentComponent())) {
result.add((HTMLMasonFileImpl) file);
}
}
}
}
// implicit autohandled children
if (StringUtil.equals(containingFile.getName(), settings.autoHandlerName)) {
collectAuthoHandledFiles(PsiManager.getInstance(project), containingFile.getParent(), result, settings.autoHandlerName, null);
}
}
}
return result;
}
use of com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl in project Perl5-IDEA by Camelcade.
the class HTMLMasonPathsNotification method createNotificationPanel.
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull FileEditor fileEditor) {
if (file.getFileType() == HTMLMasonFileType.INSTANCE) {
String message = null;
if (HTMLMasonSettings.getInstance(myProject).getComponentsRoots().isEmpty()) {
message = "HTML::Mason components roots are not configured";
} else {
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (psiFile instanceof HTMLMasonFileImpl && ((HTMLMasonFileImpl) psiFile).getComponentRoot() == null) {
message = "Component is not under one of configured roots";
}
}
if (message != null) {
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText(message);
panel.createActionLabel("Configure", () -> Perl5SettingsConfigurable.open(myProject));
return panel;
}
}
return null;
}
use of com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl in project Perl5-IDEA by Camelcade.
the class HTMLMasonComponentReference method handleElementRename.
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
ResolveResult[] results = multiResolve(false);
String currentContent = ElementManipulators.getValueText(myElement);
if (results.length == 1 && results[0].getElement() instanceof HTMLMasonFileImpl) {
return handleFilePathChange((HTMLMasonFileImpl) results[0].getElement(), currentContent, newElementName);
} else if (HTMLMasonNamedElement.HTML_MASON_IDENTIFIER_PATTERN.matcher(newElementName).matches()) {
String newContent = newElementName + currentContent.substring(getRangeInElement().getLength());
return ElementManipulators.handleContentChange(myElement, newContent);
}
return myElement;
}
use of com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl in project Perl5-IDEA by Camelcade.
the class HTMLMasonMethodReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PerlString element = getElement();
String methodName = getRangeInElement().substring(element.getText());
if (StringUtil.isNotEmpty(methodName)) {
PsiReference[] references = element.getReferences();
if (references.length == 2) {
PsiReference componentReference = references[0];
PsiElement startComponent = componentReference.resolve();
if (startComponent instanceof HTMLMasonFileImpl) {
HTMLMasonMethodDefinition methodDefinition = ((HTMLMasonFileImpl) startComponent).findMethodDefinitionByNameInThisOrParents(methodName);
if (methodDefinition != null) {
return new ResolveResult[] { new PsiElementResolveResult(methodDefinition) };
}
}
}
}
return ResolveResult.EMPTY_ARRAY;
}
Aggregations