Replace uses of presumed locations where they do not make sense

Various uses of `getPresumedLineAndColumnForLoc` were likely added when
that function was the very misleading name `getLineAndColumn`. Change
these to use `getLineAndColumnForBuffer` instead where appropriate, ie.
we want the underlying file rather than the location to display to the
user.

There were also some cases where the buffer identifier had been swapped
to use the display name instead, under the assumption that the presumed
location was needed. Updated those as well.

SingleRawComment: Lines are only used when merging comments, where the
original location is fine to use.

Index: Doesn't store the file set in #sourceLocation, so using the
presumed line would end up pointing to a location that makes no sense.

Editor functionality: Formatting and refactoring are on the current
file. Using the presumed location would result in incorrect
replacements.
This commit is contained in:
Ben Barham
2021-04-08 10:17:48 +10:00
parent cb6b1ea07b
commit 20f45ec284
13 changed files with 54 additions and 28 deletions

View File

@@ -340,7 +340,7 @@ void swift::simple_display(llvm::raw_ostream &out, const CursorInfoOwner &owner)
return;
auto &SM = owner.File->getASTContext().SourceMgr;
out << SM.getIdentifierForBuffer(*owner.File->getBufferID());
auto LC = SM.getPresumedLineAndColumnForLoc(owner.Loc);
auto LC = SM.getLineAndColumnInBuffer(owner.Loc);
out << ":" << LC.first << ":" << LC.second;
}
@@ -351,7 +351,7 @@ void swift::ide::simple_display(llvm::raw_ostream &out,
out << "Resolved cursor info at ";
auto &SM = info.SF->getASTContext().SourceMgr;
out << SM.getIdentifierForBuffer(*info.SF->getBufferID());
auto LC = SM.getPresumedLineAndColumnForLoc(info.Loc);
auto LC = SM.getLineAndColumnInBuffer(info.Loc);
out << ":" << LC.first << ":" << LC.second;
}
@@ -1072,8 +1072,8 @@ void swift::simple_display(llvm::raw_ostream &out,
return;
auto &SM = owner.File->getASTContext().SourceMgr;
out << SM.getIdentifierForBuffer(*owner.File->getBufferID());
auto SLC = SM.getPresumedLineAndColumnForLoc(owner.StartLoc);
auto ELC = SM.getPresumedLineAndColumnForLoc(owner.EndLoc);
auto SLC = SM.getLineAndColumnInBuffer(owner.StartLoc);
auto ELC = SM.getLineAndColumnInBuffer(owner.EndLoc);
out << ": (" << SLC.first << ":" << SLC.second << ", "
<< ELC.first << ":" << ELC.second << ")";
}