company-lsp
company-lsp copied to clipboard
Suggested snippets for something already completed (c/c++ includes as an example)
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.
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:
- Company completes using the label, the line after company completion is
##include <...>
- Company-lsp recognized the
textEdit
value and replaced the line with#include <...>
- Because the lines before and after
textEdit
are different, self-completion is triggered - 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.
@scturtle
I do not remember being bothered with this issue. What can I do for help?
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
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.