use of com.intellij.openapi.vfs.VirtualFile in project intellij-leiningen-plugin by derkork.
the class LeiningenRunConfiguration method checkConfiguration.
public void checkConfiguration() throws RuntimeConfigurationException {
String wd = myRunnerParams.getWorkingDirectory();
if (wd.isEmpty()) {
throw new RuntimeConfigurationError("You need to specify a working directory.");
}
VirtualFile vf = LocalFileSystem.getInstance().findFileByPath(wd);
if (vf != null && vf.exists()) {
VirtualFile vf2 = vf.findChild(LeiningenConstants.PROJECT_CLJ);
if (vf2 == null || !vf2.isValid()) {
throw new RuntimeConfigurationError("There is no Leiningen project file in the selected working directory.");
}
} else {
throw new RuntimeConfigurationError("The selected working directory does not exist.");
}
if (myRunnerParams.getGoals().isEmpty()) {
throw new RuntimeConfigurationError("You need to specify at least one goal.");
}
}
use of com.intellij.openapi.vfs.VirtualFile in project intellij-leiningen-plugin by derkork.
the class AddManagedFilesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project ideaProject = e.getData(PlatformDataKeys.PROJECT);
final LeiningenProjectsManager manager = LeiningenProjectsManager.getInstance(ideaProject);
FileChooserDescriptor leinProjectFileDescriptor = new FileChooserDescriptor(true, false, false, false, false, true) {
@Override
public boolean isFileSelectable(VirtualFile file) {
return super.isFileSelectable(file) && !manager.isManagedFile(file);
}
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return (file.isDirectory() || LeiningenProjectsManager.isProjectFile(file)) && super.isFileVisible(file, showHiddenFiles);
}
};
VirtualFile fileToSelect = e.getData(PlatformDataKeys.VIRTUAL_FILE);
FileChooserDialog dialog = FileChooserFactory.getInstance().createFileChooser(leinProjectFileDescriptor, ideaProject, null);
VirtualFile[] files = dialog.choose(fileToSelect, ideaProject);
if (files.length == 0)
return;
for (VirtualFile file : files) {
manager.importLeiningenProject(file, ideaProject);
}
}
use of com.intellij.openapi.vfs.VirtualFile in project idea-handlebars by dmarcotte.
the class HbFormatterTest method doFormatterActionTest.
private void doFormatterActionTest(final FormatRunnableFactory formatAction, final String beforeText, String textAfter, LanguageFileType templateDataLanguageType) {
PsiFile baseFile = myFixture.configureByText("A.hbs", beforeText);
VirtualFile virtualFile = baseFile.getVirtualFile();
assert virtualFile != null;
TemplateDataLanguageMappings.getInstance(getProject()).setMapping(virtualFile, templateDataLanguageType.getLanguage());
// fetch a fresh instance of the file -- the template data mapping creates a new instance,
// which was causing problems in PsiFileImpl.isValid()
final PsiFile file = PsiManager.getInstance(getProject()).findFile(virtualFile);
assert file != null;
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(formatAction.createFormatRunnable(file));
}
}, "", "");
TemplateDataLanguageMappings.getInstance(getProject()).cleanupForNextTest();
assertEquals("Reformat Code failed", prepareText(textAfter), prepareText(file.getText()));
assertEquals("Reformat Code failed", prepareText(textAfter), prepareText(file.getText()));
}
use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.
the class ChooseTargetContributor method addPathSugestions.
public void addPathSugestions(final List<String> names, final Project project) {
String currentText = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY).getEnteredText();
// Remove the begining //
currentText = currentText.replaceFirst("^/*", "");
// check if we have as input a proper target
int currentTargetSeparatorIndex = currentText.lastIndexOf(TARGET_NAME_SEPARATOR);
if (currentTargetSeparatorIndex != -1) {
currentText = currentText.substring(0, currentText.lastIndexOf(TARGET_NAME_SEPARATOR));
}
// Try to get the relative path to the current input folder
VirtualFile baseDir = project.getBaseDir().findFileByRelativePath(currentText + "/");
if (baseDir == null) {
// Try to get the relative path to the previous input folder
if (currentText.lastIndexOf("/") != -1) {
currentText = currentText.substring(0, currentText.lastIndexOf("/"));
} else {
// Get the base path if there is no previous folder
currentText = "";
}
baseDir = project.getBaseDir().findFileByRelativePath(currentText);
// If the base dir is still null, then we have a bad relative path
if (baseDir == null) {
return;
}
}
// get the files under the base folder
VirtualFile[] files = baseDir.getChildren();
if (!currentText.isEmpty()) {
currentText += "/";
}
for (VirtualFile file : files) {
// if the file is a directory we add it to the targets
if (file.isDirectory()) {
names.add("//" + currentText + file.getName());
}
//if the file is a buck file we parse it and add its target names to the list
if (file.getName().equals("BUCK")) {
int end = currentText.length() - 1;
// Handle if the BUCK file is the main directory of the project
if (currentText.isEmpty()) {
end = 0;
}
String target = "//" + currentText.substring(0, end) + ":";
// we need the aliases now
names.addAll(BuckQueryAction.execute(project, target, new Function<List<String>, Void>() {
@Nullable
@Override
public Void apply(@Nullable List<String> strings) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
ChooseByNamePopup chooseByNamePopup = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
// the user might have closed the window
if (chooseByNamePopup != null) {
// if we don't have them, just refresh the view when we do, if the
// window is still open
chooseByNamePopup.rebuildList(true);
}
}
});
return null;
}
}));
}
}
}
use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.
the class BuckAnnotator method annotateErrors.
private void annotateErrors(PsiElement psiElement, AnnotationHolder annotationHolder) {
BuckValue value = PsiTreeUtil.getParentOfType(psiElement, BuckValue.class);
if (value == null) {
return;
}
final Project project = psiElement.getProject();
if (project == null) {
return;
}
String target = psiElement.getText();
if (target.matches("\".*\"") || target.matches("'.*'")) {
target = target.substring(1, target.length() - 1);
} else {
return;
}
if (!BuckBuildUtil.isValidAbsoluteTarget(target)) {
return;
}
VirtualFile buckDir = project.getBaseDir().findFileByRelativePath(BuckBuildUtil.extractAbsoluteTarget(target));
VirtualFile targetBuckFile = buckDir != null ? buckDir.findChild("BUCK") : null;
if (targetBuckFile == null) {
TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getEndOffset());
annotationHolder.createErrorAnnotation(range, ANNOTATOR_ERROR_CANNOT_LOCATE_TARGET);
project.getMessageBus().syncPublisher(IntellijBuckAction.EVENT).consume(this.getClass().toString());
}
}
Aggregations