sublimelsp / LSP-jdtls

Convenience package for the Eclipse JDT language server

Home Page:https://packagecontrol.io/packages/LSP-jdtls

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android Support?

blackjyn opened this issue · comments

It said that JDTLS https://github.com/eclipse/eclipse.jdt.ls has experimental Android support.

Gradle project support (with experimental Android project import support)

I've already set settings for Gradle support but when I tried to open Android project , Android completion is likely doesn't work.
It downloaded several deps into GRADLE_USER_HOME but again completion is not working.

I know this is still experimental, but does ANdroid support requires different settings mainly on "language.java.languageServer.arguments" part , or somewhere?

I would have expected it to just work out-of-the-box. Does a manual Gradle build succeed? Do you have the Android SDK installed?

manual build via gradle works just fine,
I also have Android Studio installed.

But I give SB4 a try because how crazy AS and Intellij on the indexing process even on simple project and I love doing most of things manually via CMD.

and yeah, I know someone succed On this but he is on Emacs rather than SB4. https://jwill.dev/blog/2022/01/26/EmacsAsIDE-Android.html

I tried to follow on SB4 but failed

Since they are using the exact same language server (jdtls) I assume that this is an issue with the server rather than with this plugin. (Its Gradle support is limited, after all)

See here on how to enable debug output. Maybe jdtls outputs an error that helps you to track the issue down.

Is there any plan on improving to support android development with this plugin? I tried many times, it works fine with vscode, all environment variables for android had been set up right, but in sublime still cant work with this plugin.

Or maybe there could be android lsp plugin rather than supporting android development through this java lsp?

This plugin should behave just like "Language Support for Java" for VSCode since it uses the same server under the hood.

If there are differences, I am happy to investigate further but I would need detailed information about the difference, your setup as well as a minimal example/project.

Troubleshooting: jdtls

Version & some environment variables

  • LSP: 1.20.0
  • Sublime Text: 4143
  • $ANDROID_SDK_ROOT: /home/bani/Android/Sdk
  • $JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64
  • $GRADLE_HOME: /opt/gradle/gradle-7.4.2
  • $GRADLE_USER_HOME: /opt/gradle/gradle-7.4.2

Server Test Run

  • exit code: 0
  • output
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

Server Configuration

  • command
[
  "${java_executable}", 
  "--add-modules=ALL-SYSTEM", 
  "--add-opens", 
  "java.base/java.util=ALL-UNNAMED", 
  "--add-opens", 
  "java.base/java.lang=ALL-UNNAMED", 
  "--add-opens", 
  "java.base/sun.nio.fs=ALL-UNNAMED", 
  "-Declipse.application=org.eclipse.jdt.ls.core.id1", 
  "-Dosgi.bundles.defaultStartLevel=4", 
  "-Declipse.product=org.eclipse.jdt.ls.core.product", 
  "-Dfile.encoding=UTF-8", 
  "-DwatchParentProcess=${watch_parent_process}", 
  "-noverify", 
  "-XX:+UseParallelGC", 
  "-XX:GCTimeRatio=4", 
  "-XX:AdaptiveSizePolicyWeight=90", 
  "-Dsun.zip.disableMemoryMapping=true", 
  "-Xmx1G", 
  "-Xms100m", 
  "-jar", 
  "${serverdir}/plugins/org.eclipse.equinox.launcher_${launcher_version}.jar", 
  "-configuration", 
  "${serverdir}/config_${jdtls_platform}", 
  "-data", 
  "${datadir}"
]
  • shell command
/usr/lib/jvm/java-11-openjdk-amd64/bin/java --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.nio.fs=ALL-UNNAMED -Declipse.application=org.eclipse.jdt.ls.core.id1 -Dosgi.bundles.defaultStartLevel=4 -Declipse.product=org.eclipse.jdt.ls.core.product -Dfile.encoding=UTF-8 -DwatchParentProcess=true -noverify -XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -jar "/home/bani/.cache/sublime-text/Package Storage/LSP-jdtls/server/1.12.0-202206011637/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar" -configuration "/home/bani/.cache/sublime-text/Package Storage/LSP-jdtls/server/1.12.0-202206011637/config_linux" -data "/home/bani/.cache/sublime-text/Package Storage/LSP-jdtls/data"
  • selector
source.java
  • priority_selector
