eclipse-jdtls / eclipse.jdt.ls

Java language server
1.75k stars 391 forks source link

jdt.ls cannot autocomplete third-party libraries #967

Closed NitroCao closed 5 years ago

NitroCao commented 5 years ago

Editor: neovim 0.4.0-DEV with coc-java. OS: Archlinux. build tool: Gradle. Gradle version:

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_202 (Oracle Corporation 25.202-b26)
OS:           Linux 5.0.2-arch1-1-ARCH amd64

build.gradle:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.2.1/userguide/tutorial_java_projects.html
 */

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

    id 'eclipse'
    // Apply the application plugin to add support for building an application
    id 'application'
}

sourceCompatibility = 1.8

repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // This dependency is found on compile classpath of this component and consumers.
    implementation 'com.google.guava:guava:27.0.1-jre'
    implementation 'commons-cli:commons-cli:1.4'
    implementation 'com.squareup.okhttp3:okhttp:3.14.0'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
}

// Define the main class for the application
//mainClassName = 'm3u8Downloader.App'

project structure:

.
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
    ├── main
    │   ├── java
    │   │   ├── m3u8Downloader
    │   │   │   ├── App.java
    │   │   │   └── Downloader.java
    │   │   └── m3u8parser
    │   │       ├── FormatException.java
    │   │       └── m3u8parser.java
    │   └── resources
    └── test
        ├── java
        │   └── m3u8Downloader
        │       └── AppTest.java
        └── resources

12 directories, 11 files

log:

