This is an archive of the discontinued LLVM Phabricator instance.

[CodeComplete] Fix completion at the end of keywords
ClosedPublic

Authored by ilya-biryukov on Apr 20 2018, 9:48 AM.

Details

Summary

Make completion behave consistently no matter if it is run at the
start, in the middle or at the end of an identifier that happens to
be a keyword or a macro name. Since completion is often ran on
incomplete identifiers, they may turn into keywords by accident.

For example, we should produce same results for all of these
completion points:

// ^ is completion point.
^class
cla^ss
class^

Previously clang produced different results for the last case (as if
the completion point was after a space: class ^).

This change also updates some offsets in tests that (unintentionally?)
relied on the old behavior.

Diff Detail

Repository
rL LLVM

Event Timeline

ilya-biryukov created this revision.Apr 20 2018, 9:48 AM
sammccall accepted this revision.Apr 24 2018, 2:04 AM

Nice! I'm a little surprised that this wasn't fixed before, so I'm worried I missing something.
But nobody else has reviewed it, and it really seems right (and the test cases you fixed did seem broken). We can always revert :)

lib/Lex/Lexer.cpp
1647 ↗(On Diff #143335)

move this down to where it's used - it's ignored for CC

1649 ↗(On Diff #143335)

maybe this deserves a comment describing exactly this change, something like:

If the completion point is at the end of an identifier, we want to treat it as incomplete even if it
is valid. This allows e.g. class^ to complete to classifier.

test/CodeCompletion/end-of-ident-macro.cpp
3 ↗(On Diff #143335)

nit: remove this blank line?

6 ↗(On Diff #143335)

Maybe add a comment above this line:

We should get all three completions when the cursor is at the beginning, middle, or end.

(I know documenting the intent of lit tests seems to not be fashionable, but... :-)

This revision is now accepted and ready to land.Apr 24 2018, 2:04 AM
ilya-biryukov marked 3 inline comments as done.
  • Added comments
  • Fix nits in tests
lib/Lex/Lexer.cpp
1647 ↗(On Diff #143335)

It actually updates Result too!
And things break if we don't call it. Added a comment.

This revision was automatically updated to reflect the committed changes.