Underline the entire token when producing diagnostic messages. (#3413)

This is an incremental improvement on our diagnostic messages that
simply underlines an entire token if the token is larger than 1 char
(else it points to the single char with a caret like it used to).
This commit is contained in:
Jacob Schneider
2023-11-27 16:36:26 +00:00
committed by GitHub
parent 437b5e60d6
commit 1d443a3617
98 changed files with 270 additions and 230 deletions
+6 -2
View File
@@ -12,6 +12,7 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatVariadic.h"
#include "toolchain/base/value_store.h"
#include "toolchain/diagnostics/diagnostic_emitter.h"
#include "toolchain/lex/character_set.h"
#include "toolchain/lex/numeric_literal.h"
#include "toolchain/lex/string_literal.h"
@@ -377,8 +378,11 @@ auto TokenLocationTranslator::GetLocation(Token token) -> DiagnosticLocation {
// Find the corresponding file location.
// TODO: Should we somehow indicate in the diagnostic location if this token
// is a recovery token that doesn't correspond to the original source?
return TokenizedBuffer::SourceBufferLocationTranslator(buffer_).GetLocation(
token_start);
DiagnosticLocation loc =
TokenizedBuffer::SourceBufferLocationTranslator(buffer_).GetLocation(
token_start);
loc.length = buffer_->GetTokenText(token).size();
return loc;
}
} // namespace Carbon::Lex