emacs-lsp / lsp-java

lsp-mode :heart: java
https://emacs-lsp.github.io/lsp-java
GNU General Public License v3.0
650 stars 90 forks source link

Company: backend company-capf error "Wrong type argument: integer-or-marker-p, nil" with args (candidates Sys) #258

Closed bbenchen closed 4 years ago

bbenchen commented 4 years ago

Describe the bug When I want to enter the System.out.println statement in the java file, when I enter Sys, the auto-complete prompt cannot be displayed, and the following error occurs:

Company: backend company-capf error "Wrong type argument: integer-or-marker-p, nil" with args (candidates Sys)

I turned on debug-on-error, After opening the Backtrace error window, it will automatically close soon, and there are no errors in the Backtrace buffer.

I executed emacs -Q and installed the latest version through melpa to test the same problem.

test project

Screenshots 89274897-24319100-d674-11ea-883e-3c30372b966a

yyoncho commented 4 years ago

Hm, this seems to be very recent regression. I am not sure how it is introduced.

CC @kiennq

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  buffer-substring-no-properties(nil 180)
  #f(compiled-function (cand) #<bytecode 0x15781a71fced>)("")
  -keep(#f(compiled-function (cand) #<bytecode 0x15781a71fced>) (#("SafeVarargs" 0 1 (sort-score 9.090909090909092e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781a2e9865> lsp-completion-start-point 179 lsp-completion-score nil) 1 11 (lsp-completion-item #<hash-table equal 10/13 0x15781a2e9865> lsp-completion-start-point 179 lsp-completion-score nil)) #("SecurityException" 0 1 (sort-score 5.882352941176471e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781b54a9f1> lsp-completion-start-point 179 lsp-completion-score nil) 1 17 (lsp-completion-item #<hash-table equal 10/13 0x15781b54a9f1> lsp-completion-start-point 179 lsp-completion-score nil)) #("SecurityManager" 0 1 (sort-score 6.666666666666667e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781b473ead> lsp-completion-start-point 179 lsp-completion-score nil) 1 15 (lsp-completion-item #<hash-table equal 10/13 0x15781b473ead> lsp-completion-start-point 179 lsp-completion-score nil)) #("Short" 0 1 (sort-score 0.0002 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781a394041> lsp-completion-start-point 179 lsp-completion-score nil) 1 5 (lsp-completion-item #<hash-table equal 10/13 0x15781a394041> lsp-completion-start-point 179 lsp-completion-score nil)) #("StackOverflowError" 0 1 (sort-score 5.555555555555555e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781a617755> lsp-completion-start-point 179 lsp-completion-score nil) 1 18 (lsp-completion-item #<hash-table equal 10/13 0x15781a617755> lsp-completion-start-point 179 lsp-completion-score nil)) #("StackTraceElement" 0 1 (sort-score 5.882352941176471e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781a36560d> lsp-completion-start-point 179 lsp-completion-score nil) 1 17 (lsp-completion-item #<hash-table equal 10/13 0x15781a36560d> lsp-completion-start-point 179 lsp-completion-score nil)) #("StrictMath" 0 1 (sort-score 0.0001 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781b356a91> lsp-completion-start-point 179 lsp-completion-score nil) 1 10 (lsp-completion-item #<hash-table equal 10/13 0x15781b356a91> lsp-completion-start-point 179 lsp-completion-score nil)) #("String" 0 1 (sort-score 0.00016666666666666666 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781a2cb691> lsp-completion-start-point 179 lsp-completion-score nil) 1 6 (lsp-completion-item #<hash-table equal 10/13 0x15781a2cb691> lsp-completion-start-point 179 lsp-completion-score nil)) #("StringBuffer" 0 1 (sort-score 8.333333333333333e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781b5e9229> lsp-completion-start-point 179 lsp-completion-score nil) 1 12 (lsp-completion-item #<hash-table equal 10/13 0x15781b5e9229> lsp-completion-start-point 179 lsp-completion-score nil)) #("StringBuilder" 0 1 (sort-score 7.692307692307693e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781bb9feb9> lsp-completion-start-point 179 lsp-completion-score nil) 1 13 (lsp-completion-item #<hash-table equal 10/13 0x15781bb9feb9> lsp-completion-start-point 179 lsp-completion-score nil)) #("StringIndexOutOfBoundsException" 0 1 (sort-score 3.2258064516129034e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781b4852f5> lsp-completion-start-point 179 lsp-completion-score nil) 1 31 (lsp-completion-item #<hash-table equal 10/13 0x15781b4852f5> lsp-completion-start-point 179 lsp-completion-score nil)) #("SuppressWarnings" 0 1 (sort-score 6.25e-05 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781a91660d> lsp-completion-start-point 179 lsp-completion-score nil) 1 16 (lsp-completion-item #<hash-table equal 10/13 0x15781a91660d> lsp-completion-start-point 179 lsp-completion-score nil)) #("System" 0 1 (sort-score 0.00016666666666666666 match-data (0 1 0 1) lsp-completion-item #<hash-table equal 10/13 0x15781b5fc4f9> lsp-completion-start-point 179 lsp-completion-score nil) 1 6 (lsp-completion-item #<hash-table equal 10/13 0x15781b5fc4f9> lsp-completion-start-point 179 lsp-completion-score nil)) "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ...))
  lsp-completion--capf-filter-candidates((#("SafeVarargs" 0 1 ... 1 11 ...) #("SecurityException" 0 1 ... 1 17 ...) #("SecurityManager" 0 1 ... 1 15 ...) #("Short" 0 1 ... 1 5 ...) #("StackOverflowError" 0 1 ... 1 18 ...) #("StackTraceElement" 0 1 ... 1 17 ...) #("StrictMath" 0 1 ... 1 10 ...) #("String" 0 1 ... 1 6 ...) #("StringBuffer" 0 1 ... 1 12 ...) #("StringBuilder" 0 1 ... 1 13 ...) #("StringIndexOutOfBoun..." 0 1 ... 1 31 ...) #("SuppressWarnings" 0 1 ... 1 16 ...) #("System" 0 1 ... 1 6 ...) "" "" "" "" "" "" "" ...) :lsp-items (#<hash-table equal 10/13 0x15781a2e9865> #<hash-table equal 10/13 0x15781b54a9f1> #<hash-table equal 10/13 0x15781b473ead> #<hash-table equal 10/13 0x15781a394041> #<hash-table equal 10/13 0x15781a617755> #<hash-table equal 10/13 0x15781a36560d> #<hash-table equal 10/13 0x15781b356a91> #<hash-table equal 10/13 0x15781a2cb691> #<hash-table equal 10/13 0x15781b5e9229> #<hash-table equal 10/13 0x15781bb9feb9> #<hash-table equal 10/13 0x15781b4852f5> #<hash-table equal 10/13 0x15781a91660d> #<hash-table equal 10/13 0x15781b5fc4f9> #<hash-table equal 10/13 0x15781a9b6345> #<hash-table equal 10/13 0x15781bac91d1> #<hash-table equal 10/13 0x15781af86281> #<hash-table equal 10/13 0x15781b7514a1> #<hash-table equal 10/13 0x15781ac21f75> #<hash-table equal 10/13 0x15781b675439> #<hash-table equal 10/13 0x15781a2b4df5> ...) :markers (179 #<marker (moves after insertion) at 180 in Boot.java>) :prefix "S")
  #f(compiled-function () #<bytecode 0x15781a910251>)()
  #f(compiled-function (probe pred action) #<bytecode 0x15781a91026d>)("S" nil t)
  all-completions("S" #f(compiled-function (probe pred action) #<bytecode 0x15781a91026d>) nil)
  completion-pcm--all-completions("" ("S" point) #f(compiled-function (probe pred action) #<bytecode 0x15781a91026d>) nil)
  completion-basic-all-completions("S" #f(compiled-function (probe pred action) #<bytecode 0x15781a91026d>) nil 1)
  #f(compiled-function (style) #<bytecode 0x15781a9102f1>)(basic)
  completion--some(#f(compiled-function (style) #<bytecode 0x15781a9102f1>) (basic partial-completion emacs22))
  completion--nth-completion(2 "S" #f(compiled-function (probe pred action) #<bytecode 0x15781a91026d>) nil 1 (metadata (category . lsp-capf) (display-sort-function . identity)))
  completion-all-completions("S" #f(compiled-function (probe pred action) #<bytecode 0x15781a91026d>) nil 1 (metadata (category . lsp-capf) (display-sort-function . identity)))
  company-capf--candidates("S")
  company-capf(candidates "S")
  apply(company-capf (candidates "S"))
  company-call-backend-raw(candidates "S")
  company--fetch-candidates("S")
  company-calculate-candidates("S" nil)
  company--begin-new()
yyoncho commented 4 years ago

The issue seems to be caused by the fact that the server is sending incorrect completion responses:

    {
      "data": {
        "uri": "file:///home/yyoncho/Sources/javademo/src/main/java/cn/foscala/Boot.java",
        "rid": "7",
        "pid": "15",
        "decl_signature": "Lakka.actor.CoordinatedShutdown$tasks$$StrictPhaseDefinition$;"
      },
      "textEdit": {
        "newText": "",
        "range": {
          "end": {
            "character": 5,
            "line": 8
          },
          "start": {
            "character": 4,
            "line": 8
          }
        }
      },
      "insertTextFormat": 2,
      "insertText": "",
      "filterText": "",
      "sortText": "999999212",
      "detail": "akka.actor.CoordinatedShutdown.tasks..StrictPhaseDefinition.",
      "kind": 7,
      "label": " - akka.actor.CoordinatedShutdown.tasks..StrictPhaseDefinition"
    },

I am investigating the vscode side.

kiennq commented 4 years ago

We can probably filter out those empty string one, or replace them with pseudo item like <empty>, WDYT?

yyoncho commented 4 years ago

We can probably filter out those empty string one, or replace them with pseudo item like <empty>, WDYT?

so atm there is no start-point for items with filterText="" - I think this is the rootcause and it throws an error. I am not sure what the correct fix is here.

Also, we should investigate the vscode part - why it works there.

kiennq commented 4 years ago

so atm there is no start-point for items with filterText="" - I think this is the root cause and it throws an error.

Actually there is start point. But attaching those information to empty string is no-op in Emacs. That's why I suggest we should probably use some pseudo item like <empty>. Note that company-mode will filter out the empty string anyway, so to allow user to really insert those item (deleting text in this case), using pseudo item seems a fit.

kiennq commented 4 years ago

We can also check for empty filterText and use label instead, but this item label looks ugly though

yyoncho commented 4 years ago

Yes. Something is wrong. I am for having a quick patch lsp-mode just to make it work, and then research what the actual issue is.

kiennq commented 4 years ago

@cxb811201, @yyoncho 1 Can you check if emacs-lsp/lsp-mode#2059 resolve your issue?

bbenchen commented 4 years ago

@kiennq It works, thanks