source.java
  • init_options
{
  "bundles": [
    "${debug_plugin_path}"
  ]
}
  • settings
{
  "java": {
    "autobuild": {
      "enabled": true
    }, 
    "codeGeneration": {
      "generateComments": false, 
      "hashCodeEquals": {
        "useInstanceof": false, 
        "useJava7Objects": false
      }, 
      "toString": {
        "codeStyle": "STRING_CONCATENATION", 
        "limitElements": 0, 
        "listArrayContents": true, 
        "skipNullValues": false, 
        "template": "\\${object.className} [\\${member.name()}=\\${member.value}, \\${otherMembers}]"
      }, 
      "useBlocks": false
    }, 
    "completion": {
      "enabled": 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.*"
      ], 
      "filteredTypes": [
        "java.awt.*", 
        "com.sun.*"
      ], 
      "guessMethodArguments": false, 
      "importOrder": [
        "java", 
        "javax", 
        "com", 
        "org"
      ], 
      "maxResults": 0, 
      "overwrite": true
    }, 
    "configuration": {
      "checkProjectSettingsExclusions": true, 
      "maven": {
        "globalSettings": null, 
        "userSettings": null
      }, 
      "runtimes": [], 
      "updateBuildConfiguration": "interactive"
    }, 
    "contentProvider": {
      "preferred": null
    }, 
    "errors": {
      "incompleteClasspath": {
        "severity": "warning"
      }
    }, 
    "foldingRange": {
      "enabled": false
    }, 
    "format": {
      "comments": {
        "enabled": true
      }, 
      "enabled": true, 
      "onType": {
        "enabled": false
      }, 
      "settings": {
        "profile": null, 
        "url": null
      }
    }, 
    "home": "/usr/lib/jvm/java-11-openjdk-amd64", 
    "implementationsCodeLens": {
      "enabled": true
    }, 
    "import": {
      "exclusions": [
        "**/node_modules/**", 
        "**/.metadata/**", 
        "**/archetype-resources/**", 
        "**/META-INF/maven/**"
      ], 
      "gradle": {
        "arguments": null, 
        "enabled": true, 
        "home": null, 
        "java": {
          "home": null
        }, 
        "jvmArguments": null, 
        "offline": {
          "enabled": false
        }, 
        "user": {
          "home": null
        }, 
        "version": null, 
        "wrapper": {
          "enabled": true
        }
      }, 
      "maven": {
        "enabled": true
      }
    }, 
    "imports": {
      "gradle": {
        "wrapper": {
          "checksums": []
        }
      }
    }, 
    "maven": {
      "downloadSources": false, 
      "updateSnapshots": false
    }, 
    "maxConcurrentBuilds": 1, 
    "progressReports": {
      "enabled": true
    }, 
    "project": {
      "importHint": true, 
      "importOnFirstTimeStartup": "interactive", 
      "referencedLibraries": [
        "lib/**/*.jar"
      ], 
      "resourceFilters": [
        "node_modules", 
        ".git"
      ]
    }, 
    "refactor": {
      "renameFromFileExplorer": "prompt"
    }, 
    "references": {
      "includeAccessors": true
    }, 
    "referencesCodeLens": {
      "enabled": true
    }, 
    "saveActions": {
      "organizeImports": false
    }, 
    "selectionRange": {
      "enabled": true
    }, 
    "semanticHighlighting": {
      "enabled": false
    }, 
    "server": {
      "launchMode": "Hybrid"
    }, 
    "showBuildStatusOnStart": {
      "enabled": false
    }, 
    "signatureHelp": {
      "enabled": true
    }, 
    "sources": {
      "organizeImports": {
        "starThreshold": 99, 
        "staticStarThreshold": 99
      }
    }, 
    "templates": {
      "fileHeader": [], 
      "typeComment": []
    }, 
    "trace": {
      "server": "off"
    }
  }, 
  "jdtls": {
    "enableLombok": false
  }
}
  • env
{}

Active view

  • File name
/home/bani/AndroidStudioProjects/SublimeTest1/app/src/main/java/com/example/sublimetest1/MainActivity.java
  • Settings
{
  "auto_complete_selector": "meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc", 
  "lsp_active": true, 
  "syntax": "Packages/Java/Java.sublime-syntax"
}
  • base scope
source.java

Project / Workspace

  • folders
[
  "/home/bani/AndroidStudioProjects/SublimeTest1"
]
  • is project: False

LSP configuration

{
  "completion_insert_mode": "replace", 
  "show_diagnostics_panel_on_save": 1
}

System PATH

  • /home/bani/Applications/.bin
  • /usr/local/sbin
  • /usr/local/bin
  • /usr/sbin
  • /usr/bin
  • /sbin
  • /bin
  • /usr/games
  • /usr/local/games
  • /snap/bin

the completion didn't work, cant recognize any android api. do i have to modify the gradle.home and gradle.java.home in settings? if yes, how? whats the differences between those two?

Notes: the project tested was Empty Activity template from android studio.

@BanDroid You need at least Java 17 for jdtls. Your issue may be unrelated to Android.

@BanDroid You need at least Java 17 for jdtls. Your issue is unrelated to Android.

Sorry, but my java (console) projects working fine, getting all reference, completion, diagnostic, etc.

