sublimelsp / LSP-jdtls

Convenience package for the Eclipse JDT language server
https://packagecontrol.io/packages/LSP-jdtls
MIT License
30 stars 4 forks source link

Android Support? #31

Closed blackjyn closed 2 years ago

blackjyn commented 2 years ago

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?

LDAP commented 2 years ago

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?

blackjyn commented 2 years ago

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

LDAP commented 2 years ago

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.

BanDroid commented 2 years ago

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?

LDAP commented 2 years ago

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.

BanDroid commented 2 years ago

Troubleshooting: jdtls

Version & some environment variables

Active view

Project / Workspace

LSP configuration

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

System PATH

BanDroid commented 2 years ago

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.

LDAP commented 2 years ago

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

BanDroid commented 2 years ago

@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.

LDAP commented 2 years ago

@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?

BanDroid commented 2 years ago

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).
LDAP commented 2 years ago

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
    },
}
BanDroid commented 2 years ago

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.

LDAP commented 2 years ago

@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 commented 2 years ago

@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

LDAP commented 2 years ago

Please double-check all of these points:

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.

BanDroid commented 2 years ago

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.

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

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

BanDroid commented 2 years ago

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)

LDAP commented 2 years ago

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.

BanDroid commented 2 years ago

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

/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

LDAP commented 2 years ago

@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