This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Ignore sema code complete callback with recovery context.
ClosedPublic

Authored by ioeric on Jul 11 2018, 5:29 AM.

Details

Summary

Sema code complete in the recovery mode is generally useless. For many
cases, sema first completes in recovery context and then recovers to more useful
context, in which it's favorable to ignore results from recovery (as results are
often bad e.g. all builtin symbols and top-level symbols). There is also case
where only sema would fail to recover e.g. completions in excluded #if block.
Sema would try to give results, but the results are often useless (see the updated
excluded #if block test).

Event Timeline

ioeric created this revision.Jul 11 2018, 5:29 AM
sammccall accepted this revision.Jul 11 2018, 5:48 AM

I like this idea, of course hard to know how it will affect all practical cases.

Is it easy to get have internal stats on how many wins/losses this has?

clangd/CodeComplete.cpp
596

might

596

This might also be a case where we can trial identifier-based completion. (Eventually I think we'd want it in other contexts too)

This revision is now accepted and ready to land.Jul 11 2018, 5:48 AM
ioeric updated this revision to Diff 154979.Jul 11 2018, 5:54 AM
ioeric marked 2 inline comments as done.
  • Addressed review comments.
ilya-biryukov accepted this revision.Jul 11 2018, 6:09 AM

Thanks! That's a simple fix that makes things better overall!
LGTM with a NIT about the comment in the test.

unittests/clangd/CodeCompleteTests.cpp
797

NIT.

I would argue the results were actually useful here and we introduced a regression.
This patches fixes the more important cases, e.g. if (int x = id^), so it's actually improving things overall. However, I'm not sure about the comment that says clangd is doing the right thing here (it actually gives a worse UX). WDYT?

I like this idea, of course hard to know how it will affect all practical cases.

Is it easy to get have internal stats on how many wins/losses this has?

This would fix bad completion results when sema could recover to the normal mode (e.g. completion in macros like EXPECT_THAT, expressions in if statements). From the code completion metrics I collected from existing code, the number of completions where no result was found dropped by 30%. The loss seems to be we will get no result in recovery mode rather than bad results (e.g. in excluded preprocessor branches).

This revision was automatically updated to reflect the committed changes.