This is an archive of the discontinued LLVM Phabricator instance.

[clangd][VSCode] Force VSCode to use the ranking provided by clangd.
ClosedPublic

Authored by sammccall on Mar 4 2020, 9:38 AM.

Details

Summary

Clangd's approach is to provide lots of completions, and let ranking sort them
out. This relies on various important signals (Quality.h), without which the
large completion lists are extremely spammy.

Even with a completion result exactly at the cursor, vscode looks backwards and
tries to match the presumed partial-identifier against filterText, and uses
the result to rank, with sortText only used as a tiebreak.
By prepending the partial-identifier to the filterText, we can force the match
to be perfect and so give sortText full control of the ranking.

It's possible to do this on the server side too of course, and switch it on
with an initialization option. But it's a little easier in the extension, it
will get the fix to users of old clangd versions, and other editors

Diff Detail

Event Timeline

sammccall created this revision.Mar 4 2020, 9:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2020, 9:38 AM

I tested this with an example like:

int a_b_c;
char *abc;
int x = ab^ // prefer a_b_c due to type match.

before this patch, we see [abc, a_b_c]. After this patch, [a_b_c, abc].

hokein added a comment.Mar 5 2020, 6:32 AM

thanks for fixing that! Played around it locally, it seems work, found an issue where the global code completion is not triggered, see my comment.

clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
116

the word is undefined if we trigger the global code completion, e.g. ^, std::^.

124

nit: /*isInComplete=*/true

sammccall updated this revision to Diff 248497.Mar 5 2020, 8:52 AM
sammccall marked 2 inline comments as done.

address review comments

hokein accepted this revision.Mar 6 2020, 3:54 AM
This revision is now accepted and ready to land.Mar 6 2020, 3:54 AM
This revision was automatically updated to reflect the committed changes.