Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parameter completion #63

Closed
ChrisAmelia opened this issue Jan 6, 2020 · 21 comments
Closed

Incorrect parameter completion #63

ChrisAmelia opened this issue Jan 6, 2020 · 21 comments

Comments

@ChrisAmelia
Copy link

ChrisAmelia commented Jan 6, 2020

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.

@ChrisAmelia ChrisAmelia changed the title Parameter completion slightly incorrect Incorrect parameter completion Jan 6, 2020
@chemzqm
Copy link
Member

chemzqm commented Jan 7, 2020

Try update coc.nvim to latest version.

@ChrisAmelia
Copy link
Author

ChrisAmelia commented Jan 7, 2020

I believe coc.nvim version: 0.0.74 is the last version?

I've executed: PlugUpdate, CocUpdate and CocUpdateSync ; same issue.
This seems to only happen with java.

Before, I've executed CocCommand java.action.overrideMethodsPrompt which returns:

[coc.nvim] Command error: Internal error.

Not sure if this is related.

@ChrisAmelia
Copy link
Author

ChrisAmelia commented Jan 7, 2020

I have managed to reproduce it on my personal workspace by deleting the following folder: ~/.config/coc/extensions/coc-java-data with:

rm -rf ~/.config/coc/extensions/coc-java-data

Then running again nvim Main.java to download lastest jdt.ls which prompts:

[coc.nvim] jdt.ls not found, downloading...

Waiting for the server to be started and then doing above procedure.
It seems to be an issue with the lastest jdt.ls?

@bryanmylee
Copy link

I'm getting this same issue.

vim version: NVIM v0.5.0-416de69
node version: v13.3.0
coc.nvim version: 0.0.74-c97d41aa1e
term: iTerm.app
platform: darwin

I'm on the latest version of vim and coc.nvim. Not sure what's up though

@JSamir
Copy link

JSamir commented Jan 13, 2020

I've got the same issue. I did manually update to the latest jdt.ls a few days ago, but I am not sure if I had the issue before too...

@ghost
Copy link

ghost commented Jan 14, 2020

By completely reinstalling coc.nvim and then coc-java I have the same issue.

@ChrisAmelia
Copy link
Author

ChrisAmelia commented Jan 15, 2020

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

@chemzqm chemzqm added bug Something isn't working Cant' reproduce and removed Cant' reproduce bug Something isn't working labels Jan 15, 2020
@chemzqm
Copy link
Member

chemzqm commented Jan 15, 2020

Unable to reproduce, try upgrade https://github.com/neoclide/coc-snippets

@ChrisAmelia
Copy link
Author

ChrisAmelia commented Jan 15, 2020

Tried, same issue.

I've also tried a minimalistic configuration with nvim 0.4.3 and 0.5:

  • init.vim: above minimal vimrc
  • no extension was installed except coc-java
  • complete reinstall of coc.nvim (build from source and with release branch)
  • no configuration set in coc-settings.json

Doesn't seem to be related to another extension than coc-java 🤔

@chemzqm
Copy link
Member

chemzqm commented Jan 15, 2020

Try minimal vimrc.

@ChrisAmelia
Copy link
Author

I've edited previous post, I've tried with above minimal vimrc but same result.

@chemzqm
Copy link
Member

chemzqm commented Jan 15, 2020

Please upload verbose output from jdt.ls https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

@ChrisAmelia
Copy link
Author

jdtls.verbose.output.txt

@chemzqm
Copy link
Member

chemzqm commented Jan 16, 2020

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.

@douglarek
Copy link

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.

which jdt.ls version works ?

@dansomething
Copy link
Contributor

The latest milestone 0.48.0 is working for me.
https://download.eclipse.org/jdtls/milestones/

@douglarek
Copy link

The latest milestone 0.48.0 is working for me.
https://download.eclipse.org/jdtls/milestones/

thanks, will have a try

@chemzqm chemzqm closed this as completed Feb 9, 2020
@dansomething
Copy link
Contributor

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?

@douglarek
Copy link

IMO, it should be fixed, we can not always use an old jdt.ls version.

@chemzqm
Copy link
Member

chemzqm commented Feb 27, 2020

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

@chemzqm
Copy link
Member

chemzqm commented Feb 27, 2020

Fixed on latest release branch of coc.nvim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants