Handle empty source strings in SourceReferenceExtractor

This commit is contained in:
Daniel Kirchner 2020-01-09 14:18:54 +01:00
parent 17158995b5
commit 03c70f45d6
2 changed files with 5 additions and 1 deletions

View File

@ -46,6 +46,9 @@ SourceReference SourceReferenceExtractor::extract(SourceLocation const* _locatio
if (!_location || !_location->source.get()) // Nothing we can extract here if (!_location || !_location->source.get()) // Nothing we can extract here
return SourceReference::MessageOnly(std::move(message)); return SourceReference::MessageOnly(std::move(message));
if (_location->source->source().empty()) // No source text, so we can only extract the source name
return SourceReference::MessageOnly(std::move(message), _location->source->name());
shared_ptr<CharStream> const& source = _location->source; shared_ptr<CharStream> const& source = _location->source;
LineColumn const interest = source->translatePositionToLineColumn(_location->start); LineColumn const interest = source->translatePositionToLineColumn(_location->start);

View File

@ -49,10 +49,11 @@ struct SourceReference
int endColumn = {-1}; ///< Highlighting range-end of text field. int endColumn = {-1}; ///< Highlighting range-end of text field.
/// Constructs a SourceReference containing a message only. /// Constructs a SourceReference containing a message only.
static SourceReference MessageOnly(std::string _msg) static SourceReference MessageOnly(std::string _msg, std::string _sourceName = {})
{ {
SourceReference sref; SourceReference sref;
sref.message = std::move(_msg); sref.message = std::move(_msg);
sref.sourceName = std::move(_sourceName);
return sref; return sref;
} }
}; };