lsp-mode icon indicating copy to clipboard operation
lsp-mode copied to clipboard

During some completions, placeholder text does not get replaced.

Open ruds opened this issue 2 years ago • 1 comments

Thank you for the bug report

  • [X] I am using the latest version of lsp-mode related packages.
  • [X] I checked FAQ and Troubleshooting sections
  • [X] You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

In a buffer in c-mode with the following content (with point after retu), pressing enter completes to return expression;.

int main(int argc, char** argv) {
  retu
}

Point is now at the beginning of expression, but starting to type doesn't replace the placeholder text; instead it inserts new text before it.

Steps to reproduce

  1. Run emacs -q -l /tmp/lsp-start-plain.el
  2. Create a buffer in c-mode with the contents
int main(int argc, char**argv) {

}
  1. On the second line, type retu.
  2. Wait for the completion suggestion to come up and type RET.
  3. Start typing an expression.

Expected behavior

I expect that the placeholder text expression is replaced by whatever I start typing, but instead what I type is inserted before expression.

Which Language Server did you use?

clangd

OS

MacOS

Error callstack

No response

Anything else?

Some completions do not have this issue. For example, in

int foo(int bar) { return bar; }

int main(int argc, char** argv) {
  return foo
}

I can press enter when point is after foo to complete to foo(int bar), and in that case typing replaces the placeholder int bar as expected.

ruds avatar Aug 07 '22 22:08 ruds

This seems to be a problem with yasnippet instead. You can try

(defun test-a ()
  (interactive)
  (yas-expand-snippet "return ${0:expression};"))

(defun test-b ()
  (interactive)
  (yas-expand-snippet "return ${1:expression};"))

Using M-x test-a will behave as you described, whereas using M-x test-b will behave as you desired. Even though $0 is used as cursor position, I guess we still should replace the text inside it as well. Please open an issue in yasnippet repo instead.

kiennq avatar Aug 07 '22 22:08 kiennq