Skip to content

Commit

Permalink
[clangd] Use the macro name range as the definition range.
Browse files Browse the repository at this point in the history
Summary: This also aligns with the behavior of declarations.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

Differential Revision: https://reviews.llvm.org/D44423

llvm-svn: 327401
  • Loading branch information
hokein committed Mar 13, 2018
1 parent de18d3e commit 0259e7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions clang-tools-extra/clangd/XRefs.cpp
Expand Up @@ -219,9 +219,8 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos) {
}

for (auto Item : MacroInfos) {
SourceRange SR(Item.Info->getDefinitionLoc(),
Item.Info->getDefinitionEndLoc());
auto L = makeLocation(AST, SR);
auto Loc = Item.Info->getDefinitionLoc();
auto L = makeLocation(AST, SourceRange(Loc, Loc));
if (L)
Result.push_back(*L);
}
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/unittests/clangd/XRefsTests.cpp
Expand Up @@ -207,15 +207,15 @@ TEST(GoToDefinition, All) {

R"cpp(// Macro
#define MACRO 0
#define [[MACRO 1]]
#define [[MACRO]] 1
int main() { return ^MACRO; }
#define MACRO 2
#undef macro
)cpp",

R"cpp(// Macro
class TTT { public: int a; };
#define [[FF(S) if (int b = S.a) {}]]
#define [[FF]](S) if (int b = S.a) {}
void f() {
TTT t;
F^F(t);
Expand Down

0 comments on commit 0259e7d

Please sign in to comment.