com.intellij.codeInsight.daemon.DaemonCodeAnalyzer Java Examples

The following examples show how to use com.intellij.codeInsight.daemon.DaemonCodeAnalyzer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeCompletionPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void apply() {

    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

    codeInsightSettings.COMPLETION_CASE_SENSITIVE = getCaseSensitiveValue();

    codeInsightSettings.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = myCbSelectByChars.isSelected();
    codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION = myCbOnCodeCompletion.isSelected();
    codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = myCbOnSmartTypeCompletion.isSelected();
    codeInsightSettings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO = myCbShowFullParameterSignatures.isSelected();

    codeInsightSettings.AUTO_POPUP_PARAMETER_INFO = myCbParameterInfoPopup.isSelected();
    codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP = myCbAutocompletion.isSelected();
    codeInsightSettings.AUTO_POPUP_JAVADOC_INFO = myCbAutopopupJavaDoc.isSelected();

    codeInsightSettings.PARAMETER_INFO_DELAY = getIntegerValue(myParameterInfoDelayField.getText(), 0);
    codeInsightSettings.JAVADOC_INFO_DELAY = getIntegerValue(myAutopopupJavaDocField.getText(), 0);

    UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = myCbSorting.isSelected();

    final Project project = DataManager.getInstance().getDataContext(myPanel).getData(CommonDataKeys.PROJECT);
    if (project != null){
      DaemonCodeAnalyzer.getInstance(project).settingsChanged();
    }
  }
 
Example #2
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void fireUpdate() {

    UISettings.getInstance().fireUISettingsChanged();
    EditorFactory.getInstance().refreshAllEditors();

    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    for (Project openProject : openProjects) {
      FileStatusManager.getInstance(openProject).fileStatusesChanged();
      DaemonCodeAnalyzer.getInstance(openProject).restart();
    }
    for (IdeFrame frame : WindowManagerEx.getInstanceEx().getAllProjectFrames()) {
      if (frame instanceof IdeFrameEx) {
        ((IdeFrameEx)frame).updateView();
      }
    }
    ActionToolbarImpl.updateAllToolbarsImmediately();
  }
 
Example #3
Source File: Communicator.java    From CppTools with Apache License 2.0 6 votes vote down vote up
public void restartServer() {
  myServerRestartCount++;
  incModificationCount();

  sendCommand(new StringCommand(QUIT_COMMAND_NAME));

  serverState = ServerState.FAILED_OR_NOT_STARTED;
  commandsToRestart.add(new RestartCommand(null) {
    public void doExecute() {
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          if (!myProject.isDisposed()) DaemonCodeAnalyzer.getInstance(myProject).restart();
        }
      });
    }
  });
}
 
Example #4
Source File: DesktopPsiAwareTextEditorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected Runnable loadEditorInBackground() {
  Runnable baseAction = super.loadEditorInBackground();
  PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);
  Document document = FileDocumentManager.getInstance().getDocument(myFile);
  CodeFoldingState foldingState = document != null && !myProject.isDefault()
                                  ? CodeFoldingManager.getInstance(myProject).buildInitialFoldings(document)
                                  : null;
  return () -> {
    baseAction.run();
    if (foldingState != null) {
      foldingState.setToEditor(getEditor());
    }
    if (psiFile != null && psiFile.isValid()) {
      DaemonCodeAnalyzer.getInstance(myProject).restart(psiFile);
    }
    EditorNotifications.getInstance(myProject).updateNotifications(myFile);
  };
}
 
Example #5
Source File: ResolveRedSymbolsAction.java    From litho with Apache License 2.0 6 votes vote down vote up
private static Map<String, List<PsiElement>> collectRedSymbols(
    PsiFile psiFile, Document document, Project project, ProgressIndicator daemonIndicator) {
  Map<String, List<PsiElement>> redSymbolToElements = new HashMap<>();
  List<HighlightInfo> infos =
      ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project))
          .runMainPasses(psiFile, document, daemonIndicator);
  for (HighlightInfo info : infos) {
    if (!info.getSeverity().equals(HighlightSeverity.ERROR)) continue;

    final String redSymbol = document.getText(new TextRange(info.startOffset, info.endOffset));
    if (!StringUtil.isJavaIdentifier(redSymbol) || !StringUtil.isCapitalized(redSymbol)) continue;

    final PsiJavaCodeReferenceElement ref =
        PsiTreeUtil.findElementOfClassAtOffset(
            psiFile, info.startOffset, PsiJavaCodeReferenceElement.class, false);
    if (ref == null) continue;

    redSymbolToElements.putIfAbsent(redSymbol, new ArrayList<>());
    redSymbolToElements.get(redSymbol).add(ref);
  }
  return redSymbolToElements;
}
 
