extensibility: deduplicate panel menu items
Created by: tjkandala
close #23393 (closed).
Code intel extensions contribute the "Mix precise and search-based results" (and for "Show other repositories" for TypeScript/Go) action to the references panel.
The problem is that there's no id
property on MenuItemContribution
, so we can't cleanly deduplicate these menu items as users navigate between files of different languages; we can't determine that they're intended to be the same menu item. We can most safely assume that they're the same menu item when all properties are identical.
This PR adds a band-aid solution* of deduplicating only panel menu items. We serialize panel menu items in one pass, then parse unique strings into menu items. I thought about doing deep equality checks for all the panel menu item objects, but that would run in quadratic time in the worst case. I also thought about adding this logic in the extension host so that , but 1) it would run way too often for e.g. hover actions, and 2) this is a temporary solution. We should look into applying memoization to context computation, but this may be tough given structured cloning etc.
Desired longer term solution is for code intel extensions to add language checks to when
so the panel only shows code intel panel menu items for the active editor, which depends on adding activeEditor
info to context when scope
isn't an editor). This is blocked by extension versioning issues. Adding an identifier that isn't in context for older versions of Sourcegraph would make menu items never show up. We can explore this solution once we have a versioning system that loads the latest compatible extension by default.
We can also add id
to MenuItemContribution
, but it's not desirable to give extension authors yet another thing to name. If people think this is reasonable, I think we could add this without many issues with regards to backwards compatibility.
*why a band-aid? Most extensions won't run into this problem. It's only because code intel extensions have essentially the same manifest, but loaded once for each language.