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;
}
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();
}
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;
}
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);
}
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);
}
Aggregations