Search in sources :

Example 6 with BlazePackage

use of com.google.idea.blaze.base.lang.buildfile.search.BlazePackage in project intellij by bazelbuild.

the class LabelReference method getSkylarkExtensionLookups.

private BuildLookupElement[] getSkylarkExtensionLookups(String labelString) {
    if (!skylarkExtensionReference(myElement)) {
        return BuildLookupElement.EMPTY_ARRAY;
    }
    String packagePrefix = LabelUtils.getPackagePathComponent(labelString);
    BuildFile parentFile = myElement.getContainingFile();
    if (parentFile == null) {
        return BuildLookupElement.EMPTY_ARRAY;
    }
    BlazePackage containingPackage = BlazePackage.getContainingPackage(parentFile);
    if (containingPackage == null) {
        return BuildLookupElement.EMPTY_ARRAY;
    }
    BuildFile referencedBuildFile = LabelUtils.getReferencedBuildFile(containingPackage.buildFile, packagePrefix);
    // Directories before the colon are already covered.
    // We're only concerned with package-local directories.
    boolean hasColon = labelString.indexOf(':') != -1;
    VirtualFileFilter filter = file -> ("bzl".equals(file.getExtension()) && !file.getPath().equals(parentFile.getFilePath())) || (hasColon && file.isDirectory());
    FileLookupData lookupData = FileLookupData.packageLocalFileLookup(labelString, myElement, referencedBuildFile, filter);
    return lookupData != null ? getReferenceManager().resolvePackageLookupElements(lookupData) : BuildLookupElement.EMPTY_ARRAY;
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) ArrayUtil(com.intellij.util.ArrayUtil) IncorrectOperationException(com.intellij.util.IncorrectOperationException) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiUtils(com.google.idea.blaze.base.lang.buildfile.psi.util.PsiUtils) TextRange(com.intellij.openapi.util.TextRange) BlazePackage(com.google.idea.blaze.base.lang.buildfile.search.BlazePackage) BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) ASTNode(com.intellij.lang.ASTNode) LabelRuleLookupElement(com.google.idea.blaze.base.lang.buildfile.completion.LabelRuleLookupElement) BuildLookupElement(com.google.idea.blaze.base.lang.buildfile.completion.BuildLookupElement) PsiReferenceBase(com.intellij.psi.PsiReferenceBase) Label(com.google.idea.blaze.base.model.primitives.Label) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) BlazeFileType(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile.BlazeFileType) Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) LoadStatement(com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement) Nullable(javax.annotation.Nullable) ResolveUtil(com.google.idea.blaze.base.lang.buildfile.search.ResolveUtil) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) BlazePackage(com.google.idea.blaze.base.lang.buildfile.search.BlazePackage)

Aggregations

BlazePackage (com.google.idea.blaze.base.lang.buildfile.search.BlazePackage)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 Nullable (javax.annotation.Nullable)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)2 PsiFile (com.intellij.psi.PsiFile)2 File (java.io.File)2 BuildLookupElement (com.google.idea.blaze.base.lang.buildfile.completion.BuildLookupElement)1 LabelRuleLookupElement (com.google.idea.blaze.base.lang.buildfile.completion.LabelRuleLookupElement)1 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)1 BlazeFileType (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile.BlazeFileType)1 LoadStatement (com.google.idea.blaze.base.lang.buildfile.psi.LoadStatement)1 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)1 PsiUtils (com.google.idea.blaze.base.lang.buildfile.psi.util.PsiUtils)1 ResolveUtil (com.google.idea.blaze.base.lang.buildfile.search.ResolveUtil)1 Label (com.google.idea.blaze.base.model.primitives.Label)1 ASTNode (com.intellij.lang.ASTNode)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1