But when it comes to android project, it didn't work (cannot recognize any android classes) but class from java still works, and also giving error of MainActivity is not in the classpath.

@BanDroid You need at least Java 17 for jdtls. Your issue is unrelated to Android.

Sorry, but my java (console) projects working fine, getting all reference, completion, diagnostic, etc.

But when it comes to android project, it didn't work (cannot recognize any android classes) but class from java still works, and also giving error of MainActivity is not in the classpath.

Can you share a project where the issue occurs?

Can you share a project where the issue occurs?

It just Empty Activity from android studio.

Here's how i'm testing it out:

  1. Create a new Empty Activity project in android studio and exits.
  2. Open the project in sublime.
  3. Enable the jdtls language server.
  4. The server is running fine but didn't recognize any android classes or dependencies that have been added in the project (only basic java class).

Try setting "java.jdt.ls.androidSupport.enabled": true in the jdtls preferences:

// This is LSP-jdtls.sublime-settings
{
    "settings": {
        "java.jdt.ls.androidSupport.enabled": true
    },
}

Try setting "java.jdt.ls.androidSupport.enabled": true in the jdtls preferences:

// This is LSP-jdtls.sublime-settings
{
    "settings": {
        "java.jdt.ls.androidSupport.enabled": true
    },
}

Sorry, still the same. LSP still running fine but cant recognize any android classes.

There's also error of MainActivity.java is not on the classpath of project app, only syntax errors are reported, jdtls, Line 1, Column 1

It seems the file app/.classpath is the functionality of this plugin for the project to work. Let me know if there's something to do with that.

@BanDroid that error usually happens if the workspace ist not set correctly. Please make sure, that the first folder in your sidebar is the project base folder.

With that I was able to import your demo project and get completion, docs,...

The sidebar should look like this:
image

@BanDroid that error usually happens if the workspace ist not set correctly. Please make sure, that the first folder in your sidebar is the project base folder.

With that I was able to import your demo project and get completion, docs,...

As you could see in my troubleshoot result in the Project/Workspaces, i only open 1 project and it is the root path of the project

Please double-check all of these points:

  • Android Support is enabled in settings with java.jdt.ls.androidSupport.enabled. You can also try the latest main (by cloning the repo), I pushed the setting yesterday.
  • Android SDK is installed and ANDROID_HOME environment variable is set
  • The first folder in the sidebar is the project root folder
  • ./gradlew assembleDebug finishes without issues
  • Your Java version in path is at least 17.

With that, it works on my system (I know that that does not help - but it makes it hard for me to reproduce). If even that does not work, enable LSP log in the LSP settings and provide a server log together with a new Troubleshoot Server.

Already tried, still the same (jdtls run fine and could give completion from project reference but cant recognize any android classes). i will try with openjdk-17 next time, and will give you information here.

  • Android Support is enabled
  • Android SDK and $ANDROID_HOME variable
  • only open 1 folder which is the root folder of the project
  • ./gradlew assembleDebug without issues
  • Java version 17

shot-2022-12-01_19-16-18

shot-2022-12-01_19-21-14

I still getting the same result, already use openjdk-17, my JAVA_HOME already pointing to it and my java path in jdtls settings already changed to my openjdk-17.
please checkout these log from toggle panel and also the new troubleshoot i did.

log.txt
troubleshoot.md

i also using the debug version of this plugin as you said (by cloning it)

Your logs do not look like they are taken from the latest main. Let's eliminate all external factors:

  1. Delete ~/.cache/sublime-text/Package\ Storage/LSP-jdtls
  2. Open Sublime in safe mode with subl --safe-mode
  3. Goto Tools -> Install Package Control
  4. Goto Command Palette -> Package Control: Install Package
  5. Install LSP
  6. Goto Preferences -> Browse Packages
  7. Clone https://github.com/sublimelsp/LSP-jdtls into that folder
  8. Goto File -> Open Folder -> Open your Android Project
  9. Navigate to MainActivity.java

Then code intelligence should work. To test that, you can hover on AppCompatActivity.

the server is work in android project now. unfortunately, still give a weird error.

  • picking the completion result giving exception even there's exist item in the completion.
  • the project package name cannot be resolved. (it was known as error, so everytime i save the file, it will open diagnostic panel but it shouldn't be opened since no error from that package name cause it is exist)
/home/bani/AndroidStudioProjects/SublimeTest1/app/src/main/java/com/example/sublimetest1/MainActivity.java:
    1:1   error   The type java.lang.invoke.LambdaMetafactory cannot be resolved. It is indirectly referenced from required .class files ​Java:16777540

shot-2022-12-05_01-17-51

@BanDroid These are upstream issues of JDTLS, because they occur in VSCode too. You can open a new issue here: https://github.com/eclipse/eclipse.jdt.ls/issues