summaryrefslogtreecommitdiffstats
path: root/source/slang/diagnostics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/diagnostics.cpp')
-rw-r--r--source/slang/diagnostics.cpp60
1 files changed, 42 insertions, 18 deletions
diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp
index 9a88c041d..00205fed3 100644
--- a/source/slang/diagnostics.cpp
+++ b/source/slang/diagnostics.cpp
@@ -199,30 +199,54 @@ static void formatDiagnosticMessage(StringBuilder& sb, char const* format, int a
}
}
+static void formatDiagnostic(const HumaneSourceLoc& humaneLoc, Diagnostic const& diagnostic, StringBuilder& outBuilder)
+{
+ outBuilder << humaneLoc.pathInfo.foundPath;
+ outBuilder << "(";
+ outBuilder << Int32(humaneLoc.line);
+ outBuilder << "): ";
+
+ outBuilder << getSeverityName(diagnostic.severity);
+
+ if (diagnostic.ErrorID >= 0)
+ {
+ outBuilder << " ";
+ outBuilder << diagnostic.ErrorID;
+ }
+
+ outBuilder << ": ";
+ outBuilder << diagnostic.Message;
+ outBuilder << "\n";
+}
+
static void formatDiagnostic(
DiagnosticSink* sink,
- StringBuilder& sb,
- Diagnostic const& diagnostic)
+ Diagnostic const& diagnostic,
+ StringBuilder& sb)
{
auto sourceManager = sink->sourceManager;
- auto humaneLoc = sourceManager->getHumaneLoc(diagnostic.loc);
-
- sb << humaneLoc.pathInfo.foundPath;
- sb << "(";
- sb << Int32(humaneLoc.line);
- sb << "): ";
- sb << getSeverityName(diagnostic.severity);
-
- if( diagnostic.ErrorID >= 0 )
+ SourceView* sourceView = nullptr;
+ HumaneSourceLoc humaneLoc;
+ const auto sourceLoc = diagnostic.loc;
{
- sb << " ";
- sb << diagnostic.ErrorID;
+ sourceView = sourceManager->findSourceViewRecursively(sourceLoc);
+ if (sourceView)
+ {
+ humaneLoc = sourceView->getHumaneLoc(sourceLoc);
+ }
+ formatDiagnostic(humaneLoc, diagnostic, sb);
}
+
+ if (sourceView && (sink->flags & DiagnosticSink::Flag::VerbosePath))
+ {
+ auto actualLoc = sourceView->getHumaneLoc(diagnostic.loc, SourceLocType::Actual);
+ // Look up the full path
+ SourceFile* sourceFile = sourceView->getSourceFile();
+ actualLoc.pathInfo.foundPath = sourceFile->calcVerbosePath();
- sb << ": ";
- sb << diagnostic.Message;
- sb << "\n";
+ formatDiagnostic(actualLoc, diagnostic, sb);
+ }
}
void DiagnosticSink::diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& info, int argCount, DiagnosticArg const* const* args)
@@ -246,7 +270,7 @@ void DiagnosticSink::diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& in
{
// If so, pass the error string along to them
StringBuilder messageBuilder;
- formatDiagnostic(this, messageBuilder, diagnostic);
+ formatDiagnostic(this, diagnostic, messageBuilder);
writer->write(messageBuilder.Buffer(), messageBuilder.Length());
}
@@ -254,7 +278,7 @@ void DiagnosticSink::diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& in
{
// If the user doesn't have a callback, then just
// collect our diagnostic messages into a buffer
- formatDiagnostic(this, outputBuffer, diagnostic);
+ formatDiagnostic(this, diagnostic, outputBuffer);
}
if (diagnostic.severity >= Severity::Fatal)