question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No delegateCommandHandler for java.apply.workspaceEdit

See original GitHub issue

I’m using jdt.ls via LanguageClient-neovim, and I’m trying to use code actions. This is my file:

public class App {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
    }
}

JFrame is linted because I did not import it, and the LS suggests some code actions(this is from the log of the client - I just formatted the JSON lines to make them readable):

17:06:19 INFO    [MainThread] Begin textDocument/codeAction
17:06:19 DEBUG   [MainThread] =>
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "textDocument/codeAction",
  "params": {
    "textDocument": {
      "uri": "file:///files/tests/java/45/src/main/java/App.java"
    },
    "range": {
      "start": {
        "line": 2,
        "character": 8
      },
      "end": {
        "line": 2,
        "character": 14
      }
    },
    "context": {
      "diagnostics": [
        {
          "range": {
            "start": {
              "line": 2,
              "character": 8
            },
            "end": {
              "line": 2,
              "character": 14
            }
          },
          "severity": 1,
          "code": "16777218",
          "source": "Java",
          "message": "JFrame cannot be resolved to a type"
        }
      ]
    }
  }
}
17:06:19 DEBUG   [RPC-java  ] <= {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Oct 3, 2017 5:05:52 PM \u003e\u003e document/codeAction"}}
17:06:19 DEBUG   [RPC-java  ] <=
{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "title": "Change to 'JobName' (javax.print.attribute.standard)",
      "command": "java.apply.workspaceEdit",
      "arguments": [
        {
          "changes": {
            "file:///files/tests/java/45/src/main/java/App.java": [
              {
                "range": {
                  "start": {
                    "line": 0,
                    "character": 0
                  },
                  "end": {
                    "line": 0,
                    "character": 0
                  }
                },
                "newText": "import javax.print.attribute.standard.JobName;"
              },
              {
                "range": {
                  "start": {
                    "line": 0,
                    "character": 0
                  },
                  "end": {
                    "line": 0,
                    "character": 0
                  }
                },
                "newText": "\n\n"
              },
              {
                "range": {
                  "start": {
                    "line": 2,
                    "character": 8
                  },
                  "end": {
                    "line": 2,
                    "character": 8
                  }
                },
                "newText": "JobName"
              },
              {
                "range": {
                  "start": {
                    "line": 2,
                    "character": 8
                  },
                  "end": {
                    "line": 2,
                    "character": 14
                  }
                },
                "newText": ""
              }
            ]
          }
        }
      ]
    },
    {
      "title": "Import 'JFrame' (javax.swing)",
      "command": "java.apply.workspaceEdit",
      "arguments": [
        {
          "changes": {
            "file:///files/tests/java/45/src/main/java/App.java": [
              {
                "range": {
                  "start": {
                    "line": 0,
                    "character": 0
                  },
                  "end": {
                    "line": 0,
                    "character": 0
                  }
                },
                "newText": "import javax.swing.JFrame;"
              },
              {
                "range": {
                  "start": {
                    "line": 0,
                    "character": 0
                  },
                  "end": {
                    "line": 0,
                    "character": 0
                  }
                },
                "newText": "\n\n"
              }
            ]
          }
        }
      ]
    },
    {
      "title": "Add type parameter 'JFrame' to 'main(String[])'",
      "command": "java.apply.workspaceEdit",
      "arguments": [
        {
          "changes": {
            "file:///files/tests/java/45/src/main/java/App.java": [
              {
                "range": {
                  "start": {
                    "line": 1,
                    "character": 18
                  },
                  "end": {
                    "line": 1,
                    "character": 18
                  }
                },
                "newText": "<"
              },
              {
                "range": {
                  "start": {
                    "line": 1,
                    "character": 18
                  },
                  "end": {
                    "line": 1,
                    "character": 18
                  }
                },
                "newText": "JFrame"
              },
              {
                "range": {
                  "start": {
                    "line": 1,
                    "character": 18
                  },
                  "end": {
                    "line": 1,
                    "character": 18
                  }
                },
                "newText": "> "
              }
            ]
          }
        }
      ]
    }
  ]
}
17:06:19 DEBUG   [MainThread] state.codeActionCommands: [] =>
[
  {
    "title": "Change to 'JobName' (javax.print.attribute.standard)",
    "command": "java.apply.workspaceEdit",
    "arguments": [
      {
        "changes": {
          "file:///files/tests/java/45/src/main/java/App.java": [
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "import javax.print.attribute.standard.JobName;"
            },
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "\n\n"
            },
            {
              "range": {
                "start": {
                  "line": 2,
                  "character": 8
                },
                "end": {
                  "line": 2,
                  "character": 8
                }
              },
              "newText": "JobName"
            },
            {
              "range": {
                "start": {
                  "line": 2,
                  "character": 8
                },
                "end": {
                  "line": 2,
                  "character": 14
                }
              },
              "newText": ""
            }
          ]
        }
      }
    ]
  },
  {
    "title": "Import 'JFrame' (javax.swing)",
    "command": "java.apply.workspaceEdit",
    "arguments": [
      {
        "changes": {
          "file:///files/tests/java/45/src/main/java/App.java": [
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "import javax.swing.JFrame;"
            },
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "\n\n"
            }
          ]
        }
      }
    ]
  },
  {
    "title": "Add type parameter 'JFrame' to 'main(String[])'",
    "command": "java.apply.workspaceEdit",
    "arguments": [
      {
        "changes": {
          "file:///files/tests/java/45/src/main/java/App.java": [
            {
              "range": {
                "start": {
                  "line": 1,
                  "character": 18
                },
                "end": {
                  "line": 1,
                  "character": 18
                }
              },
              "newText": "<"
            },
            {
              "range": {
                "start": {
                  "line": 1,
                  "character": 18
                },
                "end": {
                  "line": 1,
                  "character": 18
                }
              },
              "newText": "JFrame"
            },
            {
              "range": {
                "start": {
                  "line": 1,
                  "character": 18
                },
                "end": {
                  "line": 1,
                  "character": 18
                }
              },
              "newText": "> "
            }
          ]
        }
      }
    ]
  }
]
17:06:19 INFO    [MainThread] End textDocument/codeAction

