use of com.intellij.openapi.project.Project in project buck by facebook.
the class BuckGotoProvider method getGotoDeclarationTarget.
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) {
if (source != null && source.getLanguage() instanceof BuckLanguage) {
// The parent type of the element must be BuckValue.
BuckValue value = PsiTreeUtil.getParentOfType(source, BuckValue.class);
if (value == null) {
return null;
}
final Project project = editor.getProject();
if (project == null) {
return null;
}
String target = source.getText();
if ((target.startsWith("'") && target.endsWith("'")) || (target.startsWith("\"") && target.endsWith("\""))) {
target = target.substring(1, target.length() - 1);
}
VirtualFile targetFile = // Try to find the BUCK file
Optional.fromNullable(BuckBuildUtil.getBuckFileFromAbsoluteTarget(project, target)).or(Optional.fromNullable(source.getContainingFile().getParent().getVirtualFile().findFileByRelativePath(target))).orNull();
if (targetFile == null) {
return null;
}
project.getMessageBus().syncPublisher(IntellijBuckAction.EVENT).consume(this.getClass().toString());
return PsiManager.getInstance(project).findFile(targetFile);
}
return null;
}
use of com.intellij.openapi.project.Project in project buck by facebook.
the class BuckToolWindowFactory method handleClickOnError.
private void handleClickOnError(BuckTreeNodeDetailError node) {
TreeNode parentNode = node.getParent();
if (parentNode instanceof BuckTreeNodeFileError) {
BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;
DataContext dataContext = DataManager.getInstance().getDataContext();
Project project = DataKeys.PROJECT.getData(dataContext);
String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");
VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1);
openFileDescriptor.navigate(true);
}
}
use of com.intellij.openapi.project.Project in project buck by facebook.
the class BuckBuildAction method executeOnPooledThread.
@Override
public void executeOnPooledThread(final AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
return;
}
BuckBuildManager buildManager = BuckBuildManager.getInstance(project);
String target = buildManager.getCurrentSavedTarget(project);
// Initiate a buck build
BuckModule buckModule = project.getComponent(BuckModule.class);
buckModule.attach(target);
if (target == null) {
buildManager.showNoTargetMessage(project);
return;
}
BuckBuildCommandHandler handler = new BuckBuildCommandHandler(project, project.getBaseDir(), BuckCommand.BUILD);
handler.command().addParameter(target);
buildManager.runBuckCommandWhileConnectedToBuck(handler, ACTION_TITLE, buckModule);
}
use of com.intellij.openapi.project.Project in project buck by facebook.
the class ChooseTargetAction method gotoActionPerformed.
@Override
protected void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return;
}
final ChooseTargetModel model = new ChooseTargetModel(project);
GotoActionCallback<String> callback = new GotoActionCallback<String>() {
@Override
public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object element) {
if (element == null) {
return;
}
BuckSettingsProvider buckSettingsProvider = BuckSettingsProvider.getInstance();
if (buckSettingsProvider == null || buckSettingsProvider.getState() == null) {
return;
}
ChooseTargetItem item = (ChooseTargetItem) element;
// if the target selected isn't an alias, then it has to have :
if (item.getName().contains("//") && !item.getName().contains(":")) {
return;
}
if (buckSettingsProvider.getState().lastAlias != null) {
buckSettingsProvider.getState().lastAlias.put(project.getBasePath(), item.getBuildTarget());
}
BuckToolWindowFactory.updateBuckToolWindowTitle(project);
}
};
showNavigationPopup(e, model, callback, "Choose Build Target", true, false);
// Add navigation listener for auto complete
final ChooseByNamePopup chooseByNamePopup = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
chooseByNamePopup.getTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_RIGHT == e.getKeyCode()) {
ChooseTargetItem obj = (ChooseTargetItem) chooseByNamePopup.getChosenElement();
if (obj != null) {
chooseByNamePopup.getTextField().setText(obj.getName());
chooseByNamePopup.getTextField().repaint();
}
} else {
super.keyPressed(e);
}
String adText = chooseByNamePopup.getAdText();
if (adText != null) {
chooseByNamePopup.setAdText(adText + " and " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 2)) + " to use autocomplete");
}
}
});
}
use of com.intellij.openapi.project.Project in project scss-lint-plugin by idok.
the class ScssLintTest method doTest.
private void doTest(final String file) {
Project project = myFixture.getProject();
Settings settings = Settings.getInstance(project);
// settings.scssLintExecutable = ScssLintRunnerTest.SCSS_LINT_BIN;
// settings.scssLintConfigFile = getTestDataPath() + "/.eslintrc";
// settings.nodeInterpreter = ScssLintRunnerTest.SCSS_EXE;
// settings.rulesPath = "";
settings.pluginEnabled = true;
myFixture.configureByFile(file);
myFixture.enableInspections(new ScssLintInspection());
myFixture.checkHighlighting(true, false, true);
}
Aggregations