This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Exclude preprocessed-to-nothing tokens from selection
ClosedPublic

Authored by sammccall on Jul 17 2020, 3:16 AM.

Details

Summary

This prevents selection of empty preprocessor entities (like #define directives,or text in disabled sections) creating a selection in the parent element.

Based on D83508 by Aleksandr Platonov.

Diff Detail

Event Timeline

sammccall created this revision.Jul 17 2020, 3:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2020, 3:16 AM
sammccall retitled this revision from [clangd] Exclude preprocessed-to-nothing tokens from selection This prevents selection of empty preprocessor entities (like #define directives, or text in disabled sections) creating a selection in the parent element. to [clangd] Exclude preprocessed-to-nothing tokens from selection.
sammccall edited the summary of this revision. (Show Details)
kadircet accepted this revision.Jul 17 2020, 3:44 AM

LGTM, thanks!

clang-tools-extra/clangd/Selection.cpp
228

nit: reduce nesting via

if(!X.Expanded.empty())
  continue
clang-tools-extra/clangd/unittests/SelectionTests.cpp
564

this case isn't disabled PP, moreover seems to be already tested in CommonAncestor, see:

{
    R"cpp(
      void foo();
      #define CALL_FUNCTION(X) X^()^
      void bar() { CALL_FUNCTION(foo); }
    )cpp",
    nullptr,
},

maybe also put a couple of tests for the macroname and the directive itself? (or just extend the test above to whole directive line?)

578

nit: i am not sure if this is worth it's own test

This revision is now accepted and ready to land.Jul 17 2020, 3:44 AM
sammccall updated this revision to Diff 278717.Jul 17 2020, 4:06 AM
sammccall marked 3 inline comments as done.
sammccall edited the summary of this revision. (Show Details)

address comments

sammccall marked an inline comment as done.Jul 20 2020, 5:52 AM
sammccall added inline comments.
clang-tools-extra/clangd/unittests/SelectionTests.cpp
578

Moved into CommonAncestor tests. (We do need to test it somewhere, that's the point of this patch)

This revision was automatically updated to reflect the committed changes.
kadircet added inline comments.Jul 20 2020, 6:43 AM
clang-tools-extra/clangd/unittests/SelectionTests.cpp
578

sorry I was saying that having a separate TEST fixture wasn't worth it, not the test itself :D