So I pick Import 'JFrame' (javax.swing):

17:06:44 INFO    [MainThread] Begin workspace/executeCommand
17:06:44 DEBUG   [MainThread] =>
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "workspace/executeCommand",
  "params": {
    "command": "java.apply.workspaceEdit",
    "arguments": [
      {
        "changes": {
          "file:///files/tests/java/45/src/main/java/App.java": [
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "import javax.print.attribute.standard.JobName;"
            },
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "\n\n"
            },
            {
              "range": {
                "start": {
                  "line": 2,
                  "character": 8
                },
                "end": {
                  "line": 2,
                  "character": 8
                }
              },
              "newText": "JobName"
            },
            {
              "range": {
                "start": {
                  "line": 2,
                  "character": 8
                },
                "end": {
                  "line": 2,
                  "character": 14
                }
              },
              "newText": ""
            }
          ]
        }
      }
    ]
  }
}
17:06:44 DEBUG   [RPC-java  ] <= {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Oct 3, 2017 5:05:52 PM \u003e\u003e workspace/executeCommand"}}
17:06:44 DEBUG   [RPC-java  ] <= {"jsonrpc":"2.0","id":"2","error":{"code":-32601,"message":"No delegateCommandHandler for java.apply.workspaceEdit"}}
17:06:44 ERROR   [MainThread] {"jsonrpc": "2.0", "id": "2", "error": {"code": -32601, "message": "No delegateCommandHandler for java.apply.workspaceEdit"}}
17:06:44 INFO    [MainThread] End workspace/executeCommand

And get the error message - No delegateCommandHandler for java.apply.workspaceEdit

The LSP specs does not seem to refer to delegateCommandHandlers, and from #346 it looks like it’s jdt.ls’ extension - but I don’t see any instructions on how to use it.

So… what do I need to do to add support for it in a client?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
AObuchowcommented, Sep 25, 2019

Was testing JDT-LS integration with LSP4E and ran into this issue as well. Would it be possible to replace usage of “java.apply.workspaceEdit” in codeAction with workspaceEdit? It seems to be mentioned in CodeActionHandler.java:

if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(proposal.getKind())) {
			// TODO: Should set WorkspaceEdit directly instead of Command
			CodeAction codeAction = new CodeAction(name);
			codeAction.setKind(proposal.getKind());
			codeAction.setCommand(command);
			codeAction.setDiagnostics(context.getDiagnostics());
			return Optional.of(Either.forRight(codeAction));
		} else {
			return Optional.of(Either.forLeft(command));
		}

Also, could we retitle this issue to something like Replace usage of java.apply.workspaceEdit in codeAction by workspaceEdit?

6reactions
amiramwcommented, Feb 14, 2018

But option 2 doesn’t conform with the protocol. https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction

When the command is selected the server should be contacted again (via the workspace/executeCommand) request to execute the command.

If the need for option 2 is real shouldn’t it be pushed to the protocol?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Project in VS-Code, "No delegateCommandHandler for ...
I'm using following Extensions for Visual Studio Code: Debugger for Java (0.20.0); Gitlens (9.9.0); Java Dependency Viewer (0.5.1); Java Test ...
Read more >
org.eclipse.lsp4j.ExecuteCommandParams java code examples
How to use ... Best Java code snippets using org.eclipse.lsp4j. ... MethodNotFound, String.format("No delegateCommandHandler for %s", params.
Read more >
org.eclipse.lsp4j.ExecuteCommandParams Java Examples
Sends commands to execute to the server and applies the changes returned if the future returns a WorkspaceEdit * * @param commands The...
Read more >
redhat-developer/vscode-java - Gitter
Given URI does not belong to an existing Java source file. ... It seem like m2e doens't use the password (i'm getting 401...
Read more >
java-language-server - Bountysource
Where do I put libraries (jars) if I want to use them in my class? $ 0 ... No delegateCommandHandler for java.action.organizeImports $...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found