Example #6
Source File: DuneOutputListener.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public void processTerminated(@NotNull ProcessEvent event) {
    m_compilerLifecycle.terminate();

    if (!m_bsbInfo.isEmpty()) {
        ServiceManager.getService(m_project, ErrorsManager.class).addAllInfo(m_bsbInfo);
    }

    reset();
    m_bsbInfo.clear();

    ApplicationManager.getApplication().invokeLater(() -> {
        // When a build is done, we need to refresh editors to be notified of the latest modifications
        DaemonCodeAnalyzer.getInstance(m_project).restart();
        EditorFactory.getInstance().refreshAllEditors();
        InferredTypesService.queryForSelectedTextEditor(m_project);
    });
}
 
Example #7
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Context createContext(Editor editor, int offset) {
  Project project = Objects.requireNonNull(editor.getProject());

  HighlightInfo info = null;
  if (!Registry.is("ide.disable.editor.tooltips")) {
    info = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).findHighlightByOffset(editor.getDocument(), offset, false);
  }

  PsiElement elementForQuickDoc = null;
  if (EditorSettingsExternalizable.getInstance().isShowQuickDocOnMouseOverElement()) {
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile != null) {
      elementForQuickDoc = psiFile.findElementAt(offset);
      if (elementForQuickDoc instanceof PsiWhiteSpace || elementForQuickDoc instanceof PsiPlainText) {
        elementForQuickDoc = null;
      }
    }
  }

  return info == null && elementForQuickDoc == null ? null : new Context(offset, info, elementForQuickDoc);
}
 
Example #8
Source File: OttoProjectHandler.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
private void scheduleRefreshOfEventFiles() {
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      Set<String> eventClasses;
      synchronized (allEventClasses) {
        eventClasses = new HashSet<String>(allEventClasses);
      }
      JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(myProject);
      DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject);
      for (String eventClass : eventClasses) {
        PsiClass eventPsiClass = javaPsiFacade.findClass(eventClass,
              GlobalSearchScope.allScope(myProject));
        if (eventPsiClass == null) continue;
        PsiFile psiFile = eventPsiClass.getContainingFile();
        if (psiFile == null) continue;
        codeAnalyzer.restart(psiFile);
      }
    }
  });
}
 
Example #9
Source File: GraphQLProjectConfigurable.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
public void apply() throws ConfigurationException {
    if (myForm != null) {
        if (myProject.isDefault()) {
            myForm.apply();
        } else {
            WriteAction.run(() -> {
                myForm.apply();
            });
            ApplicationManager.getApplication().invokeLater(() -> {
                if (!myProject.isDisposed()) {
                    DaemonCodeAnalyzer.getInstance(myProject).restart();
                    EditorNotifications.getInstance(myProject).updateAllNotifications();
                }
            }, myProject.getDisposed());
        }
    }
}
 
Example #10
Source File: ErrorStripeUpdateManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("WeakerAccess") // Used in Rider
protected void setOrRefreshErrorStripeRenderer(@Nonnull EditorMarkupModel editorMarkupModel, @Nullable PsiFile file) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (!editorMarkupModel.isErrorStripeVisible() || !DaemonCodeAnalyzer.getInstance(myProject).isHighlightingAvailable(file)) {
    return;
  }
  ErrorStripeRenderer renderer = editorMarkupModel.getErrorStripeRenderer();
  if (renderer instanceof TrafficLightRenderer) {
    TrafficLightRenderer tlr = (TrafficLightRenderer)renderer;
    DesktopEditorMarkupModelImpl markupModelImpl = (DesktopEditorMarkupModelImpl)editorMarkupModel;
    tlr.refresh(markupModelImpl);
    markupModelImpl.repaintTrafficLightIcon();
    if (tlr.isValid()) return;
  }
  Editor editor = editorMarkupModel.getEditor();
  if (editor.isDisposed()) return;

  editorMarkupModel.setErrorStripeRenderer(createRenderer(editor, file));
}
 
Example #11
Source File: SuppressActionFix.java    From eslint-plugin with MIT License 6 votes vote down vote up
@Override
    public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
//        final PsiFile file = element.getContainingFile();
        if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

