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.
I'm able to replicate with the following minimal config:
(require 'package)
(package-initialize)
(use-package company)
(use-package yasnippet)
(use-package lsp-mode :commands lsp :hook (c-mode . lsp))
(yas-global-mode)
This only happens with some completions. 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
.
Here's the output of company-diag
in the first example:
Emacs 28.1 (aarch64-apple-darwin21.1.0) of 2022-05-11 on armbob.lan
Company 0.9.13
company-backends: (company-bbdb company-semantic company-cmake company-capf company-clang company-files
(company-dabbrev-code company-gtags company-etags company-keywords)
company-oddmuse company-dabbrev)
Used backend: company-capf
Value of c-a-p-f: (lsp-completion-at-point tags-completion-at-point-function)
Major mode: c-mode
Prefix: "retu"
Completions:
#("return expression;" 0 1 (lsp-completion-item #s(hash-table size 12 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("filterText" #("return" 0 6 (match-data (0 4 0 1 1 2 2 3 3 4))) "insertText" "return ${0:expression};" "insertTextFormat" 2 "kind" 15 "label" "return expression;" "score" 0.8373723030090332 "sortText" "40a9a1f8return" "textEdit" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("newText" "return ${0:expression};" "range" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("end" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("character" 5 "line" 1)) "start" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("character" 2 "line" 1)))))) "_emacsStartPoint" 37)) lsp-sort-text "40a9a1f8return" lsp-completion-start-point 37 lsp-completion-markers (37 #<marker (moves after insertion) at 41 in ph.c>) lsp-completion-prefix "ret" face (completions-first-difference)) 1 18 (lsp-completion-item #s(hash-table size 12 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("filterText" #("return" 0 6 (match-data (0 4 0 1 1 2 2 3 3 4))) "insertText" "return ${0:expression};" "insertTextFormat" 2 "kind" 15 "label" "return expression;" "score" 0.8373723030090332 "sortText" "40a9a1f8return" "textEdit" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("newText" "return ${0:expression};" "range" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("end" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("character" 5 "line" 1)) "start" #s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("character" 2 "line" 1)))))) "_emacsStartPoint" 37)) lsp-sort-text "40a9a1f8return" lsp-completion-start-point 37 lsp-completion-markers (37 #<marker (moves after insertion) at 41 in ph.c>) lsp-completion-prefix "ret")) " (Snippet)"