coc-java: Incorrect parameter completion

Versions

vim version: NVIM v0.4.3                                                                                                                                                                                                                                      
node version: v10.16.0
coc.nvim version: 0.0.74-15f685206a                                                                                                                                                                                                                         
term: xterm-256color                                                                                                                                                                                                                                        
platform: linux 

Messages

[coc.nvim] Using java from /usr/lib/jvm/java-8-openjdk-amd64, version: 8                                                           
[coc.nvim] JDT Language Server starting at /home/user/Testing/Nvim/Vanilla                                                             
[coc.nvim] JDT Language Server started  

Output channel: java

[Info  - 6:09:01 PM] JDT Language Server started
[object Object]

Describe the bug

This is the result after completing parameter for a function:

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        int index = 0;
        String element = "Hello World";

        list.add(${1:index}, ${2:element});
    }
}

I would expect instead:

list.add(index, element);

Reproduce the bug

  1. Create mini.vim with:
set runtimepath^=~/.local/share/nvim/plugged/coc.nvim
filetype plugin indent on
syntax on
set hidden
  1. Create Main.java with:
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        int index = 0;
        String element = "Hello World";
    }
}
  1. Type list. then select method add(int index, String element) then press ENTER.

I believe this has happened after I’ve updated jdt.ls with java.updateLanguageServer.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

Fixed on latest release branch of coc.nvim.

I’ve made a fix to disable insertTextFormat for resolved item.

Got it, should be bug of jdt.ls.

[Trace - 2:51:41 PM] Received response 'completionItem/resolve - (7)' in 3ms.
Result: {
    "label": "add(int index, String element) : void",
    "kind": 2,
    "detail": "List.add(int index, String element) : void",
    "sortText": "999999035",
    "insertText": "add",
    "insertTextFormat": 1,
    "textEdit": {
        "range": {
            "start": {
                "line": 11,
                "character": 13
            },
            "end": {
                "line": 11,
                "character": 13
            }
        },
        "newText": "add(${1:index}, ${2:element});"
    }
}

the insertTextFormat should be 2 for snippet. Old version of jdt.ls work as expected.

The latest jdt.ls milestone 0.50.0 is out and appears to cause this same completion issue. Could it be a compatibility issue between the coc language client and jdt.ls? I’ve tested both vscode-java and coc-java using the same jdt.ls server version 0.50.0. It works fine with vscode, but not with coc. I can see in the logs the capabilities request is slightly different between the two. Perhaps that difference is leading to the jdt.ls server not responding with the correct value for “insertTextFormat”? Or perhaps its some other client configuration sent to the server that is different and leading to the faulty result?

Temporary workaround:

inoremap <silent> <c-c> <esc>v:s/${[0-9]://g<CR>v:s/}//g<CR>:nohl<CR>f(

In insert mode, CTRL+C replaces list.add(${1:index}) to list.add(index).

  • <esc>: escape in insert mode, go to normal mode
  • <c-c>: Ctrl-C
  • v: visual mode
  • <CR>: enter
  • :s/${[0-9]://g: removes ${[0-9]:
  • :s/}//g: removes }
  • :nohl: clear highight
  • f(: places cursor on first parenthesis