Skip to content

🐛 LSP organizeImports code action is filtered out in 2.4.10 #9741

@qq8721443

Description

@qq8721443

Environment information

Details
CLI:
  Version:                      2.4.10
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_PATH:                    unset
  BIOME_LOG_PREFIX_NAME:             unset
  BIOME_LOG_LEVEL:                   unset
  BIOME_LOG_KIND:                    unset
  BIOME_CONFIG_PATH:                 unset
  BIOME_THREADS:                     unset
  BIOME_WATCHER_KIND:                unset
  BIOME_WATCHER_POLLING_INTERVAL:    unset
  NO_COLOR:                     unset
  TERM:                         xterm-256color
  JS_RUNTIME_VERSION:           v24.11.1
  JS_RUNTIME_NAME:              node
  NODE_PACKAGE_MANAGER:         pnpm/10.32.1

Biome Configuration:
  Status:                       Loaded successfully
  Path:                         biome.json
  Formatter enabled:            true
  Linter enabled:               true
  Assist enabled:               true
  VCS enabled:                  true
  HTML full support enabled:    unset

Workspace:
  Open Documents:               0

What happened?

After updating to version 2.4.10, organizeImports no longer works in my IDE. (2.4.9 works well)
I'm using Zed IDE, I think I set properly.

settings:

  • biome.json
{
  "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true
    }
  },
  "assist": {
    "actions": {
      "source": {
        "organizeImports": "on"
      }
    }
  }
}
  • .zed/settings.json
{
  "code_actions_on_format": {
    "source.organizeImports.biome": true,
  },
  "format_on_save": "on",
}

I created a small reproduction repository using npm create @biomejs/biome-reproduction.

In src/index.ts file inside reproduction repository, I press Cmd+S, I expect the import order to be organized, but no changes are applied.

Below are the LSP logs from Zed. The server returns only an empty array, so I believe the IDE has no code action to apply and therefore does nothing.

// Send:
{"jsonrpc":"2.0","id":134,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/hongjeong-gi/Documents/projects/oss/biome-repro-1774939551635/src/index.ts"},"range":{"start":{"line":0,"character":0},"end":{"line":13,"character":0}},"context":{"diagnostics":[{"range":{"start":{"line":8,"character":0},"end":{"line":8,"character":24}},"severity":3,"code":"assist/source/organizeImports","source":"biome","message":"The imports and exports are not sorted."}],"only":["source.organizeImports.biome"]}}}

// Receive:
{"jsonrpc":"2.0","result":[],"id":134}

I took a quick look through the code to understand the cause, and it seems like the issue happens when actions are filtered inside the code_actions function.

let matches_filters = filters.iter().any(|filter| action.category.matches(filter));

if !filters.is_empty() && !matches_filters {
    return None;
}

filters is passed in as ["source.organizeImports.biome"], but action.category seems to become "source.biome.organizeImports" during filtering, so it does not match correctly. My guess is that this mismatch is what causes the problem. I think action_category fn seems the cause, but I'm new to Rust and this project's codebase..😊

pub fn action_category(&self, category: RuleCategory, group: &'static str) -> ActionCategory {
    match category {
        RuleCategory::Lint => {
            ActionCategory::QuickFix(Cow::Owned(format!("{}.{}", group, self.name)))
        }
        RuleCategory::Action => {
            ActionCategory::Source(SourceActionKind::Other(Cow::Borrowed(self.name)))
        }
        RuleCategory::Syntax | RuleCategory::Transformation => unimplemented!(""),
    }
}

Always thanks for this awesome project.

Expected result

import order should be organized.

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-Needs reproStatus: needs a reproduction

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions