use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoAutoImportInsertHandler method autoImport.
private static void autoImport(@NotNull InsertionContext context, @NotNull GoNamedElement element) {
PsiFile file = context.getFile();
boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(ModuleUtilCore.findModuleForPsiElement(file));
String importPath = element.getContainingFile().getImportPath(vendoringEnabled);
if (StringUtil.isEmpty(importPath))
return;
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument());
PsiReference reference = file.findReferenceAt(context.getStartOffset());
if (reference != null) {
PsiElement referenceElement = reference.getElement();
GoImportPackageQuickFix fix = new GoImportPackageQuickFix(referenceElement, importPath);
fix.invoke(context.getProject(), file, context.getEditor(), referenceElement, referenceElement);
}
}
use of com.intellij.psi.PsiFile in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiFile file = parameters.getOriginalFile();
ASTNode node = position.getNode();
if (file instanceof GoFile && position.getParent() instanceof GoPackageClause && node.getElementType() == GoTypes.IDENTIFIER) {
boolean isTestFile = GoTestFinder.isTestFile(file);
PsiDirectory directory = file.getParent();
String currentPackageName = ((GoFile) file).getPackageName();
Collection<String> packagesInDirectory = GoPackageUtil.getAllPackagesInDirectory(directory, null, true);
for (String packageName : packagesInDirectory) {
if (!packageName.equals(currentPackageName)) {
result.addElement(packageLookup(packageName, GoCompletionUtil.PACKAGE_PRIORITY - 1));
}
if (isTestFile) {
result.addElement(packageLookup(packageName + GoConstants.TEST_SUFFIX, GoCompletionUtil.PACKAGE_PRIORITY));
}
}
if (directory != null && ContainerUtil.filter(directory.getFiles(), Conditions.instanceOf(GoFile.class)).size() == 1) {
String packageFromDirectory = GoPsiImplUtil.getLocalPackageName(directory.getName());
if (!packageFromDirectory.isEmpty()) {
result.addElement(packageLookup(packageFromDirectory, GoCompletionUtil.PACKAGE_PRIORITY - 1));
}
}
result.addElement(packageLookup(GoConstants.MAIN, GoCompletionUtil.PACKAGE_PRIORITY - 2));
}
super.fillCompletionVariants(parameters, result);
}
use of com.intellij.psi.PsiFile in project freeline by alibaba.
the class UsingReportAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = event.getProject();
Module[] modules = ModuleManager.getInstance(project).getModules();
List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
for (Module module : modules) {
GradleBuildFile file = GradleBuildFile.get(module);
if (file != null && !GradleUtil.isLibrary(file)) {
selectModulesList.add(Pair.create(module, file.getPsiFile()));
}
}
if (selectModulesList.size() > 1) {
final DialogBuilder builder = new DialogBuilder();
builder.setTitle("Freeline Reporter");
builder.resizable(false);
builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the exact one.", Messages.getInformationIcon(), SwingConstants.CENTER));
builder.addOkAction().setText("Cancel");
for (final Pair<Module, PsiFile> pair : selectModulesList) {
builder.addAction(new AbstractAction(":" + pair.first.getName()) {
@Override
public void actionPerformed(ActionEvent e) {
builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
report(project, pair.getSecond());
}
});
}
if (builder.show() > -1) {
//return false;
}
} else if (selectModulesList.size() == 1) {
report(project, selectModulesList.get(0).getSecond());
}
}
use of com.intellij.psi.PsiFile in project idea-handlebars by dmarcotte.
the class HbStructureViewFactory method getStructureViewBuilder.
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
return new TemplateLanguageStructureViewBuilder(psiFile) {
@Override
protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, PsiFile mainFile) {
if (!psiFile.isValid())
return null;
final StructureViewBuilder builder = new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new HbStructureViewModel((HbPsiFile) psiFile, editor);
}
};
StructureView structureView = builder.createStructureView(fileEditor, psiFile.getProject());
return new StructureViewComposite.StructureViewDescriptor(HbLanguage.INSTANCE.getDisplayName(), structureView, HbFileType.INSTANCE.getIcon());
}
};
}
use of com.intellij.psi.PsiFile in project idea-handlebars by dmarcotte.
the class HbsEmmetTest method testSimpleTagsWithHtmlSubstitutor.
public void testSimpleTagsWithHtmlSubstitutor() {
HbTestUtils.setOpenHtmlAsHandlebars(true, getProject(), getTestRootDisposable());
final PsiFile file = myFixture.configureByText("test.html", "div>span<caret>");
assertInstanceOf(file, HbPsiFile.class);
TemplateManager.getInstance(getProject()).startTemplate(myFixture.getEditor(), TemplateSettings.TAB_CHAR);
myFixture.checkResult("<div><span></span></div>");
}
Aggregations