//  InspectionManager inspectionManager = InspectionManager.getInstance(project);
//  ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(element, element, "", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);

        final JSElement property = PsiTreeUtil.getParentOfType(element, JSElement.class);
        LOG.assertTrue(property != null);
        final int start = property.getTextRange().getStartOffset();

        @NonNls final Document doc = PsiDocumentManager.getInstance(project).getDocument(file);
        LOG.assertTrue(doc != null);
        final int line = doc.getLineNumber(start);
        final int lineStart = doc.getLineStartOffset(line);

        doc.insertString(lineStart, "/*eslint " + rule + ":0*/\n");
        DaemonCodeAnalyzer.getInstance(project).restart(file);
    }
 
Example #12
Source File: SuppressLineActionFix.java    From eslint-plugin with MIT License 6 votes vote down vote up
@Override
    public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
//        final PsiFile file = element.getContainingFile();
        if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

//  InspectionManager inspectionManager = InspectionManager.getInstance(project);
//  ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(element, element, "", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);

        final JSElement property = PsiTreeUtil.getParentOfType(element, JSElement.class);
        LOG.assertTrue(property != null);
        final int start = property.getTextRange().getStartOffset();

        @NonNls final Document doc = PsiDocumentManager.getInstance(project).getDocument(file);
        LOG.assertTrue(doc != null);
        final int line = doc.getLineNumber(start);
        final int lineEnd = doc.getLineEndOffset(line);
        doc.insertString(lineEnd, " //eslint-disable-line " + rule);
        DaemonCodeAnalyzer.getInstance(project).restart(file);
    }
 
Example #13
Source File: ESLintSettingsPage.java    From eslint-plugin with MIT License 6 votes vote down vote up
protected void saveSettings() {
    Settings settings = getSettings();
    settings.pluginEnabled = pluginEnabledCheckbox.isSelected();
    settings.autoFix = autoFixCheckbox.isSelected();
    settings.reportUnused = reportUnusedCheckbox.isSelected();
    settings.eslintExecutable = eslintBinField2.getChildComponent().getText();
    settings.nodeInterpreter = nodeInterpreterField.getChildComponent().getText();
    settings.eslintRcFile = getESLintRCFile();
    settings.rulesPath = customRulesPathField.getText();
    settings.builtinRulesPath = rulesPathField.getChildComponent().getText();
    settings.treatAllEslintIssuesAsWarnings = treatAllEslintIssuesCheckBox.isSelected();
    settings.ext = textFieldExt.getText();
    if (!project.isDefault()) {
        project.getComponent(ESLintProjectComponent.class).validateSettings();
        DaemonCodeAnalyzer.getInstance(project).restart();
    }
    validate();
}
 
Example #14
Source File: StatusBarUpdater.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateStatus() {
  if (myProject.isDisposed()) {
    return;
  }

  Editor editor = FileEditorManager.getInstance(myProject).getSelectedTextEditor();
  if (editor == null || !editor.getContentComponent().hasFocus()) {
    return;
  }

  final Document document = editor.getDocument();
  if (document instanceof DocumentEx && ((DocumentEx)document).isInBulkUpdate()) return;

  int offset = editor.getCaretModel().getOffset();
  DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject);
  HighlightInfo info = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(document, offset, false, HighlightSeverity.WARNING);
  String text = info != null && info.getDescription() != null ? info.getDescription() : "";

  StatusBar statusBar = WindowManager.getInstance().getStatusBar(editor.getContentComponent(), myProject);
  if (statusBar instanceof StatusBarEx) {
    StatusBarEx barEx = (StatusBarEx)statusBar;
    if (!text.equals(barEx.getInfo())) {
      statusBar.setInfo(text, "updater");
    }
  }
}
 
Example #15
Source File: StatusBarUpdater.java    From consulo with Apache License 2.0 6 votes vote down vote up
public StatusBarUpdater(Project project) {
  myProject = project;

  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      updateLater();
    }
  });

  project.getMessageBus().connect(this).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
    @Override
    public void daemonFinished() {
      updateLater();
    }
  });
}
 
Example #16
Source File: TextEditorBackgroundHighlighter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
List<TextEditorHighlightingPass> getPasses(@Nonnull int[] passesToIgnore) {
  if (myProject.isDisposed()) return Collections.emptyList();
  LOG.assertTrue(PsiDocumentManager.getInstance(myProject).isCommitted(myDocument));
  renewFile();
  if (myFile == null) return Collections.emptyList();
  if (myCompiled) {
    passesToIgnore = EXCEPT_OVERRIDDEN;
  }
  else if (!DaemonCodeAnalyzer.getInstance(myProject).isHighlightingAvailable(myFile)) {
    return Collections.emptyList();
  }

  TextEditorHighlightingPassManager passRegistrar = TextEditorHighlightingPassManager.getInstance(myProject);

  return passRegistrar.instantiatePasses(myFile, myEditor, passesToIgnore);
}
 
