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

Post completion function is not called in some cases

Open tigersoldier opened this issue 6 years ago • 7 comments

Spin off from #39

Reported by @david:

I'm seeing a similar problem. I have this

image

and then I hit Tab, then Space, and I get this:

image

yasnippet is enabled, and all my packages are updated. I'm seeing the problem while using lsp-java, but I also tried lsp-intellij and I got the same issue.

The output from company-diag:

Emacs 25.3.1 (x86_64-apple-darwin17.4.0) of 2018-03-22 on Davids-MacBook-Pro.local
Company 0.9.6

company-backends: (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)

Used backend: company-lsp
Major mode: java-mode
Prefix: #("endpoint" 0 1
  (fontified t face font-lock-type-face)
  1 2
  (fontified t face font-lock-type-face)
  2 3
  (fontified t face font-lock-type-face)
  3 4
  (fontified t face font-lock-type-face)
  4 5
  (fontified t face font-lock-type-face)
  5 6
  (fontified t face font-lock-type-face)
  6 7
  (fontified t face font-lock-type-face)
  7 8
  (fontified t c-type c-decl-id-start face font-lock-type-face))

Completions:
  #("endpoint : String" 0 17 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "endpoint : String" "kind" 5 "detail" "ExternalAccountController" "sortText" "999999098" "insertText" "endpoint" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Lcom.example.api.externalAccount.ExternalAccountController;" "name" "endpoint" "pid" "1" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) " ExternalAccountController (Field)"
  #("Endpoint - javax.xml.ws" 0 23 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "Endpoint - javax.xml.ws" "kind" 7 "sortText" "999999308" "filterText" "Endpoint" "insertText" "Endpoint" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Ljavax.xml.ws.Endpoint;" "pid" "4" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) "  (Class)"
  #("Endpoint - javax.websocket" 0 26 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "Endpoint - javax.websocket" "kind" 7 "sortText" "999999308" "filterText" "Endpoint" "insertText" "Endpoint" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Ljavax.websocket.Endpoint;" "pid" "5" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) "  (Class)"
  #("EndpointReference - javax.xml.ws" 0 32 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "EndpointReference - javax.xml.ws" "kind" 7 "sortText" "999999372" "filterText" "EndpointReference" "insertText" "EndpointReference" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Ljavax.xml.ws.EndpointReference;" "pid" "2" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) "  (Class)"
  #("EndpointContext - javax.xml.ws" 0 30 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "EndpointContext - javax.xml.ws" "kind" 7 "sortText" "999999372" "filterText" "EndpointContext" "insertText" "EndpointContext" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Ljavax.xml.ws.EndpointContext;" "pid" "3" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) "  (Class)"
  #("EndpointConfig - javax.websocket" 0 32 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "EndpointConfig - javax.websocket" "kind" 7 "sortText" "999999372" "filterText" "EndpointConfig" "insertText" "EndpointConfig" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Ljavax.websocket.EndpointConfig;" "pid" "6" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) "  (Class)"
  #("Endpoints - org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties" 0 80 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "Endpoints - org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties" "kind" 7 "sortText" "999999372" "filterText" "Endpoints" "insertText" "Endpoints" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Lorg.springframework.boot.autoconfigure.couchbase.CouchbaseProperties$Endpoints;" "pid" "7" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) "  (Class)"
  #("EndpointPair - com.google.common.graph" 0 38 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "EndpointPair - com.google.common.graph" "kind" 7 "sortText" "999999372" "filterText" "EndpointPair" "insertText" "EndpointPair" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Lcom.google.common.graph.EndpointPair;" "pid" "8" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) "  (Class)"
  #("verifyEndpoint : String" 0 23 (lsp-completion-item #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("label" "verifyEndpoint : String" "kind" 5 "detail" "ExternalAccountController" "sortText" "999999642" "insertText" "verifyEndpoint" "data" #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ("decl_signature" "Lcom.example.api.externalAccount.ExternalAccountController;" "name" "verifyEndpoint" "pid" "0" "rid" "17" "uri" "file:///Users/david/projects/my-project/src/main/java/com/example/api/externalAccount/ExternalAccountController.java")))))) " ExternalAccountController (Field)"

tigersoldier avatar May 11 '18 01:05 tigersoldier

Based on the output of company-diag and the report from @david, company-lsp--post-completion is not run in this case:

  • The server returns candidate with label of endpoint : String and insertText of endpoint
  • On completion, company-mode inserts endpoint : String, because it's what the server wants us to display as the completion candidate
  • After company-mode inserts endpoint : String, company-lsp--post-completion should be triggered and replace endpoint : String with the content of insertText, which is endpoing
  • Because company-lsp--post-completion is not called, the original candidate, endpoint : String, remains unchanged.

@david, you mentioned this is triggered by Tab then Space. What happens if you just Enter?

tigersoldier avatar May 11 '18 01:05 tigersoldier

@tigersoldier when I press Enter the same thing happens, but the cursor is placed on another line.

david avatar May 11 '18 08:05 david

I confirm this issue still exists in the current build. Any solutions?

niwtr avatar Jun 06 '19 04:06 niwtr

This https://github.com/company-mode/company-mode/issues/891 ?

yyoncho avatar Jun 06 '19 05:06 yyoncho

I've found the exact problem for me. I personally use this gist that offers YouCompleteMe-style tab completion. This gist has an issue that it does not call post-completion right after completion. Adding a line of code

(company-call-backend 'post-completion (nth company-selection company-candidates))

solves this issue completely. So this is the modified version: https://gist.github.com/niwtr/125be33c34b25be44e444f553dab5291

@yyoncho BTW thanks for your kind help in Gitter Chat!

niwtr avatar Jun 06 '19 07:06 niwtr

Hello guys, I'm experiencing the same issue, I tried the workaround proposed by @niwtr, and indeed completions do not longer include completion metadata (such as type signatures) but while cycling completions by pressing TAB an extra closing parethensis is inserted, when finally choosing a completion this is the result I get:

Screen Shot 2019-10-20 at 14 31 57

What can I do to fix this?

That is in a Scala file, using metals as the language server and Company version: 0.9.10, Company-lsp version: 2.1.0.

zzantares avatar Oct 20 '19 19:10 zzantares

I guess you are using company-tng frontend, it is incompatible with company-lsp.

yyoncho avatar Oct 20 '19 19:10 yyoncho