Skip to content

Commit 7d7a8d3

Browse files
committed
[SymbolGraph] Don't trim comment segments past the first nonspace offset
Otherwise, the `SourceManager` may skip over a blank line, causing it to have a line number off by one. Measure initial indentation from the first non-blank line. rdar://61827368
1 parent ed28d8b commit 7d7a8d3

File tree

3 files changed

+823
-3
lines changed

3 files changed

+823
-3
lines changed

lib/SymbolGraphGen/Symbol.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,25 @@ void Symbol::serializeDocComment(llvm::json::OStream &OS) const {
175175

176176
OS.attributeObject("docComment", [&](){
177177
auto LL = Graph->Ctx.getLineList(RC);
178-
size_t InitialIndentation = LL.getLines().empty()
178+
StringRef FirstNonBlankLine;
179+
for (const auto &Line : LL.getLines()) {
180+
if (!Line.Text.empty()) {
181+
FirstNonBlankLine = Line.Text;
182+
break;
183+
}
184+
}
185+
size_t InitialIndentation = FirstNonBlankLine.empty()
179186
? 0
180-
: markup::measureIndentation(LL.getLines().front().Text);
187+
: markup::measureIndentation(FirstNonBlankLine);
181188
OS.attributeArray("lines", [&](){
182189
for (const auto &Line : LL.getLines()) {
183190
// Line object
184191
OS.object([&](){
185192
// Trim off any initial indentation from the line's
186193
// text and start of its source range, if it has one.
187194
if (Line.Range.isValid()) {
188-
serializeRange(InitialIndentation,
195+
serializeRange(std::min(InitialIndentation,
196+
Line.FirstNonspaceOffset),
189197
Line.Range, Graph->M.getASTContext().SourceMgr, OS);
190198
}
191199
auto TrimmedLine = Line.Text.drop_front(std::min(InitialIndentation,

0 commit comments

Comments
 (0)