Skip to content

Minor improvements to the new diagnostics formatter #68289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/swift/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ class SourceManager {
SourceLoc();
}

std::string getLineString(unsigned BufferID, unsigned LineNumber);

/// Retrieve the buffer ID for \p Path, loading if necessary.
unsigned getExternalSourceBufferID(StringRef Path);

Expand Down
5 changes: 0 additions & 5 deletions include/swift/Frontend/PrintingDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "llvm/Support/Process.h"

namespace swift {
class AnnotatedSourceSnippet;

/// Diagnostic consumer that displays diagnostics to standard error.
class PrintingDiagnosticConsumer : public DiagnosticConsumer {
Expand All @@ -38,10 +37,6 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
bool DidErrorOccur = false;
DiagnosticOptions::FormattingStyle FormattingStyle =
DiagnosticOptions::FormattingStyle::LLVM;
// The current snippet used to display an error/warning/remark and the notes
// implicitly associated with it. Uses `std::unique_ptr` so that
// `AnnotatedSourceSnippet` can be forward declared.
std::unique_ptr<AnnotatedSourceSnippet> currentSnippet;
// Educational notes which are buffered until the consumer is finished
// constructing a snippet.
SmallVector<std::string, 1> BufferedEducationalNotes;
Expand Down
30 changes: 16 additions & 14 deletions lib/ASTGen/Sources/ASTGen/Diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ fileprivate func emitDiagnosticParts(
let bridgedDiagEngine = BridgedDiagnosticEngine(raw: diagEnginePtr)

// Map severity
let bridgedSeverity: BridgedDiagnosticSeverity
switch severity {
case .error: bridgedSeverity = .error
case .note: bridgedSeverity = .note
case .warning: bridgedSeverity = .warning
}
let bridgedSeverity = severity.bridged

func bridgedSourceLoc(at position: AbsolutePosition) -> BridgedSourceLoc {
return BridgedSourceLoc(at: position, in: sourceFileBuffer)
Expand Down Expand Up @@ -119,6 +114,18 @@ func emitDiagnostic(
}
}

extension DiagnosticSeverity {
var bridged: BridgedDiagnosticSeverity {
switch self {
case .error: return .error
case .note: return .note
case .warning: return .warning
case .remark: return .remark
@unknown default: return .error
}
}
}

extension SourceManager {
private func diagnoseSingle<Node: SyntaxProtocol>(
message: String,
Expand All @@ -129,12 +136,7 @@ extension SourceManager {
fixItChanges: [FixIt.Change] = []
) {
// Map severity
let bridgedSeverity: BridgedDiagnosticSeverity
switch severity {
case .error: bridgedSeverity = .error
case .note: bridgedSeverity = .note
case .warning: bridgedSeverity = .warning
}
let bridgedSeverity = severity.bridged

// Emit the diagnostic
var mutableMessage = message
Expand Down Expand Up @@ -292,7 +294,7 @@ extension BridgedDiagnosticSeverity {
case .fatalError: return .error
case .error: return .error
case .warning: return .warning
case .remark: return .warning // FIXME
case .remark: return .remark
case .note: return .note
@unknown default: return .error
}
Expand Down Expand Up @@ -443,7 +445,7 @@ public func addQueuedDiagnostic(

/// Render the queued diagnostics into a UTF-8 string.
@_cdecl("swift_ASTGen_renderQueuedDiagnostics")
public func renterQueuedDiagnostics(
public func renderQueuedDiagnostics(
queuedDiagnosticsPtr: UnsafeMutablePointer<UInt8>,
contextSize: Int,
colorize: Int,
Expand Down
2 changes: 2 additions & 0 deletions lib/ASTGen/Sources/ASTGen/PluginHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class PluginDiagnosticsEngine {
case .error: bridgedSeverity = .error
case .note: bridgedSeverity = .note
case .warning: bridgedSeverity = .warning
case .remark: bridgedSeverity = .remark
@unknown default: bridgedSeverity = .error
}

// Emit the diagnostic
Expand Down
Loading