Skip to content
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

Improve default diagnostic formatter #535

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
128c7f0
Improve default diagnostic formatter
arthurcro Mar 28, 2023
f5e90e2
Fix suggestion display ordering
arthurcro Apr 15, 2023
0897174
Highlight output only when connected to termnial
arthurcro Apr 19, 2023
4568572
Highlight diagnostic summary only when connected to terminal
arthurcro Apr 22, 2023
eb98dc7
Fix exisiting tests to use tools output formatting option
arthurcro Apr 22, 2023
2b9d1a8
Add default diagnostic formatting tests
arthurcro Apr 23, 2023
2536b61
Relocate default diagnostic formatting test to a separate file
arthurcro May 10, 2023
51fa1eb
Remove URL force unwrapping
arthurcro May 10, 2023
add872b
Refactor formatted description for diagnostic
arthurcro May 10, 2023
fd50fc3
Refactor suggestion grouping
arthurcro May 10, 2023
25468c7
Remove redundant ANSIAnnotation color reset
arthurcro May 10, 2023
40a4384
Improve suggestion vertical alignment prefix
arthurcro May 10, 2023
6e1d037
Revert public initializer changes
arthurcro May 10, 2023
57792a7
Clean up source lines after writing the diagnostics
arthurcro May 10, 2023
fe9beef
Improve inline documentation
arthurcro May 10, 2023
aa171a6
Clean up source lines cache after all diagnostics have been formatted
arthurcro May 16, 2023
b2b438d
Improve C import
arthurcro Jul 7, 2023
01d65d7
Merge branch 'main' into arthurcro/default-diagnostic-readability-imp…
arthurcro Jul 7, 2023
8f6d042
Revert whitespace change
arthurcro Jul 7, 2023
8d4d5d9
Revert "Revert public initializer changes"
arthurcro Jul 11, 2023
7c7e99f
Merge branch 'main' into arthurcro/default-diagnostic-readability-imp…
d-ronnqvist Jul 13, 2023
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
57 changes: 57 additions & 0 deletions Sources/SwiftDocC/Infrastructure/Diagnostics/ANSIAnnotation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Foundation

struct ANSIAnnotation {
enum Color: UInt8 {
case normal = 0
case red = 31
case green = 32
case yellow = 33
case `default` = 39
}

enum Trait: UInt8 {
case normal = 0
case bold = 1
case italic = 3
}

private var color: Color
private var trait: Trait

/// The textual representation of the annotation.
private var code: String {
"\u{001B}[\(trait.rawValue);\(color.rawValue)m"
}

init(color: Color, trait: Trait = .normal) {
self.color = color
self.trait = trait
}

func applied(to message: String) -> String {
"\(code)\(message)\(ANSIAnnotation.normal.code)"
}

static var normal: ANSIAnnotation {
self.init(color: .normal, trait: .normal)
}

/// Annotation used for highlighting source text.
static var sourceHighlight: ANSIAnnotation {
ANSIAnnotation(color: .green, trait: .bold)
}
/// Annotation used for highlighting source suggestion.
static var sourceSuggestionHighlight: ANSIAnnotation {
ANSIAnnotation(color: .default, trait: .bold)
}
}
Loading