microsoft / vscode-json-languageservice

JSON language service extracted from VSCode to be reused, e.g in the Monaco editor.
Other
258 stars 109 forks source link

`getInfoContribution` is not composable #221

Open charlespwd opened 6 months ago

charlespwd commented 6 months ago

I'm struggling a little with the JSONWorkerContribution interface to provide smart hover.

From what I can read in jsonHover, it looks like a JSONWorkerContribution.getInfoContribution should return undefined when there's nothing to show (which prevents the use of async function() since it would return Promise).

I'm struggling with two things with this API design:

  1. getInfoContribution(uri, location) does not let me discriminate on if the location is to a property or value node
  2. If getInfoContribution(uri, location) returns something, hover info from the schema is not shown (it's one or the other)

I kind of would like to be able to show both if both have something.

For instance, at Shopify we have those large translation files. It feels like it would make sense to have a getInfoContribution that prints out the translation key of the thing under the cursor ('deep.path.to.key'), but this should only happen on the key and if there's something special from the schema, then I'd probably want that as well.

e.g. keys that end in _html have a special meaning and there's docs associated with them.

charlespwd commented 6 months ago

Problem in context: https://github.com/Shopify/theme-tools/pull/298/files#diff-aea5d250853eb5009b8fb955d459ac55fe2efd48da480d24d05df4654fbe9d14R13-R40