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

Says MessageActionItem additionalPropertiesSupport is true, but not seeing the properties #614

Open
tjpalmer opened this issue May 10, 2022 · 5 comments

Comments

@tjpalmer
Copy link

For MessageActionItem, LSP and lsp4j support the additionalPropertiesSupport indicator.

https://github.com/eclipse/lsp4j/blob/c0eaa1837900fcac5f0a991b3a33a26c6ed160b6/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend#L1773

I'm trying to use it to disambiguate choices, and I've subclassed MessageActionItem for my outgoing items as seen in this trace:

[Trace - 06:40:43 AM] Sending request 'window/showMessageRequest - (2)'
Params: {
  "actions": [
    {
      "value": "",
      "title": "notes/"
    },
    {
      "value": "yodel",
      "title": "yodel/"
    },
    {
      "value": "yodel/monkey",
      "title": "monkey/"
    },
    {
      "value": "yodel/monkey/yodel",
      "title": "yodel/"
    }
  ],
  "type": 2,
  "message": "Choose a folder."
}

[Trace - 06:40:46 AM] Received response 'window/showMessageRequest - (2)' in 2161ms
Result: {
  "title": "yodel/"
}

I expect to see the "value" field back as well. And I'm not sure if vscode isn't sending it (in which case maybe my fault) or if lsp4j is converting to MessageActionItem and then logging the equivalent json. And I haven't found a way to customize the return type in lsp4j.

And vscode seems to claim to support this feature based on earlier in the trace logs:

      "showMessage": {
        "messageActionItem": {
          "additionalPropertiesSupport": true
        }
      },

Is it possible this issue is in lsp4j, and if so, is there a way to get back the additional properties?

@tjpalmer
Copy link
Author

One of my questions is that I'm unsure if the "Result" trace above is the pure response or if it's a re-jsonification of the created MessageActionItem object.

@pisv
Copy link
Contributor

pisv commented May 11, 2022

LSP4J does not (cannot) support additional properties for MessageActionItem OOTB. By default, GSON deserialization will just create an instance of MessageActionItem and not of your subclass, so all of the additional properties get lost.

I think you need to use one of createIoLauncher methods in org.eclipse.lsp4j.jsonrpc.Launcher that allow you to get access to a GsonBuilder and then register a type adapter for MessageActionItem that would return an instance of your subclass. See https://futurestud.io/tutorials/gson-advanced-custom-deserialization-basics for more information on this topic.

@tjpalmer
Copy link
Author

🙏 Thanks much for the tips! I'll look that direction.

One other thing I tried doing was making my own custom method to send the same message to the client, but then it complained I had two methods with the same message type registered. Not sure if there's any way lsp4j could allow that and coordinate the response.

@pisv
Copy link
Contributor

pisv commented May 11, 2022

One other thing I tried doing was making my own custom method to send the same message to the client, but then it complained I had two methods with the same message type registered. Not sure if there's any way lsp4j could allow that and coordinate the response.

I don't think it is supported.

@KamasamaK
Copy link
Contributor

KamasamaK commented Jul 20, 2022

This was an unfortunate choice for LSP. I opened microsoft/language-server-protocol#1471 but I'm not sure when it will be addressed.

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

3 participants