Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clangd-8 + company + flymake snippets problem #301

Closed
q3cpma opened this issue Sep 21, 2019 · 17 comments
Closed

clangd-8 + company + flymake snippets problem #301

q3cpma opened this issue Sep 21, 2019 · 17 comments

Comments

@q3cpma
Copy link

q3cpma commented Sep 21, 2019

Hello and sorry for vague title,

First, here's a video of the problem: https://files.catbox.moe/71f1jv.webm
This problem only happens with function snippets after overwriting the parameter by typing on it. The only way to describe it is that Flymake's view is desynchronized with what emacs truly has.
I had the same kind of problems with ccls and llvm-7, but it seems gone with llvm-8, so I'll be using it from now.

Here's what the prog-mode section of my config file looks like:

  ;; Completion
  (require 'company)
  (add-hook 'prog-mode-hook 'company-mode)
  (setq
   company-minimum-prefix-length 3
   company-idle-delay 0
   company-tooltip-limit 10
   company-dabbrev-downcase nil)
  ;; Eglot
  (require 'eglot)
  (add-to-list 'eglot-server-programs '((c++-mode c-mode) "ccls"))
  (add-hook 'c-mode-hook 'eglot-ensure)
  (advice-add 'eglot-eldoc-function :around
              (lambda (oldfun)
                (let ((help (help-at-pt-kbd-string)))
                  (if help (message "%s" help) (funcall oldfun)))))
  ;; Various prog-mode stuff
  (add-hook 'prog-mode-hook 'electric-pair-mode)
  (add-hook 'prog-mode-hook 'linum-mode))

And here are the eglot output buffers:
eglot-events.txt
eglot-stderr.txt

This is with emacs-26.3, eglot-20190910.1347 and company-20190907.1149

@nemethf
Copy link
Collaborator

nemethf commented Sep 27, 2019

Are you sure that the attached events buffer corresponds to the video? In the video I see a possible completion of "LOG_ALERT", but that text is missing from the events buffer. Or is it because you don't get your completions from the language server? Does the problem still exist if you disable company-clang?

@q3cpma
Copy link
Author

q3cpma commented Sep 27, 2019 via email

@q3cpma
Copy link
Author

q3cpma commented Sep 27, 2019 via email

@nemethf
Copy link
Collaborator

nemethf commented Sep 30, 2019

Hopefully, there's a solution to this problem, but first we need to understand what's going on.

Can you disable company altogether and use the built-in completion-at-point bound to C-M-i? If you get bad results with completion-at-point, try to repeat the experiment with a file containing as few lines as possible and share the events buffer.

If C-M-i works, then re-enable company with the default settings and with only one back-end (capf). Once again, if it fails, share the events buffer of a "minimal" session.

@q3cpma
Copy link
Author

q3cpma commented Sep 30, 2019

Thanks for your help. Here's the input:

int intsum(int a, int b)
{
    return a + b;
}

int main(void)
{
    ints[C-M-i here]
}

Result with clangd: intsum
Event log: https://files.catbox.moe/4etxqm.txt

Result with ccls: intsum(int a, int b) -> int
Event log: https://files.catbox.moe/1nhdia.txt

I think I should mention that I had not installed yasnippets before (but doing so didn't solve my problem).

@nemethf
Copy link
Collaborator

nemethf commented Oct 1, 2019

In both cases, the client sends (:snippetSupport :json-false), which indicates that yasnippet wasn't enabled when eglot started. The easiest way to overcome this is to execute M-x yas-global-mode RET even before you open any files.

But then I don't understand how you got snippet like behavior in your original video.

The ccls log also shows an eglot bug: it inserted "um(int a, int b) -> int" instead of "um(". Is that right?

So, can you repeat your experiment with yasnippet enabled? If that's successful, try to complicate the experiment with snippet completion inside an on-going snippet completion. If that's successful as well, then go back from M-C-i to a very simple company setup.

@q3cpma
Copy link
Author

q3cpma commented Oct 1, 2019 via email

@joaotavora
Copy link
Owner

joaotavora commented Oct 1, 2019

However, I thought eglot would automatically detect yasnippet and use it.

It does precisely this. But currently, you still must have snippet support enabled globally for the detection and auto-use to take effect. And that's what @nemethf means with M-x yas-global-mode RET.

However, that could change. I could be convinced to turn on yasnippet automatically with Eglot just as we do with Flymake. @nemethf any thoughts on this?

@nemethf
Copy link
Collaborator

nemethf commented Oct 2, 2019

With clangd I get the full prototype, intsum(int a, int b), but without the functionality allowing you to type on the parameters to erase them

This is a new bug you've just discovered (#311). Luckily, this bug doesn't affect completion with company.

With ccls Still get intsum(int a, int b) -> int.

And this one is most probably bug #279.

So, there are two ways to continue this saga. You can try to avoid #311 with having multiple completion candidates and test whether the "snippet inside snippet" case works with C-M-i and clangd. Or you can try to enable company-mode with its default settings and try to repeat your previous experiment.

In the meantime, I try to look into #279.

@nemethf
Copy link
Collaborator

nemethf commented Oct 2, 2019

However, that could change. I could be convinced to turn on yasnippet automatically with Eglot just as we do with Flymake. @nemethf any thoughts on this?

I think that will improve newcomers' initial experience. So I'm not against changing the snippet support to an opt-out feature.

@joaotavora
Copy link
Owner

support to an opt-out feature.

How exactly would one opt out? By not having the yasnippet feature? Or by yas-minor-modeing yasnippet away in the eglot-managed-mode-hook?

@q3cpma
Copy link
Author

q3cpma commented Oct 2, 2019 via email

@nemethf
Copy link
Collaborator

nemethf commented Oct 4, 2019

support to an opt-out feature.

How exactly would one opt out? By not having the yasnippet feature? Or by yas-minor-modeing yasnippet away in the eglot-managed-mode-hook?

Maybe with a new eglot-ignored-client-capabilites defcustom? I think it's important to let the users easily disable this feature. It might help them to debug a server or eglot, or they might just prefer company-clang. Just because yasnippet is installed, it doesn't mean the users want to use it with eglot. (And the same goes for flymake, probably.)

@nemethf
Copy link
Collaborator

nemethf commented Oct 4, 2019

@q3cpma your videos helped a lot. It seems you go to the next field with right-char in company-clang, but you need to press TAB to jump to the next field in yasnippet. They work differently.

Now I'm positive eglot + company-capf + yasnippets works with your last, minimal configuration if you use yasnippet in the intended way. However, you might like the company-clang style better, so it would be good if we could fix that for you. On the bright side, I start to understand your initial bug report. But I cannot dig into the details at the moment.

@q3cpma
Copy link
Author

q3cpma commented Oct 4, 2019 via email

@joaotavora
Copy link
Owner

@q3cpma your problem is most likely gone in the latest Eglot, which ensures company-clang will not unintentionally interfere with Eglot's use of company-capf.

@joaotavora
Copy link
Owner

Feel free to reopen if you think this isn't fully solved yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants