joaotavora / eglot

A client for Language Server Protocol servers
GNU General Public License v3.0
2.21k stars 203 forks source link

What is the right way to use company with eglot? #122

Closed FirstLoveLife closed 5 years ago

FirstLoveLife commented 5 years ago

I noticed in README:

completionItem/resolve (works quite well with company-mode)

Doesn't require anything other than Emacs, but will automatically upgrade to work with stuff outside Emacs, like company, markdown-mode, if you happen to have these installed.

IIUC, company-mode can work fine with eglot out of box. But, unfortunately, something goes wrong with my config.

I'm using doom emacs and its default company backend is:

;;;###autoload
defvar +company-backend-alist
  '((text-mode :derived (company-dabbrev company-yasnippet company-ispell))
    (prog-mode :derived (:separate company-capf
                                    company-yasnippet
                                   ))
    (conf-mode :derived company-capf company-dabbrev-code company-yasnippet))

So, for prog-mode, the default company backend is company-capf and company-yasnippet

company-diag:

Emacs 26.1 (x86_64-pc-linux-gnu) of 2018-07-05 on juergen
Company 0.9.6

company-backends: ((:separate company-capf company-yasnippet)
 company-nand2tetris)

Used backend: (:separate company-capf company-yasnippet)

Major mode: haskell-mode
Prefix: "getL"
Completions: none

With the setting above, I cannot get completion from language server. Sometimes company-yasnippet do help me complete, but it is slow.

But if I use lsp-mode and add company-lsp to backend, then the completion works fine:

Emacs 26.1 (x86_64-pc-linux-gnu) of 2018-07-05 on juergen
Company 0.9.6

company-backends: (company-lsp
 (:separate company-capf company-yasnippet)
 company-nand2tetris)

Used backend: company-lsp
Major mode: haskell-mode
Prefix: #("getL" 0 4
  (fontified t ws-butler-chg chg))

Completions:
  #("getLine" 0 7 (lsp-completion-prefix #("getL" 0 4 (fontified t ws-butler-chg chg)) lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("insertText" "getLine ${1:IO String}" "kind" 3 "data" "getLine module:Prelude is:exact" "insertTextFormat" 2 "label" "getLine" "detail" "IO String
Prelude")))) " IO String
Prelude (Function)"

What should I do or what else can I provide? Thanks in advance

whatacold commented 5 years ago

Hi,

Since eglot adds a hook at completion-at-point-funtions to do completion, company-capf should be enough to go.

I recommend you to trigger company manually with company-begin-backend, and select company-capf as the backend. If it works, I think the problem comes from this setting (:separate company-capf company-yasnippet).

FirstLoveLife commented 5 years ago

@whatacold Thanks! The completion works fine once comment out the :separate part and use company-capf only.