Code action response contains `null` as one of the code actions
See original GitHub issueThe response to a textDocument/codeAction
request contains null
as one of the code actions, which according to LSP specification is not allowed.
LSP specification: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction
Log:
:: --> jdtls textDocument/codeAction(55): {'context': {'diagnostics': [], 'triggerKind': 2}, 'textDocument': {'uri': '<REMOVED>'}, 'range': {'end': {'character': 27, 'line': 20}, 'start': {'character': 27, 'line': 20}}}
:: <<< jdtls 55: [{'title': 'Assign statement to new field', 'kind': 'refactor.assign.field', 'data': {'pid': '0', 'rid': '15'}, 'diagnostics': []}, {'title': 'Assign statement to new local variable', 'kind': 'refactor.assign.variable', 'data': {'pid': '1', 'rid': '15'}, 'diagnostics': []}, None, {'title': 'Organize imports', 'kind': 'source.organizeImports', 'data': {'pid': '2', 'rid': '15'}, 'diagnostics': []}, {'title': 'Generate toString()', 'kind': 'source.generate.toString', 'data': {'pid': '3', 'rid': '15'}, 'diagnostics': []}, {'title': "Sort Members for 'DynamicProxyTest.java'", 'kind': 'source.sortMembers', 'data': {'pid': '4', 'rid': '15'}, 'diagnostics': []}, {'title': 'Change modifiers to final where possible', 'kind': 'source.generate.finalModifiers', 'data': {'pid': '5', 'rid': '15'}, 'diagnostics': []}]
See https://github.com/sublimelsp/LSP/issues/2057 for additional information.
Issue Analytics
- State:
- Created 10 months ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Cannot parse response.content when contains null as value
Work correctly when Jenkins returns a valid Json. ACTUAL RESULTS. Jenkinsapi raised exception. USEFUL INFORMATION. The codes are here, in jenkinsbase.py#L85.
Read more >ASP.NET Web API and Status Code For Null Response
Response can be null when an exception occurs; and the NullObjectActionFilter class shown above can obscure error HTTP status codes.
Read more >Flow failing due to 'Null' value - Power Platform Community
Solved: I have a flow setup to create a Trello card upon creation of a Sharepoint list item. One of the items I'm...
Read more >UpdateItem - Amazon DynamoDB - AWS Documentation
Edits an existing item's attributes, or adds a new item to the table if it does not already exist. You can put, delete,...
Read more >Null API Responses and HTTP 204 Results in ASP.NET Core
x has a behavior that results in API results that return null from the controller action returning a HTTP 204 - No Content...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just to follow up here. So (1) is done now, which resulted in this change being closed. We should no longer emit
None
/null
items (at least from that code path) in code action responses.For (2), I suspect quick-assists are special in that we might have needed a separate category (eg.
quickassist
) and didn’t want to place such code actions undersource
. The problem is thatcodeActionLiteralSupport
can’t be overriden in vscode-languageclient and it may be the same for other clients also. if a language client emitted the empty string (""
) or"quickassist"
forcodeActionKind
that will probably work to pick up these quick assists.For (3), as from (2), I think some changes need to happen, but we’re partly limited by client API. If all clients had access to
codeActionLiteralSupport
then we could implement the check more appropriately on the language server.Ok, I’ve debbuged this and know what’s going wrong. I think we can fix this in JDT-LS, but the Sublime extension is also going to need to update some settings it sends to the server to ensure it continues to receive the relevant code actions (in additon to maybe others that are missing).
I’m including in this comment a sample of what I see Sublime sending in
initialize
as well as what I see VS Code sending for the sake of comparison.Sublime Java initialize
VS Code Java initialize
When a language server sends an
initialize
request to the server, the most obvious thing to send, are the settings, but there’s also a lot of capabilities that are sent to determine what kinds of things the server can safely send back (eg. completions, code actions, hover, etc.)The part I’d like to focus on is :
Sublime
VS Code
https://github.com/eclipse/eclipse.jdt.ls/blob/e64c205d6b2c3edbf6a9f5df3b4c216ba35d3c87/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeActionHandler.java#L281-L298
If you look closely, you’ll see
Add Javadoc for 'add'
has akind
ofquickassist
, which the Sublime LSP client does not register with the language server. This results in an empty union (eg.null
) ending up in the list of code actions. The “empty” code action kind that VS Code sends always matches every code action, which seems like another bug, but ultimately ensures the code action is processed. You can see the differences here :https://github.com/microsoft/vscode-languageserver-node/blob/release/client/7.1.0-next.5/client/src/common/client.ts#L2018 . https://github.com/sublimelsp/LSP/blob/main/plugin/core/sessions.py#L324
So to summarize, I think we need to do the following :