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

bogus autocomplete and index #15

Closed
dlyr opened this issue Oct 8, 2018 · 7 comments
Closed

bogus autocomplete and index #15

dlyr opened this issue Oct 8, 2018 · 7 comments

Comments

@dlyr
Copy link

dlyr commented Oct 8, 2018

Hi,
I'm trying to setup my configuration, and get some trouble with ccls+lsp+company

First test an a unique file, give completion, but when accept a completion, the text is not what expected see here:
capture d ecran de 2018-10-08 09-45-51
after selecting the first entry:
capture d ecran de 2018-10-08 09-46-05
On this simple example, vanilla company perform well.

The other problem I face is using a bigger project, ccls seems to run (as I can see from the log file), but the proposed completion are totally wrong. reference navigation seems to me ok btw.

I new to ccls and lsp, so feel free to ask any relevant information and what I should test to resolve the situation.
I'm using vanilla emacs (no spacemacs nor doom...)

@MaskRay
Copy link
Member

MaskRay commented Oct 8, 2018

Have you installed company-lsp?

(defun company-lsp--client-capabilities ()
  "Return the extra client capabilities supported by company-lsp."
  (when company-lsp-enable-snippet
    '(:textDocument (:completion (:completionItem (:snippetSupport t))))))

Can you check if M-: (lsp--client-capabilities) contains (:snippetSupport t)?

When it is true, ccls uses LSP snippets $1 $0 .... These placeholders will cause trouble if you don't configure company-lsp in company-backends. Please make sure company-lsp is the first entry or the only entry of company-backends.

Not directly related but a tip. If you want to disable snippets on ccls's side, you may customize initialization options as follows:

(setq ccls-extra-init-params '(:client (:snippetSupport :json-false)))

but the proposed completion are totally wrong

These pieces of information will be helpful: the project name (if not confidential), how you get compile_commands.json, how the completion is wrong

@dlyr
Copy link
Author

dlyr commented Oct 8, 2018

Thanks for your reply, it seems that company-lsp is installed.

company-backends is a variable defined in ‘company.el’.
Its value is (company-lsp company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
	     (company-dabbrev-code company-gtags company-etags company-keywords)
	     company-oddmuse company-dabbrev)

and

(lsp--client-capabilities)

(:workspace (:applyEdit t :executeCommand (:dynamicRegistration t)) :textDocument (:synchronization (:willSave t :didSave t :willSaveWaitUntil t) :documentSymbol (:symbolKind (:valueSet [1 2 3 4 5 6 7 8 9 10 11 12 ...]) :hierarchicalDocumentSymbolSupport t) :formatting (:dynamicRegistration t) :codeAction (:dynamicRegistration t) :completion (:completionItem (:snippetSupport t))))

For the second issue, I will wait to have this working and try to give you more informations.

@dlyr
Copy link
Author

dlyr commented Oct 8, 2018

btw

(setq ccls-extra-init-params '(:client (:snippetSupport :json-false)))

do not change the behavior

@MaskRay
Copy link
Member

MaskRay commented Oct 8, 2018

(setq ccls-extra-init-params '(:client (:snippetSupport :json-false)))

Since Sep 14, the initialization option client.snippetSupport: false will instruct ccls to disable LSP snippets in completion items. Please ensure your company-lsp emacs-ccls and ccls are up-to-date.

Can you use strace -e write -f -p $(pgrep -fn ccls) or sysdig -As9999 --unbuffered -p '%evt.time %evt.buffer' "proc.exe contains ccls and fd.type=pipe" to dump textDocument/completion responses?

{"jsonrpc":"2.0","id":11,"result":{"isIncomplete":false,"items":[{"label":"result : struct Result","kind":5,"detail":"Out_cclsInfo","sortText":"...........","filterText":"result","insertText":"result","insertTextFormat":1,"textEdit":{"range":{"start":{"line":64,"character":8},"end":{"line":64,"character":8}},"newText":"result"},"additionalTextEdits":[]}

Take a look what insertText and textEdit are. They should contain $1 style LSP snippets. company-lsp is supposed to interpret them. (setq company-backends '(company-lsp)) may also help.

@dlyr
Copy link
Author

dlyr commented Oct 8, 2018

Packages version :
company-lsp 20180917.2244 installed Company completion backend for lsp-mode.
ccls 20181007.524 installed ccls client for lsp-mode
$ git log ea8f6cb8 (HEAD -> master, origin/master, origin/HEAD) Misc

I could not install sysdig (not in debian buster repository as I write these lines ...)
So here is what I get with strace (repages without ascii code)

Content-Length: 466....{"jsonrpc":"2.0","id":6,"result":{"isIncomplete":false,"items":[{"label":"bar(int a, double b, std::string c) -> void","kind":2,"detail":"foo","sortText":"...........","insertText":"bar(${1:int a}, ${2:double b}, ${3:std::string c})$0","filterText":"bar","insertTextFormat":2},{"label":"bar2(double a, double b) -> void","kind":2,"detail":"foo","sortText":"........../","insertText":"bar2(${1:double a}, ${2:double b})$0","filterText":"bar2","insertTextFormat":2}]}}

and with (setq ccls-extra-init-params '(:client (:snippetSupport :json-false)))

Content-Length: 387....{"jsonrpc":"2.0","id":7,"result":{"isIncomplete":false,"items":[{"label":"bar(int a, double b, std::string c) -> void","kind":2,"detail":"foo","sortText":"...........","insertText":"bar(","filterText":"bar","insertTextFormat":1},{"label":"bar2(double a, double b) -> void","kind":2,"detail":"foo","sortText":"........../","insertText":"bar2(","filterText":"bar2","insertTextFormat":1}]}}

Seems coherent with what you expect right ?

But the final insertion still insert the ->void for instance. Btw the behavior is not the same when strace is running (I could not guess why), the completion is just bar( and stops.
Well I test again, and get this insertText ...

Content-Length: 453....{"jsonrpc":"2.0","id":4,"result":{"isIncomplete":false,"items":[{"label":"bar(int a, double b, std::string c) -> void","kind":2,"detail":"foo","sortText":"...........","insertText":"bar(int a, double b, std::string c) -> void","filterText":"bar","insertTextFormat":1},{"label":"bar2(double a, double b) -> void","kind":2,"detail":"foo","sortText":"........../","insertText":"bar2(double a, double b) -> void","filterText":"bar2","insertTextFormat":1}]}}    

@MaskRay
Copy link
Member

MaskRay commented Oct 9, 2018

So here is what I get with strace (repages without ascii code)

"insertText":"bar(${1:int a}, ${2:double b}, ${3:std::string c})$0"

This is expected when snippetSupport is enabled (with company-lsp installed)

and with (setq ccls-extra-init-params '(:client (:snippetSupport :json-false)))

"insertText":"bar("

This is also correct. When snippetSupport is disabled, only text before the first placeholder is inserted.

But the final insertion still insert the ->void for instance.

This is the snippetSupport: false case. It couldn't happen. Please make sure company-lsp is indeed chosen as the only company-backends item (you can add more once you get a usable configuration).

You can open company-lsp.el, and add some (message (format "+++ %s %s" label insert-text)) in (defun company-lsp--post-completion (candidate), to confirm company-lsp is used and insertText instead of label is inserted. With ccls HEAD, you should find textEdit.newText in the response.

According to https://microsoft.github.io/language-server-protocol/specification

/**
 * An edit which is applied to a document when selecting this completion. When an edit is provided the value of
 * `insertText` is ignored.
 *
 * *Note:* The range of the edit must be a single line range and it must contain the position at which completion
 * has been requested.
 */
textEdit?: TextEdit;

@dlyr
Copy link
Author

dlyr commented Oct 9, 2018

Issue solved:
I first update ccls (and then see textEdit part in company-lsp--post-completion message which was not the case before). Then I get inserted @{$1 chars instead of snippet completion

Then I install and activate yasnippet, I just don't get that I have to to get nice completion working.

I will test now the other issue I have and try to give you proper way to reproduce.
Thanks for all.
++ d

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

2 participants