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

[Feature request] Add a codeAction to generate the serialVersionUID field #1892

Closed
baobaoit opened this issue Sep 28, 2021 · 15 comments · Fixed by #1893
Closed

[Feature request] Add a codeAction to generate the serialVersionUID field #1892

baobaoit opened this issue Sep 28, 2021 · 15 comments · Fixed by #1893
Assignees

Comments

@baobaoit
Copy link

Problem Statement

As the Eclipse IDE:
Which class implements the Serializable, we need to put a field: private static final long serialVersionUID = X;.
Where X is a number type long be generated by the tool serialver of Java.

Ideas or possible solutions

Reference: Java – How to generate serialVersionUID

Conclusion

Thank you for the hard-working to make this LS for Java, I really appreciate it.

@snjeza
Copy link
Contributor

snjeza commented Sep 28, 2021

A related issue - redhat-developer/vscode-java#401

@baobaoit
Copy link
Author

A related issue - redhat-developer/vscode-java#401

Hi @mfussenegger , would you please take a look at that issue, it seems like already been implemented. Thank you.

@snjeza
Copy link
Contributor

snjeza commented Sep 29, 2021

A related issue - redhat-developer/vscode-java#401

You should set the following JDT preference:

org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning

to <your_project>/.settings/org.eclipse.jdt.core.prefs

See also Settings Global Preferences

@testforstephen
Copy link
Contributor

One improvement is to show this quick fix suggestion at the light bulb regardless of whether the "missingSerialVersion" flag is enabled or not.

@baobaoit
Copy link
Author

Hi @snjeza,

Your solution on <your_project>/.settings/org.eclipse.jdt.core.prefs works well, but for the Settings Global Preferences seems like not working in my case.

I have researched and found this redhat-developer/vscode-java#1939.

I'm using:

  • Neovim v0.5.1 (installed from Homebrew).
  • eclipse.jdt.ls build from source.
  • nvim-jdtls plugin for my Neovim.

The config for nvim-jdtls:
image
image

The settings.prefs file content:
image

Would you please check if I doing some things wrong?

Thank you so much.

@snjeza snjeza self-assigned this Sep 29, 2021
@snjeza
Copy link
Contributor

snjeza commented Sep 29, 2021

@baobaoit
Copy link
Author

baobaoit commented Sep 30, 2021

Could you try https://github.com/snjeza/vscode-test/raw/master/jdt-language-server-1.5.0-202109292033.tar.gz ?

I have tried and the same result with the build from source.

JDT.LS downloaded from your link:
image

settings.prefs:
image

When open a class implements Serializable interface:
image

The codeAction:
image

This is when I put it in my project setting <project>/.settings/org.eclipse.jdt.core.prefs:
image
image

@snjeza
Copy link
Contributor

snjeza commented Sep 30, 2021

@baobaoit Could you try the following:

  • clone eclipse.jdt.ls
  • apply the following patch
diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java
index 4e99ffac..da940b77 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java
@@ -529,6 +529,7 @@ public class StandardProjectsManager extends ProjectsManager {
 
        @Override
        public void registerListeners() {
+               configureSettings(preferenceManager.getPreferences());
                if (this.preferenceChangeListener == null) {
                        this.preferenceChangeListener = new IPreferencesChangeListener() {
                                @Override

  • build jdt.ls
  • check your issue

@baobaoit
Copy link
Author

baobaoit commented Sep 30, 2021

@snjeza I applied your patch and these are some test cases:

Your patch:
image

Build jdt.ls with Java 11:

./mvnw clean verify -DskipTests

Case 1: settings.prefs with Eclipse IDE export format
image

Case 2: settings.prefs with JDT.LS format
image

Updated (Sep 30, 2021 - 5:19 PM)

I found this article https://dzone.com/articles/eclipse-global-preferences

I follow it guide but still no hope.

image

@snjeza
Copy link
Contributor

snjeza commented Sep 30, 2021

@mfussenegger Does nvim-jdtls support the java.settings.url preference?

@baobaoit
Copy link
Author

baobaoit commented Oct 1, 2021

@snjeza today, I make it works with a little tweak like the picture below (includes your patch or without it):
image

So this issue is resolved. I want to give to you huge respect.

A ridiculous that, when I test in Lua demo the format:

local settings = {
  java = {
    settings = {
      url = "/path"
    }
  }
}

print(settings.java.settings.url)
-- Output: /path

But with that format in nvim-jdtls it doesn't work. I need to explicit it for the key of table settings:

local settings = {
  ["java.settings.url"] = "/path"
}

@mfussenegger
Copy link
Contributor

That the nested setting definition doesn't work is odd. It works for all other settings I've tried so far.

Is the java.settings.url handling in eclipse.jdt.ls doing something special compared to other settings?

@baobaoit
Copy link
Author

baobaoit commented Oct 7, 2021

Hi @mfussenegger, reference to my comment: #1892 (comment)

The property java.settings.url is work with this format:

local settings = {
  ["java.settings.url"] = "/path"
}

It doesn't work with this format, although other settings work with this format:

local settings = {
  java = {
    settings = {
      url = "/path"
    }
  }
}

Would you please check this, thank you.

@rgrunber rgrunber added this to the Mid October 2021 milestone Oct 12, 2021
@linux40
Copy link

linux40 commented Mar 15, 2022

You should set the following JDT preference:

org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning

to <your_project>/.settings/org.eclipse.jdt.core.prefs

Excuse me, can this preference or java.settings.url be set through the command line?

@rgrunber
Copy link
Contributor

Excuse me, can this preference or java.settings.url be set through the command line?

If you mean as an environment variable or system property, we don't do this since the purpose of the language server protocol is to set it via didChangeConfiguration.

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

Successfully merging a pull request may close this issue.

6 participants