Example #17
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      try {
        myProjectFixture.setUp();
        myTempDirFixture.setUp();
      }
      catch (Exception e) {
        throw new RuntimeException(e);
      }
      myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject());
      configureInspections(myInspections == null ? LocalInspectionTool.EMPTY_ARRAY : myInspections);

      DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
      daemonCodeAnalyzer.prepareForTest();

      DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
      ensureIndexesUpToDate(getProject());
      ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities(UIAccess.get());
    }
  });
}
 
Example #18
Source File: EditorTextField.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void releaseEditor(Editor editor) {
  if (editor == null) return;

  // todo IMHO this should be removed completely
  if (myProject != null && !myProject.isDisposed() && myIsViewer) {
    final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
    if (psiFile != null) {
      DaemonCodeAnalyzer.getInstance(myProject).setHighlightingEnabled(psiFile, true);
    }
  }

  remove(editor.getComponent());

  editor.getContentComponent().removeMouseListener(myProxyListeners);
  editor.getContentComponent().removeFocusListener(myProxyListeners);

  if (!editor.isDisposed()) {
    EditorFactory.getInstance().releaseEditor(editor);
  }
}
 
Example #19
Source File: LiveTemplateSettingsEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void dispose() {
  final Project project = myTemplateEditor.getProject();
  if (project != null) {
    final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(myTemplateEditor.getDocument());
    if (psiFile != null) {
      DaemonCodeAnalyzer.getInstance(project).setHighlightingEnabled(psiFile, true);
    }
  }
  EditorFactory.getInstance().releaseEditor(myTemplateEditor);
}
 
Example #20
Source File: ShowIntentionActionsHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void invoke(@Nonnull final Project project, @Nonnull Editor editor, @Nonnull PsiFile file, boolean showFeedbackOnEmptyMenu) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  if (editor instanceof EditorWindow) {
    editor = ((EditorWindow)editor).getDelegate();
    file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
  }

  final LookupEx lookup = LookupManager.getActiveLookup(editor);
  if (lookup != null) {
    lookup.showElementActions(null);
    return;
  }

  final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project);
  letAutoImportComplete(editor, file, codeAnalyzer);

  ShowIntentionsPass.IntentionsInfo intentions = ShowIntentionsPass.getActionsToShow(editor, file, true);
  IntentionsUI.getInstance(project).hide();

  if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction()) return;

  //intentions check isWritable before modification: if (!file.isWritable()) return;

  TemplateState state = TemplateManagerImpl.getTemplateState(editor);
  if (state != null && !state.isFinished()) {
    return;
  }

  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  Editor finalEditor = editor;
  PsiFile finalFile = file;
  showIntentionHint(project, finalEditor, finalFile, intentions, showFeedbackOnEmptyMenu);
}
 
Example #21
Source File: LookupImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LookupImpl(Project project, Editor editor, @Nonnull LookupArranger arranger) {
  super(new JPanel(new BorderLayout()));
  setForceShowAsPopup(true);
  setCancelOnClickOutside(false);
  setResizable(true);

  myProject = project;
  myEditor = InjectedLanguageUtil.getTopLevelEditor(editor);
  myArranger = arranger;
  myPresentableArranger = arranger;
  myEditor.getColorsScheme().getFontPreferences().copyTo(myFontPreferences);

  DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(this);

  myCellRenderer = new LookupCellRenderer(this);
  myList.setCellRenderer(myCellRenderer);

  myList.setFocusable(false);
  myList.setFixedCellWidth(50);
  myList.setBorder(null);

  // a new top level frame just got the focus. This is important to prevent screen readers
  // from announcing the title of the top level frame when the list is shown (or hidden),
  // as they usually do when a new top-level frame receives the focus.
  AccessibleContextUtil.setParent((Component)myList, myEditor.getContentComponent());

  myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myList.setBackground(LookupCellRenderer.BACKGROUND_COLOR);

  myAdComponent = new Advertiser();
  myAdComponent.setBackground(LookupCellRenderer.BACKGROUND_COLOR);

  myOffsets = new LookupOffsets(myEditor);

  final CollectionListModel<LookupElement> model = getListModel();
  addEmptyItem(model);
  updateListHeight(model);

  addListeners();
}
 
Example #22
Source File: ColorAndFontOptions.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void applyChangesToEditors() {
  EditorFactory.getInstance().refreshAllEditors();

  TodoConfiguration.getInstance().colorSettingsChanged();
  Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
  for (Project openProject : openProjects) {
    FileStatusManager.getInstance(openProject).fileStatusesChanged();
    DaemonCodeAnalyzer.getInstance(openProject).restart();
    BookmarkManager.getInstance(openProject).colorsChanged();
  }
}
 
Example #23
Source File: TogglePopupHintsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  PsiFile psiFile = getTargetFile(e.getDataContext());
  LOG.assertTrue(psiFile != null);
  Project project = e.getProject();
  LOG.assertTrue(project != null);
  DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(project);
  codeAnalyzer.setImportHintsEnabled(psiFile, !codeAnalyzer.isImportHintsEnabled(psiFile));
}
 
Example #24
Source File: ShowErrorDescriptionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void invoke(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file) {
  int offset = editor.getCaretModel().getOffset();
  DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(project);
  HighlightInfo info = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(editor.getDocument(), offset, false);
  if (info != null) {
    DaemonTooltipUtil.showInfoTooltip(info, editor, editor.getCaretModel().getOffset(), myWidth, myRequestFocus, true);
  }
}
 
Example #25
Source File: GotoNextErrorHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void showMessageWhenNoHighlights(Project project, PsiFile file, Editor editor) {
  DaemonCodeAnalyzerImpl codeHighlighter = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project);
  String message = codeHighlighter.isErrorAnalyzingFinished(file)
                   ? InspectionsBundle.message("no.errors.found.in.this.file")
                   : InspectionsBundle.message("error.analysis.is.in.progress");
  HintManager.getInstance().showInformationHint(editor, message);
}
 
Example #26
Source File: CodeInspectionOnEditorAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  final PsiFile psiFile = dataContext.getData(CommonDataKeys.PSI_FILE);
  e.getPresentation().setEnabled(project != null && psiFile != null  && DaemonCodeAnalyzer.getInstance(project).isHighlightingAvailable(psiFile));
}
 
Example #27
Source File: DisableInspectionToolAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(file.getProject());
  InspectionProfile inspectionProfile = profileManager.getInspectionProfile();
  ModifiableModel model = inspectionProfile.getModifiableModel();
  model.disableTool(myToolId, file);
  try {
    model.commit();
  }
  catch (IOException e) {
    Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
  }
  DaemonCodeAnalyzer.getInstance(project).restart();
}
 
Example #28
Source File: CodeSmellDetectorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private List<CodeSmellInfo> findCodeSmells(@Nonnull final VirtualFile file, @Nonnull final ProgressIndicator progress) {
  final List<CodeSmellInfo> result = Collections.synchronizedList(new ArrayList<CodeSmellInfo>());

  final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject);
  final ProgressIndicator daemonIndicator = new DaemonProgressIndicator();
  ((ProgressIndicatorEx)progress).addStateDelegate(new AbstractProgressIndicatorExBase() {
    @Override
    public void cancel() {
      super.cancel();
      daemonIndicator.cancel();
    }
  });
  ProgressManager.getInstance().runProcess(new Runnable() {
    @Override
    public void run() {
      DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {
        @Override
        public void run() {
          final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
          final Document document = FileDocumentManager.getInstance().getDocument(file);
          if (psiFile == null || document == null) {
            return;
          }
          List<HighlightInfo> infos = codeAnalyzer.runMainPasses(psiFile, document, daemonIndicator);
          convertErrorsAndWarnings(infos, result, document);
        }
      });
    }
  }, daemonIndicator);

  return result;
}
 
Example #29
Source File: EditorOptionDescription.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void fireUpdated() {
  Project[] projects = ProjectManager.getInstance().getOpenProjects();
  for (Project project : projects) {
    DaemonCodeAnalyzer.getInstance(project).settingsChanged();
  }

  EditorFactory.getInstance().refreshAllEditors();
}
 
Example #30
Source File: ConfigureHighlightingLevel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setSelected(@Nonnull AnActionEvent e, boolean state) {
  if (!state) return;
  PsiFile file = provider.getPsi(language);
  if (file == null) {
    return;
  }

  FileHighlightingSetting target;

  switch (level) {
    case NONE:
      target = FileHighlightingSetting.SKIP_HIGHLIGHTING;
      break;
    case ERRORS:
      target = FileHighlightingSetting.SKIP_INSPECTION;
      break;
    case ALL:
      target = FileHighlightingSetting.FORCE_HIGHLIGHTING;
      break;
    default:
      throw new UnsupportedOperationException();
  }

  HighlightLevelUtil.forceRootHighlighting(file, target);

  InjectedLanguageManager.getInstance(file.getProject()).dropFileCaches(file);
  DaemonCodeAnalyzer.getInstance(file.getProject()).restart();
}