sourcegraph / sourcegraph-public-snapshot

Code AI platform with Code Search & Cody
https://sourcegraph.com
Other
10.12k stars 1.29k forks source link

Improve code intelligence reliability #32294

Open macraig opened 2 years ago

macraig commented 2 years ago

Goal

Improve user quality of life by making code intelligence more predictable.

Problem

We've had a lot of discussions (and tickets and Slack threads) over the years on how users have a hard time anticipating if and when a hover tooltip will show and whether it will contain useful information.

Users don't know what to expect or why things happened the way they did. Unsure whether tooltip didn't show up because of network problems, or because there never will be hover tooltip on that token (some tokens don't have hovers and that's completely fine), or because no data is available (search-based is indexing in background, no LSIF dump uploaded), etc.

Documented issues

github-actions[bot] commented 2 years ago

Heads up @macraig - the "team/code-intelligence" label was applied to this issue.

mrnugget commented 2 years ago

Cross-linking this issue here for API implementation: https://github.com/sourcegraph/sourcegraph/issues/31071

mrnugget commented 2 years ago

Here's another thing that makes it feel unrealiable: we do have some weird double-renders sometimes (I suspect that this stray ?References GraphQL query has something to do with it):

https://user-images.githubusercontent.com/1185253/157445115-c638b89f-ec5b-4afe-bf2a-861bf6d78282.mp4

mrnugget commented 2 years ago

I dug into this today, trying to see how hard it would be to add a "No results" in the hover if we can't find anything. I'd prefer that over seeing a spinner and the tooltip then disappearing.

Some findings:

  1. We only show the spinner after 600ms. That can lead to some rather tricky behaviour: if the first request is slow and doesn't find results, you'll see a spinner and then the hover disappears. If you then hover over the token again, the response from the previous request is cached, which means it'll not cross the 600ms, which means you won't see the spinner or a hover tooltip again. https://github.com/sourcegraph/sourcegraph/blob/93eebb8b847a92675b181fd34cef8501f0b2ea06/client/codeintellify/src/hoverifier.ts#L345-L346
  2. Our code contains some (really old) logic to display "nothing found" when there is no result: https://github.com/sourcegraph/sourcegraph/blob/93eebb8b847a92675b181fd34cef8501f0b2ea06/client%2Fshared%2Fsrc%2Fhover%2FHoverOverlayContents%2FHoverOverlayContents.tsx#L54-L59
  3. That code is never triggered, because the hover overlay hides the hover if there is no cursor position provided: https://github.com/sourcegraph/sourcegraph/blob/93eebb8b847a92675b181fd34cef8501f0b2ea06/client%2Fshared%2Fsrc%2Fhover%2FHoverOverlay.tsx#L63-L74
  4. On the other end of things we have some code that also decides when to render a hover tooltip and when not. And if it doesn't have content for the hover (but maybe actions?) then it doesn't return anything, which means it doesn't return a position, which leads to code in (2) not being shown, due to (3). https://github.com/sourcegraph/sourcegraph/blob/93eebb8b847a92675b181fd34cef8501f0b2ea06/client%2Fcodeintellify%2Fsrc%2Fhoverifier.ts#L308-L319
  5. I changed the logic in (4) to always return the position, even if there is no hover content and now we can see the "No results found" content:

https://user-images.githubusercontent.com/1185253/157459009-0211fb15-1337-4bd2-bd2e-4ed6100edda6.mp4

  1. The problem: we don't distinguish between "no result found and we'll never find a result for a token like this (whitespace, parentheses, ...)" and "no result found, but maybe with precise", which leads to the "no results found" showing up on every empty line and on every token, including keywords.
macraig commented 2 years ago

Pulled these out in issues https://github.com/sourcegraph/sourcegraph/issues/33557 and https://github.com/sourcegraph/sourcegraph/issues/33558

vdavid commented 2 years ago

Bug report (copied from Slack):

Problem: I’m trying to go to the definition of a Java class. When I hover over the class name, the code intel popup shows a progress indicator, then disappears after a few secs. 34-sec Loom Solution suggestion: I’d be happier with even a simple “No definition or references found” message than with the silently disappearing box. The error message would indicate to me that there is no bug in the UI, just no data was found. With the current state, I have no clue if it’s a UI error, a backend error, or just no data found. If we want to make it super cool, we could check the file type and be more specific, e.g. tell the user additional context like “This is a Kotlin file, and your definition might be in Java. We currently don’t have a cross-language association for Kotlin and Java, but it’s on our roadmap to add it.”