rust-lang / rust-lang/rust-analyzer

Messed up completions eating spaces, smeicolons etc.

Open
#20,630 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion A-macro C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer 0.3.2593-standalone

rustc version: rustc 1.88.0 (6b00bc388 2025-06-23)

editor or extension: Emacs lsp-mode

code snippet to reproduce:

use crate::backend::{Backend, BackendId};
use async_lsp::{
    lsp_types::{InitializeParams, InitializeResult, ServerCapabilities}, router::Router, LanguageServer, ResponseError
};
use futures::future::BoxFuture;
use std::{collections::HashMap, ops::ControlFlow};

pub struct Server {
    backends: HashMap<BackendId, Backend>,
}

impl Server {
    fn new() {
        let mut router = Router::from_language_server(Self { backends: HashMap::new() });
    }
}

impl LanguageServer for Server {
    typeError = ; // This is the problem
    type NotifyResult = ControlFlow<async_lsp::Result<()>>;

    fn initialize(
        &mut self,
        params: InitializeParams,
    ) -> BoxFuture<'static, Result<InitializeResult, Self::Error>> {
        Box::pin(async move {Ok(InitializeResult { capabilities: ServerCapabilities::default(), server_info: None })})
    }
}

Here are the relevant portion of the logs

{
   "label":"type Error =",
   "kind":22,
   "preselect":true,
   "sortText":"7fffffeb",
   "filterText":"type Error",
   "insertTextFormat":2,
   "textEdit":{
      "newText":"typeError = $0;",
      "insert":{
         "start":{
            "line":18,
            "character":4
         },
         "end":{
            "line":18,
            "character":6
         }
      },
      "replace":{
         "start":{
            "line":18,
            "character":4
         },
         "end":{
            "line":18,
            "character":6
         }
      }
   },
   "data":{
      "position":{
         "textDocument":{
            "uri":"file:///home/void/Projects/Rust/rmux-lsp/src/serve.rs"
         },
         "position":{
            "line":18,
            "character":6
         }
      },
      "version":4,
      "for_ref":null,
      "hash":"+E5LTI1OZRcSvGkQXcVnEW9T0tE="
   }
},

You can see that it wants to insert typeError = $0 rather than type Error =

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

Reproduce the completion in the Rust snippet using rust-analyzer 0.3.2593 with Emacs lsp-mode, then inspect the completion item and textEdit shown in the logs. Done means completion inserts type Error = without changing it to typeError = or consuming surrounding spaces and punctuation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.