Search in sources :

Example 6 with Project

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BuckValue(com.facebook.buck.intellij.ideabuck.lang.psi.BuckValue) Project(com.intellij.openapi.project.Project) BuckLanguage(com.facebook.buck.intellij.ideabuck.lang.BuckLanguage)

Example 7 with Project

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) TreeNode(javax.swing.tree.TreeNode) BuckTreeNodeFileError(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeFileError) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 8 with Project

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);
}
Also used : Project(com.intellij.openapi.project.Project) BuckModule(com.facebook.buck.intellij.ideabuck.config.BuckModule) BuckBuildManager(com.facebook.buck.intellij.ideabuck.build.BuckBuildManager) BuckBuildCommandHandler(com.facebook.buck.intellij.ideabuck.build.BuckBuildCommandHandler)

Example 9 with Project

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");
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) ChooseTargetModel(com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetModel) KeyAdapter(java.awt.event.KeyAdapter) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) BuckSettingsProvider(com.facebook.buck.intellij.ideabuck.config.BuckSettingsProvider) ChooseTargetItem(com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetItem)

Example 10 with Project

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);
}
Also used : Project(com.intellij.openapi.project.Project) ScssLintInspection(com.scss.ScssLintInspection) Settings(com.scss.settings.Settings)

Aggregations

Project (com.intellij.openapi.project.Project)3623 VirtualFile (com.intellij.openapi.vfs.VirtualFile)874 NotNull (org.jetbrains.annotations.NotNull)580 Nullable (org.jetbrains.annotations.Nullable)478 Module (com.intellij.openapi.module.Module)368 PsiFile (com.intellij.psi.PsiFile)334 Editor (com.intellij.openapi.editor.Editor)301 PsiElement (com.intellij.psi.PsiElement)292 ArrayList (java.util.ArrayList)214 File (java.io.File)212 Document (com.intellij.openapi.editor.Document)180 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)172 List (java.util.List)158 IOException (java.io.IOException)107 TextRange (com.intellij.openapi.util.TextRange)99 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)96 IncorrectOperationException (com.intellij.util.IncorrectOperationException)95 Presentation (com.intellij.openapi.actionSystem.Presentation)94 DataContext (com.intellij.openapi.actionSystem.DataContext)92 PsiDirectory (com.intellij.psi.PsiDirectory)90