Search in sources :

Example 1 with HTMLMasonFileImpl

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;
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString) HTMLMasonMethodReference(com.perl5.lang.htmlmason.parser.psi.references.HTMLMasonMethodReference) PsiReference(com.intellij.psi.PsiReference) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) PerlString(com.perl5.lang.perl.psi.PerlString) PsiElement(com.intellij.psi.PsiElement)

Example 2 with HTMLMasonFileImpl

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with HTMLMasonFileImpl

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;
}
Also used : HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with HTMLMasonFileImpl

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;
}
Also used : HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString)

Example 5 with HTMLMasonFileImpl

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;
}
Also used : HTMLMasonMethodDefinition(com.perl5.lang.htmlmason.parser.psi.HTMLMasonMethodDefinition) HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString) PerlString(com.perl5.lang.perl.psi.PerlString) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HTMLMasonFileImpl (com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl)11 PerlString (com.perl5.lang.perl.psi.PerlString)6 PsiElement (com.intellij.psi.PsiElement)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Project (com.intellij.openapi.project.Project)3 PsiFile (com.intellij.psi.PsiFile)3 HTMLMasonSettings (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 HTMLMasonMethodDefinition (com.perl5.lang.htmlmason.parser.psi.HTMLMasonMethodDefinition)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 NavigationGutterIconBuilder (com.intellij.codeInsight.navigation.NavigationGutterIconBuilder)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiReference (com.intellij.psi.PsiReference)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)1 HTMLMasonCompositeElement (com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement)1 HTMLMasonSubcomponentDefitnition (com.perl5.lang.htmlmason.parser.psi.HTMLMasonSubcomponentDefitnition)1 HTMLMasonMethodReference (com.perl5.lang.htmlmason.parser.psi.references.HTMLMasonMethodReference)1