company-lsp icon indicating copy to clipboard operation
company-lsp copied to clipboard

Suggested snippets for something already completed (c/c++ includes as an example)

Open hicksy994 opened this issue 6 years ago • 5 comments

As referenced at the bottom of this thread (there are also unrelated topics):

https://github.com/cquery-project/cquery/issues/401

If you complete an include header in c/c++, company-lsp seems to suggest a snippet for what you've just done.

hicksy994 avatar Feb 02 '18 22:02 hicksy994

This is caused by #20. The reason why it is triggering self completion incorrectly is that company-lspthinks the prefix for #includestatements does not contain#, while cquery treats #` as part of the prefix.

The results of this is:

  1. Company completes using the label, the line after company completion is ##include <...>
  2. Company-lsp recognized the textEdit value and replaced the line with #include <...>
  3. Because the lines before and after textEdit are different, self-completion is triggered
  4. cquery sends completion for the same header file.

@Sarcasm I'll use the completion suffix to detect if self-completion should be triggered. The current logic not only causes issue with cquery, but also java auto-import.

tigersoldier avatar Feb 03 '18 21:02 tigersoldier

@scturtle

MaskRay avatar Feb 18 '18 23:02 MaskRay

I do not remember being bothered with this issue. What can I do for help?

scturtle avatar Feb 19 '18 06:02 scturtle

I should have updated this issue. The issue is now mitigated by #22. I kept this issue open because the root cause is lsp-mode/company-lsp and cquery has different view of the completion prefix. If a user completes at this point:

#include|

where | denotes the cursor, or (point) in Emacs, cquery sees #include as the prefix, while lsp-mode and company-lsp sees include as the prefix.

The result is, all candidates returned by cquery are prefixed with #, which don't match the company-lsp prefix. When a candidate is chosen, it replaces the company-lsp prefix, resulting two leading # characters.

Users don't see two leading # characters because both company-lsp and cquery support textEdit. By applying textEdit, the content is fixed and both the editor and the server share the same view of content. However, for clients that don't support textEdit, the two leading #s are visible to users. This can be verified by using the plain complete-at-point command to complete right after # in Emacs.

The best solution is allowing clients to define their own functions to get the prefix bounds. This requires fundamental changes to lsp-mode. I have a PR for lsp-mode to enable this: emacs-lsp/lsp-mode#281

tigersoldier avatar Feb 19 '18 07:02 tigersoldier

Is there an update on this? lsp-mode has that PR merged to master, and I believe I am up to date with all components of lsp and cquery, but I face the same issue(https://github.com/cquery-project/cquery/issues/401).

Edit: To add to this, all candidates are not just prefixed with "#" but "#include <" for me, all of the string being redundant since that was the triggering prefix.

sachdevaprash avatar Nov 08 '18 19:11 sachdevaprash