Skip to content

Hover actions from extensions, better handling of multiple def providers

Administrator requested to merge hover-actions into master

Created by: sqs

The goal of this PR is to make basic-code-intel an awesome experience when you need go-to-definition, hovers, and find-references when browsing code in any language with no configuration. That means that the initial experience of site admins and users will be much better, because they get to see code intelligence with much less setup required.

This incorporates the codeintellify PR sourcegraph/codeintellify#70. That PR makes it so that codeintellify (which implements our hover tooltip) supports custom actions, instead of hardcoding "Go to definition" and "Find references".

This commit makes the web app (and TODO soon the browser extension) make use of that, so that:

  1. The "Go to definition" and "Find references" actions work in the same way in the web app and browser extension as all other action buttons. This means those actions are no longer hard-coded in a separate library.
  2. These buttons are selectively displayed in a smarter way based on (e.g.) whether there are any registered definition or reference providers for the current document. This fixes the issue where both buttons were always shown if there was a hover, even if the client app knew they would not return anything.
  3. The buttons can do smarter things, like opening up the definition panel if there are multiple definitions (instead of just jumping to the 1st definition).
  4. Extensions can add their own actions to the hover, such as "Find implementations", "Show history" (eg when a func, or calls to a func, were added/removed in Git history), "Show authors", "Show users", "Show stack traces", etc.

(I initially began implementing this so that basic-code-intel could add "Go to definition (fuzzy)" to the hover using (4), but I think that the improvements in (2) and (3) actually make that unnecessary for basic-code-intel. (It's still important to prioritize precise definitions in the panel; that will come soon.) See sourcegraph/sourcegraph-basic-code-intel#9 for the basic-code-intel changes that make use of this new behavior. (Note that there are no new extension APIs added in this PR, just improved handling of what already exists.))

TODOs before merging:

  • Update the browser extension impl code to use this
  • Add more tests to actions.test.ts
  • Fix issue where the input rev is discarded and the absolute commit ID SHA is used
  • Add back logTelemetryEvent for code intel action logging - make HoverOverlay record it

Merge request reports

Loading