This is an archive of the discontinued LLVM Phabricator instance.

[clang] Give priority to Class context while parsing declarations
ClosedPublic

Authored by furkanusta on Jul 22 2022, 7:47 AM.

Diff Detail

Event Timeline

furkanusta created this revision.Jul 22 2022, 7:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2022, 7:47 AM
furkanusta requested review of this revision.Jul 22 2022, 7:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2022, 7:47 AM
nridge added a subscriber: nridge.Jul 23 2022, 11:46 PM

Can you also add a test, preferably in clang/test/CodeCompletion/overrides.cpp ?

clang/lib/Parse/ParseDecl.cpp
3269–3270

i think the importance of ordering requires a comment here, maybe something like:
Class context can appear inside a function/block, so prioritise that.

  • [clang] Add test case for D130363

I've added a test case but I have a question.
This is regardless of the current issue (i.e. no function context, clang++14 with no patches)

struct X {
virtual void foo();
};
struct Y : public X {
over
};

I am trying to complete override in class Y here, but I get no result.
The command I am using is:
clang++ -cc1 -xc++ -code-completion-patterns -fsyntax-only -code-completion-at="test.cpp:5:2" test.cpp
The only output I get is: COMPLETION: operator
If I start the completion at the first column I receive the correct result.
Is my invocation correct or is this case handled by clangd and not clang?

Is my invocation correct or is this case handled by clangd and not clang?

yeah your invocation is correct. this is because clang's printer does a prefix based filtering (while clangd does a fuzzy match) https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/CodeCompleteConsumer.cpp#L623.

clang/test/CodeCompletion/overrides.cpp
36

no need for -code-completion-patterns. can you also move the new test case below (after CHECK-CC3-NOT) that way we get to keep the line numbers for old tests the same.

  • [clangd] D130363 (CodeCompletion/overrides.cpp) Move tests to bottom
kadircet accepted this revision.Aug 11 2022, 4:23 AM

thanks, lgtm! let me know if i should land this for you.

This revision is now accepted and ready to land.Aug 11 2022, 4:23 AM
furkanusta marked an inline comment as not done.Aug 11 2022, 5:53 AM

That would be great, thanks

clang/test/CodeCompletion/overrides.cpp
36

I put the test in between because anything after vf on line 14 gives an error.

error: unknown type name 'vf'

vf
^

It still outputs the correct completions but since the return code is non-zero, FileCheck fails

36

I've found from one of the others tests it is possible to invert the return code from clang.
This way I was able to move the newly added test to bottom.