use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRunConfigurationProducerTest method testSameRunApplicationConfigurationOnDirectory.
public void testSameRunApplicationConfigurationOnDirectory() {
PsiFile file = myFixture.addFileToProject("import/path/a.go", "package main; func main(){}");
PsiDirectory directory = file.getParent();
assertNotNull(directory);
ConfigurationContext configurationContext = new ConfigurationContext(directory);
GoApplicationRunConfigurationProducer producer = new GoApplicationRunConfigurationProducer();
GoApplicationConfiguration runConfiguration = createRunAppPackageConfiguration("import/path");
assertTrue(producer.isConfigurationFromContext(runConfiguration, configurationContext));
runConfiguration = createRunAppPackageConfiguration("import/path/other");
assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
}
use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRunConfigurationProducerTest method testDirectory.
public void testDirectory() {
PsiFile file = myFixture.addFileToProject("import/path/a.go", "package main; func main(){}");
doTestProducedConfigurations(file.getParent());
}
use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRunConfigurationProducerTest method testSameRunApplicationConfigurationOnFile.
public void testSameRunApplicationConfigurationOnFile() {
PsiFile file = myFixture.configureByText("a.go", "package main; <caret>\nfunc main() {}");
PsiElement at = file.findElementAt(myFixture.getCaretOffset());
assertNotNull(at);
ConfigurationContext configurationContext = new ConfigurationContext(at);
GoRunFileConfigurationProducer producer = new GoRunFileConfigurationProducer();
GoRunFileConfiguration runConfiguration = createFileConfiguration(file.getVirtualFile().getPath());
assertTrue(producer.isConfigurationFromContext(runConfiguration, configurationContext));
runConfiguration = createFileConfiguration(file.getVirtualFile().getPath() + "_vl");
assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
}
use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestFunctionCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
Project project = parameters.getPosition().getProject();
PsiFile file = parameters.getOriginalFile();
PsiDirectory containingDirectory = file.getContainingDirectory();
if (file instanceof GoFile && containingDirectory != null) {
CompletionResultSet resultSet = result.withPrefixMatcher(new CamelHumpMatcher(result.getPrefixMatcher().getPrefix(), false));
Collection<String> allPackageFunctionNames = collectAllFunctionNames(containingDirectory);
Set<String> allTestFunctionNames = collectAllTestNames(allPackageFunctionNames, project, (GoFile) file);
String fileNameWithoutTestPrefix = StringUtil.trimEnd(file.getName(), GoConstants.TEST_SUFFIX_WITH_EXTENSION) + ".go";
GlobalSearchScope packageScope = GoPackageUtil.packageScope(containingDirectory, ((GoFile) file).getCanonicalPackageName());
GlobalSearchScope scope = new GoUtil.ExceptTestsScope(packageScope);
IdFilter idFilter = GoIdFilter.getFilesFilter(scope);
for (String functionName : allPackageFunctionNames) {
GoFunctionIndex.process(functionName, project, scope, idFilter, declaration -> {
addVariants(declaration, functionName, fileNameWithoutTestPrefix, allTestFunctionNames, resultSet);
return false;
});
}
Collection<String> methodKeys = ContainerUtil.newTroveSet();
StubIndex.getInstance().processAllKeys(GoMethodIndex.KEY, new CancellableCollectProcessor<>(methodKeys), scope, idFilter);
for (String key : methodKeys) {
Processor<GoMethodDeclaration> processor = declaration -> {
GoMethodDeclarationStubElementType.calcTypeText(declaration);
String typeText = key.substring(Math.min(key.indexOf('.') + 1, key.length()));
String methodName = declaration.getName();
if (methodName != null) {
if (!declaration.isPublic() || declaration.isBlank()) {
return true;
}
String lookupString = !typeText.isEmpty() ? StringUtil.capitalize(typeText) + "_" + methodName : methodName;
addVariants(declaration, lookupString, fileNameWithoutTestPrefix, allTestFunctionNames, resultSet);
}
return true;
};
GoMethodIndex.process(key, project, scope, idFilter, processor);
}
}
}
use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoFmtCheckinFactory method createHandler.
@Override
@NotNull
public CheckinHandler createHandler(@NotNull CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
return new CheckinHandler() {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
JCheckBox checkBox = new JCheckBox("Go fmt");
return new RefreshableOnComponent() {
@Override
@NotNull
public JComponent getComponent() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(checkBox, BorderLayout.WEST);
return panel;
}
@Override
public void refresh() {
}
@Override
public void saveState() {
PropertiesComponent.getInstance(panel.getProject()).setValue(GO_FMT, Boolean.toString(checkBox.isSelected()));
}
@Override
public void restoreState() {
checkBox.setSelected(enabled(panel));
}
};
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
if (enabled(panel)) {
Ref<Boolean> success = Ref.create(true);
FileDocumentManager.getInstance().saveAllDocuments();
for (PsiFile file : getPsiFiles()) {
VirtualFile virtualFile = file.getVirtualFile();
new GoFmtFileAction().doSomething(virtualFile, ModuleUtilCore.findModuleForPsiElement(file), file.getProject(), "Go fmt", true, result -> {
if (!result)
success.set(false);
});
}
if (!success.get()) {
return showErrorMessage(executor);
}
}
return super.beforeCheckin();
}
@NotNull
private ReturnResult showErrorMessage(@Nullable CommitExecutor executor) {
String[] buttons = new String[] { "&Details...", commitButtonMessage(executor, panel), CommonBundle.getCancelButtonText() };
int answer = Messages.showDialog(panel.getProject(), "<html><body>GoFmt returned non-zero code on some of the files.<br/>" + "Would you like to commit anyway?</body></html>\n", "Go Fmt", null, buttons, 0, 1, UIUtil.getWarningIcon());
if (answer == Messages.OK) {
return ReturnResult.CLOSE_WINDOW;
}
if (answer == Messages.NO) {
return ReturnResult.COMMIT;
}
return ReturnResult.CANCEL;
}
@NotNull
private List<PsiFile> getPsiFiles() {
Collection<VirtualFile> files = panel.getVirtualFiles();
List<PsiFile> psiFiles = ContainerUtil.newArrayList();
PsiManager manager = PsiManager.getInstance(panel.getProject());
for (VirtualFile file : files) {
PsiFile psiFile = manager.findFile(file);
if (psiFile instanceof GoFile) {
psiFiles.add(psiFile);
}
}
return psiFiles;
}
};
}
Aggregations