forked from OSchip/llvm-project
[clangd] Fix filename ranges while replaying preamble
Clangd used first token of filename as filename range rather than the synthezied filename token. Unfortunately the former only contains `"` or `<` in the raw lexing mode, resulting in wrong range information and breaking tidy checks that relied on it. Fixes https://github.com/clangd/clangd/issues/896. Differential Revision: https://reviews.llvm.org/D112559
This commit is contained in:
parent
ae27c57b18
commit
e42f5d4b48
|
@ -222,11 +222,14 @@ private:
|
|||
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 {
|
||||
|
|
|
@ -361,7 +361,11 @@ TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) {
|
|||
: 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;
|
||||
|
|
Loading…
Reference in New Issue