rust-lang / rust-lang/rust-analyzer

More specific kind name for Code Action items

Open
#8,107 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

This is feature request.

Problem

When running Code Action, rust-analyzer returns list of actions like below:

[
  {
    "edit": {
      snip...
    },
    "kind": "quickfix",
    "title": "Import `std::io`"
  },
  {
    "edit": {
      snip...
    },
    "kind": "quickfix",
    "title": "Qualify as `std::io`"
  },
  {
    "edit": {
      snip...
    },
    "kind": "refactor.extract",
    "title": "Extract into function"
  }
]

With this list, it is not possible to filter only import fix by kind. kind is used to filter actions, but some actions have the same kind so they cannot be filtered. LSP v3.16 says:

	/**
	 * The kind of the code action.
	 *
	 * Used to filter code actions.
	 */
	kind?: CodeActionKind;

and vim-lsp's :LspCodeAction provides the way to filter actions by kind:

LspCodeAction [{CodeActionKind}]                            *:LspCodeAction*

Gets a list of possible commands that can be applied to a file so it can be
fixed (quick fix).

If the optional {CodeActionKind} specified, will invoke code action
immediately when matched code action is one only.

I want to specify more specific kind for actions, for example filtering only import actions so that I can easily run specific action for current cursor position without selecting item from list.

Solution

gopls uses kind names which can be distinguished like source.organizeImports for organizing imports.

I want to suggest more specific kind name separated by . for example:

  • quickfix.import for adding import statement
  • quickfix.qualify for completing module name qualifier

If this idea looks good, I want to try to make a PR for this issue.

Environment
  • rust-analyzer: d54e115
  • LSP client: vim-lsp
  • OS: macOS 10.15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating rust-analyzer's Code Action generation and the handling of LSP CodeAction.kind; the issue provides no file or test names. Compare the proposed quickfix.import and quickfix.qualify naming with the LSP v3.16 specification and the gopls example, then identify how filtering should distinguish these actions. Done means the relevant actions expose specific kinds and coverage verifies the resulting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.