Search in sources :

Example 1 with HTMLMasonSettings

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings 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 2 with HTMLMasonSettings

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.

the class HTMLMasonParserTest method addCustomTag.

private void addCustomTag(String text, HTMLMasonCustomTagRole role) {
    HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
    settings.customTags.add(new HTMLMasonCustomTag(text, role));
    settings.settingsUpdated();
}
Also used : HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) HTMLMasonCustomTag(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag)

Example 3 with HTMLMasonSettings

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.

the class HTMLMasonArgsDefVariablesResolveTest method doTestResolve.

@Override
public void doTestResolve() {
    HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
    settings.globalVariables.add(new VariableDescription("$product", "Foo::Bar"));
    settings.settingsUpdated();
    super.doTestResolve();
}
Also used : VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription) HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings)

Example 4 with HTMLMasonSettings

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.

the class HTMLMasonComponentReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    List<ResolveResult> result = null;
    // looking subcomponents
    String nameOrPath = getRangeInElement().substring(getElement().getText());
    final PsiFile file = getElement().getContainingFile();
    if (file instanceof HTMLMasonFileImpl) {
        for (HTMLMasonCompositeElement subcomponentDefitnition : ((HTMLMasonFileImpl) file).getSubComponentsDefinitions()) {
            assert subcomponentDefitnition instanceof HTMLMasonSubcomponentDefitnition;
            if (StringUtil.equals(((HTMLMasonSubcomponentDefitnition) subcomponentDefitnition).getName(), nameOrPath)) {
                if (result == null) {
                    result = new ArrayList<>();
                }
                result.add(new PsiElementResolveResult(subcomponentDefitnition));
            }
        }
    }
    // looking components
    if (result == null) {
        final Project project = file.getProject();
        VirtualFile componentVirtualFile = null;
        if (StringUtil.startsWith(nameOrPath, "/")) {
            HTMLMasonSettings settings = HTMLMasonSettings.getInstance(project);
            for (VirtualFile componentRoot : settings.getComponentsRoots()) {
                componentVirtualFile = componentRoot.findFileByRelativePath(nameOrPath);
                if (componentVirtualFile != null) {
                    break;
                }
            }
        } else // possible relative path
        {
            VirtualFile containingFile = file.getVirtualFile();
            if (containingFile != null) {
                VirtualFile containingDir = containingFile.getParent();
                componentVirtualFile = containingDir.findFileByRelativePath(nameOrPath);
            }
        }
        if (componentVirtualFile != null) {
            PsiFile componentFile = PsiManager.getInstance(project).findFile(componentVirtualFile);
            if (componentFile instanceof HTMLMasonFileImpl) {
                result = new ArrayList<>();
                result.add(new PsiElementResolveResult(componentFile));
            }
        }
    }
    return result == null ? ResolveResult.EMPTY_ARRAY : result.toArray(new ResolveResult[result.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) HTMLMasonFileImpl(com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl) HTMLMasonCompositeElement(com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement) HTMLMasonSubcomponentDefitnition(com.perl5.lang.htmlmason.parser.psi.HTMLMasonSubcomponentDefitnition) PerlString(com.perl5.lang.perl.psi.PerlString) HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with HTMLMasonSettings

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings in project Perl5-IDEA by Camelcade.

the class HTMLMasonFileImpl method getParentComponent.

@Nullable
public HTMLMasonFileImpl getParentComponent() {
    String parentComponentPath = getParentComponentPath();
    HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
    VirtualFile parentFile = null;
    if (// autohandler
    parentComponentPath == null) {
        VirtualFile containingFile = getComponentVirtualFile();
        if (containingFile != null) {
            VirtualFile startDir = containingFile.getParent();
            if (StringUtil.equals(containingFile.getName(), settings.autoHandlerName)) {
                startDir = startDir.getParent();
            }
            VirtualFile componentRoot = HTMLMasonUtil.getComponentRoot(getProject(), startDir);
            if (componentRoot != null) {
                while (VfsUtil.isAncestor(componentRoot, startDir, false)) {
                    if ((parentFile = startDir.findFileByRelativePath(settings.autoHandlerName)) != null) {
                        break;
                    }
                    startDir = startDir.getParent();
                }
            }
        }
    } else if (// Specific component
    !StringUtil.equals(parentComponentPath, HTMLMasonFlagsStatement.UNDEF_RESULT)) {
        if (// absolute path
        StringUtil.startsWith(parentComponentPath, "/")) {
            parentComponentPath = parentComponentPath.substring(1);
            for (VirtualFile root : settings.getComponentsRoots()) {
                if ((parentFile = root.findFileByRelativePath(parentComponentPath)) != null) {
                    break;
                }
            }
        } else // relative path
        {
            VirtualFile containingVirtualFile = getComponentVirtualFile();
            if (containingVirtualFile != null) {
                VirtualFile containingDir = containingVirtualFile.getParent();
                if (containingDir != null) {
                    parentFile = containingDir.findFileByRelativePath(parentComponentPath);
                }
            }
        }
    }
    if (parentFile != null) {
        PsiFile file = PsiManager.getInstance(getProject()).findFile(parentFile);
        if (file instanceof HTMLMasonFileImpl) {
            return (HTMLMasonFileImpl) file;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HTMLMasonSettings (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 Project (com.intellij.openapi.project.Project)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 HTMLMasonFileViewProviderFactory (com.perl5.lang.htmlmason.HTMLMasonFileViewProviderFactory)1 HTMLMasonCustomTag (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag)1 HTMLMasonCompositeElement (com.perl5.lang.htmlmason.parser.psi.HTMLMasonCompositeElement)1 HTMLMasonSubcomponentDefitnition (com.perl5.lang.htmlmason.parser.psi.HTMLMasonSubcomponentDefitnition)1 HTMLMasonFileImpl (com.perl5.lang.htmlmason.parser.psi.impl.HTMLMasonFileImpl)1 VariableDescription (com.perl5.lang.mason2.idea.configuration.VariableDescription)1 PerlString (com.perl5.lang.perl.psi.PerlString)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1