Search in sources :

Example 26 with GoFile

use of com.goide.psi.GoFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoSdkUtil method findBuiltinFile.

@Nullable
public static GoFile findBuiltinFile(@NotNull PsiElement context) {
    Project project = context.getProject();
    // it's important to ask module on file, otherwise module won't be found for elements in libraries files [zolotov]
    Module moduleFromContext = ModuleUtilCore.findModuleForPsiElement(context.getContainingFile());
    if (moduleFromContext == null) {
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            if (GoSdkService.getInstance(project).isGoModule(module)) {
                moduleFromContext = module;
                break;
            }
        }
    }
    Module module = moduleFromContext;
    UserDataHolder holder = ObjectUtils.notNull(module, project);
    VirtualFile file = CachedValuesManager.getManager(context.getProject()).getCachedValue(holder, () -> {
        VirtualFile sdkSrcDir = getSdkSrcDir(project, module);
        VirtualFile result = sdkSrcDir != null ? sdkSrcDir.findFileByRelativePath(GoConstants.BUILTIN_FILE_PATH) : null;
        return CachedValueProvider.Result.create(result, getSdkAndLibrariesCacheDependencies(project, module, result));
    });
    if (file == null)
        return null;
    PsiFile psiBuiltin = context.getManager().findFile(file);
    return psiBuiltin instanceof GoFile ? (GoFile) psiBuiltin : null;
}
Also used : Project(com.intellij.openapi.project.Project) GoFile(com.goide.psi.GoFile) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) UserDataHolder(com.intellij.openapi.util.UserDataHolder) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with GoFile

use of com.goide.psi.GoFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTestFinder method findClassesForTest.

@NotNull
@Override
public Collection<PsiElement> findClassesForTest(@NotNull PsiElement element) {
    PsiFile testFile = InjectedLanguageUtil.getTopLevelFile(element);
    if (testFile instanceof GoFile) {
        PsiDirectory directory = testFile.getContainingDirectory();
        PsiFile sourceFile = directory.findFile(StringUtil.trimEnd(testFile.getName(), GoConstants.TEST_SUFFIX_WITH_EXTENSION) + EXTENSION);
        if (sourceFile != null) {
            return ContainerUtil.newSmartList(sourceFile);
        }
    }
    return Collections.emptyList();
}
Also used : GoFile(com.goide.psi.GoFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with GoFile

use of com.goide.psi.GoFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationProducerBase method getFileFromContext.

@Nullable
private static GoFile getFileFromContext(@Nullable ConfigurationContext context) {
    PsiElement contextElement = GoRunUtil.getContextElement(context);
    PsiFile psiFile = contextElement != null ? contextElement.getContainingFile() : null;
    return psiFile instanceof GoFile ? (GoFile) psiFile : null;
}
Also used : GoFile(com.goide.psi.GoFile) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with GoFile

use of com.goide.psi.GoFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPathUseScope method create.

public static GlobalSearchScope create(@NotNull PsiElement declarationContext, boolean filterByImportList) {
    if (declarationContext instanceof GoNamedElement && ((GoNamedElement) declarationContext).isBlank()) {
        return GlobalSearchScope.EMPTY_SCOPE;
    }
    PsiFile declarationPsiFile = declarationContext.getContainingFile();
    if (!(declarationPsiFile instanceof GoFile)) {
        return GlobalSearchScope.fileScope(declarationPsiFile);
    }
    if (GoPsiImplUtil.isBuiltinFile(declarationPsiFile)) {
        return GlobalSearchScope.allScope(declarationContext.getProject());
    }
    VirtualFile declarationFile = declarationPsiFile.getVirtualFile();
    if (declarationFile == null || declarationFile.getParent() == null) {
        return GlobalSearchScope.fileScope(declarationPsiFile);
    }
    return new GoPathUseScope(declarationPsiFile.getProject(), declarationFile, filterByImportList);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GoFile(com.goide.psi.GoFile) GoNamedElement(com.goide.psi.GoNamedElement) PsiFile(com.intellij.psi.PsiFile)

Example 30 with GoFile

use of com.goide.psi.GoFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoCreateFileActionTest method doTemplateTest.

private static void doTemplateTest(@NotNull PsiDirectory dir, @NotNull String newFileName, @NotNull String expectedPackage, @NotNull CustomFileTemplate template) {
    GoFile file = (GoFile) CreateFileFromTemplateAction.createFileFromTemplate(newFileName, template, dir, null, true);
    assertNotNull(file);
    assertEquals(expectedPackage, file.getPackageName());
    WriteCommandAction.runWriteCommandAction(dir.getProject(), file::delete);
}
Also used : GoFile(com.goide.psi.GoFile)

Aggregations

GoFile (com.goide.psi.GoFile)31 PsiFile (com.intellij.psi.PsiFile)20 PsiElement (com.intellij.psi.PsiElement)12 Project (com.intellij.openapi.project.Project)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiDirectory (com.intellij.psi.PsiDirectory)8 Module (com.intellij.openapi.module.Module)6 NotNull (org.jetbrains.annotations.NotNull)6 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)4 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)4 WorkspacePathResolverImpl (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl)4 Nullable (javax.annotation.Nullable)4 Test (org.junit.Test)4 GoPackageClause (com.goide.psi.GoPackageClause)3 Nullable (org.jetbrains.annotations.Nullable)3 GoFunctionDeclaration (com.goide.psi.GoFunctionDeclaration)2 GoFunctionOrMethodDeclaration (com.goide.psi.GoFunctionOrMethodDeclaration)2