diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -222,11 +222,14 @@ const FileEntry *FE = File ? &File->getFileEntry() : nullptr; llvm::StringRef WrittenFilename = llvm::StringRef(Inc.Written).drop_front().drop_back(); - Delegate->InclusionDirective(HashTok->location(), SynthesizedIncludeTok, - WrittenFilename, Inc.Written.front() == '<', - FileTok->range(SM).toCharRange(SM), FE, - "SearchPath", "RelPath", - /*Imported=*/nullptr, Inc.FileKind); + Delegate->InclusionDirective( + HashTok->location(), SynthesizedIncludeTok, WrittenFilename, + Inc.Written.front() == '<', + syntax::FileRange(SM, SynthesizedFilenameTok.getLocation(), + SynthesizedFilenameTok.getEndLoc()) + .toCharRange(SM), + FE, "SearchPath", "RelPath", + /*Imported=*/nullptr, Inc.FileKind); if (File) Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind); else { diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp @@ -361,7 +361,11 @@ : HashOffset(SM.getDecomposedLoc(HashLoc).second), IncTok(IncludeTok), IncDirective(IncludeTok.getIdentifierInfo()->getName()), FileNameOffset(SM.getDecomposedLoc(FilenameRange.getBegin()).second), - FileName(FileName), IsAngled(IsAngled) {} + FileName(FileName), IsAngled(IsAngled) { + EXPECT_EQ( + toSourceCode(SM, FilenameRange.getAsRange()).drop_back().drop_front(), + FileName); + } size_t HashOffset; syntax::Token IncTok; llvm::StringRef IncDirective;