0

Say I have a piece of code like foo.bar(), but I realize I need to change it to foo.unwrap().bar(). If I first move to the position after the dot, and start typing unwrap, I'll reach a state like foo.unw^bar() (where ^ denotes my cursor position). At this point, if I use company-complete-selection to complete unwrap, it turns into foo.unwrap(), i.e. the bar gets eaten.

Note that this "eating" gets blocked by punctuation, e.g. If I have foo..bar(), and position myself between the two dots, type unw and then complete, I get foo.unwrap^.bar(), which is what I want (^ is again cursor position).

I'm using doom emacs, writing rust code with lsp-mode and rustic-mode (and company-mode). I actually don't know if this is an issue with company, or if it's rust-specific. Maybe the rust language server (rust-analyzer) is providing company with "completions" that include eating the following word?

I haven't tested whether this type of issue applies

  • in non-rust buffers
  • in other editors using LSP with rust-analyzer
ajp
  • 1,723
  • 14
  • 22
  • 3
    I can verify that rust-analyzer on VS Code does _not_ do this. You get `foo.unwrap^bar()` and have to put the parens in yourself. – cdhowie May 09 '23 at 17:58

1 Answers1

1

The variable lsp-completion-default-behaviour controls this. You can change it to :insert instead of :replace to get that behaviour.

Rorschach
  • 31,301
  • 5
  • 78
  • 129