!SESSION 2019-03-21 09:40:32.572 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_202
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments:  -data /home/xxxxxx/.config/coc/extensions/coc-java-data/jdt_ws_266a429de305e6bac55f8d917736af7f

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.104
!MESSAGE class org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin is started

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.204
!MESSAGE Main thread is waiting

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.226
!MESSAGE >> initialize

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.227
!MESSAGE Initializing Java Language Server 0.36.0.201903182216

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.248
!MESSAGE >> initialized

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.273
!MESSAGE Creating the Java project jdt.ls-java-project

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.661
!MESSAGE Finished creating the Java project jdt.ls-java-project

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.920
!MESSAGE Workspace initialized in 682ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.978
!MESSAGE >> workspace/didChangeConfiguration

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.980
!MESSAGE >> registerFeature 'workspace/didChangeWatchedFiles'

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.990
!MESSAGE >>New configuration: {java={jdt={ls={vmargs=-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication}}, errors={incompleteClasspath={severity=ignore}}, configuration={checkProjectSettingsExclusions=true, updateBuildConfiguration=interactive}, trace={server=off}, import={gradle={enabled=false}, maven={enabled=true}, exclusions=[**/node_modules/**, **/.metadata/**, **/archetype-resources/**, **/META-INF/maven/**]}, referencesCodeLens={enabled=false}, signatureHelp={enabled=false}, implementationsCodeLens={enabled=false}, format={enabled=true, comments={enabled=true}, onType={enabled=true}}, autobuild={enabled=true}, maxConcurrentBuilds=1.0, completion={enabled=true, overwrite=false, guessMethodArguments=true, favoriteStaticMembers=[org.junit.Assert.*, org.junit.Assume.*, org.junit.jupiter.api.Assertions.*, org.junit.jupiter.api.Assumptions.*, org.junit.jupiter.api.DynamicContainer.*, org.junit.jupiter.api.DynamicTest.*, org.mockito.Mockito.*, org.mockito.ArgumentMatchers.*, org.mockito.Answers.*], importOrder=[java, javax, com, org]}, progressReports={enabled=true}, codeGeneration={hashCodeEquals={useJava7Objects=false, useInstanceof=false, useBlocks=false, generateComments=false}}}}

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:34.992
!MESSAGE >> document/didOpen

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:35.007
!MESSAGE Classpath is incomplete. Only syntax errors will be reported for file:///home/xxxxxxx/UNIX_Programming/java/m3u8Downloader/src/main/java/m3u8Downloader/Downloader.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:35.728
!MESSAGE begin problem for /Downloader.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:35.729
!MESSAGE 0 problems reported for /Downloader.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2019-03-21 09:40:35.733
!MESSAGE Reconciled 0, validated: 1. Took 228 ms

.project in data directory:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>jdt.ls-java-project</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
    <linkedResources>
        <link>
            <name>src/m3u8Downloader/App.java</name>
            <type>1</type>
            <location>/home/xxxxxx/UNIX_Programming/java/m3u8Downloader/src/main/java/m3u8Downloader/App.java</location>
        </link>
        <link>
            <name>src/m3u8Downloader/Downloader.java</name>
            <type>1</type>
            <location>/home/xxxxxx/UNIX_Programming/java/m3u8Downloader/src/main/java/m3u8Downloader/Downloader.java</location>
        </link>
    </linkedResources>
</projectDescription>

.classpath in data directory:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Please help me... I haven't found a solution for a long time.

yaohaizh commented 5 years ago

In which scenario the auto complete doesn't work?

NitroCao commented 5 years ago

In which scenario the auto complete doesn't work?

When I use objects and functions from third party libraries. For example:

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;
import java.net.MalformedURLException;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.ParseException;

import m3u8parser.m3u8parser;
import m3u8parser.FormatException;

import org.apache.commons.cli.HelpFormatter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class App {
    public static void main(String[] args) throws IOException, ParseException, FileNotFoundException, FormatException {
        Options options = new Options();
        CommandLineParser parser = new DefaultParser();
        HelpFormatter formatter = new HelpFormatter();
        CommandLine cmd = null;

        options.addOption(Option.builder("i")
                                .longOpt("url")
                                .hasArg()
                                .argName("url")
                                .desc("Specify the url of m3u8 file")
                            .build());

the variable options is a Options object from org.apache.commons.cli. When I insert options., it cannot show the methods of Options, such as addOption.

yaohaizh commented 5 years ago

image

It works from VScode Java. It might an issue of neovim.

NitroCao commented 5 years ago

Seems that it's the problem of my configuration :(

orlandoc01 commented 5 years ago

@JayceCao I'm also using Vim and have the same issue, did you figure out how to resolve this?

NitroCao commented 5 years ago

@JayceCao I'm also using Vim and have the same issue, did you figure out how to resolve this?

Update plugins first. Then configure the value of GRADLE_USER_HOME shell environment variable to your home .gradle directory. Clear the $HOME/.gradle/wrapper/dists directory. Hope it will work for you.

GrimKriegor commented 5 years ago

Hello everyone. I am running Vim 8.1 on Arch and using ALE as the client for eclipse.jdt.ls. Unfortunately, even though linting and autocomplete are working for the core Java libraries, I can neither get auto-completion for third party libraries, similarly to what is shown by @JayceCao above, nor does it seem like there is any activity regarding Gradle when I open the project, as a clean ~/.gradle folder remains unpopulated. Even when I call Gradle to download the dependencies, I still get no autocompletion on the third party libraries, even though they are present. This is surely an issue with my configuration so I come here searching for some guidance. My questions are as follows, does autocomplete for third party libraries still work for you on eclipse.jdt.ls 0.35+, @JayceCao? Did setting GRADLE_USER_HOME and cleaning up ~/.gradle fix the issue for you @orlandoc01? Should eclipse.jdt.ls trigger Gradle when opening a project? Thank you for your time.

NitroCao commented 5 years ago

I'm using coc-java plugin in coc.nvim completion plugin, which uses jdt.ls. And everything works fine. You can have a try.

Hello everyone. I am running Vim 8.1 on Arch and using ALE as the client for eclipse.jdt.ls. Unfortunately, even though linting and autocomplete are working for the core Java libraries, I can neither get auto-completion for third party libraries, similarly to what is shown by @JayceCao above, nor does it seem like there is any activity regarding Gradle when I open the project, as a clean ~/.gradle folder remains unpopulated. Even when I call Gradle to download the dependencies, I still get no autocompletion on the third party libraries, even though they are present. This is surely an issue with my configuration so I come here searching for some guidance. My questions are as follows, does autocomplete for third party libraries still work for you on eclipse.jdt.ls 0.35+, @JayceCao? Did setting GRADLE_USER_HOME and cleaning up ~/.gradle fix the issue for you @orlandoc01? Should eclipse.jdt.ls trigger Gradle when opening a project? Thank you for your time.

BBonifield commented 5 years ago

@JayceCao can you elaborate on your coc.nvim setup? I am using coc.nvim with the jdt.ls extension. I get errors like The import com.whatever.whatever cannot be resolved or any third-party package that I have. I don't get this issue when i load the project in Eclipse itself or IntelliJ.

rickywu commented 5 years ago

@JayceCao can you share your coc.nvim and coc-java configuration, I updated to lastest version of eclispe.jdt.ls and vim plugins also clear dist folder, and still have this problem

mdacach commented 4 years ago

@JayceCao can you elaborate on your coc.nvim setup? I am using coc.nvim with the jdt.ls extension. I get errors like The import com.whatever.whatever cannot be resolved or any third-party package that I have. I don't get this issue when i load the project in Eclipse itself or IntelliJ.

I have the same problem, did you figure it out?

NitroCao commented 4 years ago

@JayceCao can you elaborate on your coc.nvim setup? I am using coc.nvim with the jdt.ls extension. I get errors like The import com.whatever.whatever cannot be resolved or any third-party package that I have. I don't get this issue when i load the project in Eclipse itself or IntelliJ.

I have the same problem, did you figure it out?

Sorry that I don't use nvim to write Java anymore and the original configuration file has been lost

Rheisen commented 4 years ago

Also having this problem... has anyone found a solution?

mdacach commented 4 years ago

Also having this problem... has anyone found a solution?

Yeah I got it working for me (just a simple java file, not a project).
I put my libraries here java.project.referencedLibraries
See here https://github.com/redhat-developer/vscode-java/pull/1196#issuecomment-568192224

Rheisen commented 4 years ago

Ah ok, I suppose I could download the jars manually for my projects, thanks! I am using gradle with coc-java and neovim when experiencing this problem. With vscode everything works fine, but with nvim I get package not found and symbol missing errors. I believe that shouldn't be the case and it shouldn't require manually downloading jars, but I'm having a hard time finding out why it is happening.