Skip to content

Support LSP quick fixes and intention actions on non-project files by implementing DumbAware on LSPLazyCodeActionIntentionAction #1668

Closed

Description

@SergejSalnikov

Summary

LSP4IJ already supports diagnostics, folding, code lenses, documentation, and document links on non-project files (files outside content roots) by marking their respective passes/providers as DumbAware (LSPDiagnosticsPassFactory, LSPFoldingRangeBuilder, LSPCodeLensProvider, LSPDocumentationTargetProvider, LSPDocumentLinkPass).

However, LSP quick fixes (LSPQuickFixIntentionAction) and intention actions (LSPIntentionAction0..19) do not work on non-project files because their base class LSPLazyCodeActionIntentionAction does not implement com.intellij.openapi.project.DumbAware.

Root Cause

In IntelliJ Platform, both the intention popup (Alt+Enter via ShowIntentionsPass#addAvailableFixesForGroups and ShowIntentionsPass#getRegisteredIntentionActions) and the hover tooltip quick-fix button (DaemonTooltipActionProviderKt#extractMostPriorityFixFromHighlightInfo / DaemonTooltipAction#execute -> findIntention) filter actions using DumbService#isUsableInCurrentContext(Object thing, VirtualFile file):

fun isUsableInCurrentContext(thing: Any, file: VirtualFile?) : Boolean {
  if (file == null || !file.isInLocalFileSystem) return isUsableInCurrentContext(thing)
  return (!isDumb && FileIndexFacade.getInstance(project).isIndexable(file)) || isDumbAware(thing, project is LightEditCompatible)
}

For a non-project file (a file outside the project's content roots/libraries), FileIndexFacade.getInstance(project).isIndexable(file) returns false even when the IDE is in Smart Mode (!isDumb == true).

Because (!isDumb && isIndexable(file)) evaluates to false, IntelliJ requires isDumbAware(thing) to be true:

  • Prior to IntelliJ 2026.2 (IJPL-254242), extractMostPriorityFixFromHighlightInfo missed the isUsableInCurrentContext check, so LSP quick fixes were shown in hover tooltips on non-project files, but clicking them silently failed inside DaemonTooltipAction#execute -> findIntention (which called ShowIntentionsPass#getAvailableFixes -> isUsableInCurrentContext -> false).
  • In newer IntelliJ builds where extractMostPriorityFixFromHighlightInfo also checks isUsableInCurrentContext, non-DumbAware quick fixes and intentions are completely hidden on non-project files in both tooltips and Alt+Enter.

Proposed Solution

  1. Implement DumbAware on LSPLazyCodeActionIntentionAction:
    Since external language servers operate out-of-process and do not rely on IntelliJ's PSI indexes, LSPLazyCodeActionIntentionAction should implement DumbAware.

    • Note: For LSPIntentionAction0..19 registered via <intentionAction> in plugin.xml, IntelliJ wraps them in IntentionActionWrapper which implements IntentionActionDelegate (PossiblyDumbAware) and delegates isDumbAware() to DumbService.isDumbAware(getDelegate()). Thus, marking LSPLazyCodeActionIntentionAction as DumbAware automatically makes both LSPQuickFixIntentionAction and LSPIntentionAction0..19 dumb-aware.
  2. Guard against actual project indexing in LSPLazyCodeActionIntentionAction#isAvailable:
    LSPIntentionAction#isAvailable already checks ProjectIndexingManager.canExecuteLSPFeature(file) != ExecuteLSPFeatureStatus.NOW to avoid triggering LSP requests while the project is actually indexing (scanning || dumbIndexing || DumbService.isDumb(project)). Moving this check up to LSPLazyCodeActionIntentionAction#isAvailable ensures that LSPQuickFixIntentionAction is also guarded during actual indexing while still returning true (ExecuteLSPFeatureStatus.NOW) for non-project files in Smart Mode:

// In com.redhat.devtools.lsp4ij.features.codeAction.LSPLazyCodeActionIntentionAction
public class LSPLazyCodeActionIntentionAction implements IntentionAction, DumbAware {
    ...
    @Override
    public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
        if (ProjectIndexingManager.canExecuteLSPFeature(file) != ExecuteLSPFeatureStatus.NOW) {
            return false;
        }
        loadCodeActionIfNeeded();
        return isValidCodeAction(this.action);
    }
  1. (Optional) Ensure write access for multi-file WorkspaceEdits on non-project files:
    For the currently active PsiFile, ShowIntentionActionsHandler#invokeIntention automatically calls FileModificationService.getInstance().preparePsiElementsForWrite(...) (triggering IntelliJ's standard "Non-Project Files Protection" unlock dialog before invoke() runs). However, if a WorkspaceEdit modifies secondary non-project files, LSPIJUtils#applyWorkspaceEdit should call FileModificationService.getInstance().prepareVirtualFilesForWrite(project, affectedFiles) (or ReadonlyStatusHandler.ensureFilesWritable(...)) before modifying documents.

Activity

  1. lagergren commented on Nov 9, 2026

    @lagergren
    Collaborator

    The cause, checked in the IntelliJ sources and with LSP4IJ's tests: since IntelliJ 2025.3, ShowIntentionsPass.getRegisteredIntentionActions offers a registered intention only if DumbService.isUsableInCurrentContext(action, file), which for a file on the local file system is (!isDumb && FileIndexFacade.isIndexable(file)) || isDumbAware(action). A file outside the project's content isn't indexable, so LSP4IJ's intentions (LSPIntentionAction0…, which aren't DumbAware) aren't offered there, even when nothing is being indexed. 2025.2 and earlier have only isUsableInCurrentContext(thing), which looks at dumb mode alone.

    LSP4IJ's own ResolvedCodeActionTest shows it: its fixture's file is outside the project's content, and on 2025.3 and 2026.3 getAvailableIntentions() is empty, so both of its tests fail, while they pass on 2024.2, which CI builds against. So the intentions are missing in non-project files for everyone on IntelliJ 2025.3 and later. #1681 makes them DumbAware, which is what that check asks for. Found while looking into building against 2026.x (#1908).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions