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

Java formatting options provided as initializationOptions.settings.java.format.settings.url are ignored #3108

Open
HaraldKi opened this issue Mar 24, 2024 · 5 comments

Comments

@HaraldKi
Copy link

Summary:

Despite providing a formatter specification xml which is actually read and seemingly understood by the language server, formatting does not change from the default.

My setup:

  • Emacs eglot (but read on, I checked most things on the language server level)
  • On commit 66f98a6 of Wed Mar 20 15:56:53 2024 +0800

What I do:
I configure formatting with an xml file and I see the following things:

At initialization the format specification xml is send by the editor as follows (taken from the editor<->language server logs provided by eglot):

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "processId": 5196,
    "clientInfo": {
      "name": "Eglot",
      "version": "1.17"
    },
    "rootPath": "/home/... some project",
    "rootUri": "file:///home/... same project",
    "initializationOptions": {
      "settings": {
        "java": {
          "format": {
            "enabled": true,
            "settings": {
              "url": "/home/user/.emacs.d/eclipse-formatter.xml"
            }
          }
        }
      }
    },
 ...

I added a log output to FormatterManager.java to verify the file is actually read.

diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/FormatterManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/FormatterManager.java
index 232040ba..33bd53e2 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/FormatterManager.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/FormatterManager.java
@@ -167,6 +167,7 @@ public class FormatterManager {
                        throw new CoreException(new Status(IStatus.WARNING, IConstants.PLUGIN_ID, e.getMessage(), e));
                }
                int version = handler.getVersion();
+    JavaLanguageServerPlugin.logInfo("TTTTTTTTTTTTTTTT " + handler.getSettings());
                if (handler.getSettings() == null) {
                        if (!Objects.equals(profileName, handler.fName)) {
                                JavaLanguageServerPlugin.logError("Invalid settings: java.format.settings.profile=" + profileName + ". The '" + profileName + "' profile doesn't exist.");

The output from this log looks like:

!ENTRY org.eclipse.jdt.ls.core 1 0 2024-03-24 10:02:35.140
!MESSAGE TTTTTTTTTTTTTTTT {org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert, org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert, org.eclipse.jdt.core.formatter.insert_space_before_comma_in_a...

Further I delete any project_<hexcode> directories from the workspace to force the language server to set up the project freshly. This project has neither a gradle nor maven build. Apart from the formatting it works as expected, in particular compiler errors are shown, etc.

Yet, the formatting rules are clearly not applied.

I'll keep digging, but would be grateful for any hints.

@HaraldKi

This comment was marked as outdated.

@HaraldKi
Copy link
Author

I could verify the following:

  • At initialization, eglot sends the the configuration I want and it accepted without problem by the server.
  • But then soon after initialization, eglot sends this: workspace/didChangeConfiguration {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{}}}
  • The empty settings provided are the reason, afaict, that all server settings are reverted to their defaults.

Is this a mismatch in interpretation what empty settings in didChangeConfiguration mean? Eglot seems to assume that it is OK to send empty settings if in fact nothing has changed. I assume it would send only changed values if there would be a real change. But eclipse.jdt.ls seems to assume that the change message provides not just changes but all settings?

Hints welcome.

@fbricon
Copy link
Contributor

fbricon commented Mar 25, 2024

indeed jdt.ls falls back to default settings when receiving an empty object. It expects the full settings. Partials won't be enough.

@HaraldKi
Copy link
Author

Now I wonder: is this in accordance with the protocol specification? If I read https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeConfiguration I would rather interpret this as "send changes", not "send full settings". Though the "specification" is not very formal.

@fbricon
Copy link
Contributor

fbricon commented Mar 25, 2024

@HaraldKi I think you're right, jdt.ls deviates from the spec here.

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

No branches or pull requests

2 participants