emacs-lsp / emacs-ccls

Emacs client for ccls, a C/C++ language server
200 stars 29 forks source link

Using function prototypes auto-completion has strange behavior #126

Open braoult opened 3 months ago

braoult commented 3 months ago

Note: I use lsp-mode, ccls and flycheck.

Let say I have somewhere a C function int my_func(char *str, int num).

If I want to use it, I will start to type its name, let's say my_f, and I will be proposed the auto-complete choices:

my_func
my_func  (char *str, int num)

There is an issue if I select my_func (char *str, int num) ; The text is inserted in my buffer, then, after I replace the parameters with my own ones, ccls will always give errors on the line, which are very difficult to get rid of: Even If I delete function name/parameters on the line, and re-type everything completely (function and parameters), the error will not disappear. It looks like ccls keeps some wrong status. The only solution is to save then revert buffer, so that ccls "forgets" something about the inserted function declaration. Killing the line (C-a C-k) works also.

It will be clearer with an example :

  1. Initial situation. I start to type a function name line 153, some choices are proposed. step 1
  2. I select the prototype. step 2
  3. After doing it, the text is inserted, with parameters highlighted. step 3
  4. I type the letter "i", the highlighted text is replaced with "i". Note that ccls looks unhappy with "i". step 4
    1. I complete the func call with a semicolon step 5
  5. After moving the cursor we can see there are likely 2 errors step 6
  6. Showing Flycheck all errors line 153, : step 7
  7. After deleting the function call (using "DEL" from EOL to first char function), an error remain on line. step 8
  8. Remaining Flycheck error on "empty" line step 9
  9. After "C-x C-s" and "M-x revert-buffer", the error is gone step 10

Feel free to ask if you need more information/testing.