codespan-reporting-0.11.1/.cargo_vcs_info.json 0000644 00000000112 00000000000 0014710 0 ustar {
"git": {
"sha1": "fd389a13f5bb6d625b71e2e4694b26e127f393f9"
}
}
codespan-reporting-0.11.1/CHANGELOG.md 0000644 0000000 0000000 00000033613 00000000000 0015303 0 ustar 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.11.1] - 2021-01-18
### Added
- Add `Chars::{box_drawing, ascii}` functions, the latter supporting a rustc-style of
output that only uses ASCII characters (not above U+007F) for use cases that do not allow
for box drawing characters, e.g. terminals that do not support them.
### Changed
- `Diagnostic::with_labels` and `Diagnostic::with_notes` now append additional
labels rather tan overwriting them, meaning that the documentation and behaviour match
more closely. The behaviour will only differ if you call the same builder methods
multiple times. If you call every builder method once only, nothing should change.
- `config::Chars::snippet_start` is now a String instead of a single `char`.
## [0.11.0] - 2020-11-30
There is now a [code of conduct](https://github.com/brendanzab/codespan/blob/master/CODE_OF_CONDUCT.md)
and a [contributing guide](https://github.com/brendanzab/codespan/blob/master/CONTRIBUTING.md).
Some versions were skipped to sync up with the `codespan-lsp` crate. The release
process has been changed so this should not happen again.
### Added
- If a label spans over multiple lines, not all lines are rendered.
The number of lines rendered at beginning and end is configurable separately.
- There is now a custom error type.
- There now is a medium rendering mode that is like the short rendering mode
but also shows notes from the diagnostic.
- `PartialEq` and `Eq` implementations for the `diagnostic::{Diagnostic, Label, Severity}` types.
### Changed
- All errors now use the error type `codespan_reporting::file::Error`.
This type also replaces the custom error type for `codespan-lsp`.
### Fixed
- Empty error codes are not rendered.
- The locus ("location of the diagnostic") is now computed so it is always at the first
primary label, or at the first secondary label if no primary labels are available.
- All `unwrap`s outside of tests and examples have been removed.
- Some internal improvements, including various code style improvements by using Clippy.
- Improved documentation, also mentioning how the ordering of labels is handled.
## [0.9.5] - 2020-06-24
### Changed
- Sections of source code that are marked with primary labels are now rendered
using the primary highlight color.
- Tab stops are now rendered properly.
We used to just render `\t` characters in source snippets with the same
number of spaces.
Example
For example, when rendering with a tab width of `3` we
would print:
```text
warning: tab test
┌─ tab_columns:1:2
│
1 │ hello
│ ^^^^^
2 │ ∙ hello
│ ^^^^^
3 │ ∙∙ hello
│ ^^^^^
4 │ ∙∙∙ hello
│ ^^^^^
5 │ ∙∙∙∙ hello
│ ^^^^^
6 │ ∙∙∙∙∙ hello
│ ^^^^^
7 │ ∙∙∙∙∙∙ hello
│ ^^^^^
```
Now we properly take into account the column of the tab character:
```text
warning: tab test
┌─ tab_columns:1:2
│
1 │ hello
│ ^^^^^
2 │ ∙ hello
│ ^^^^^
3 │ ∙∙ hello
│ ^^^^^
4 │ ∙∙∙ hello
│ ^^^^^
5 │ ∙∙∙∙ hello
│ ^^^^^
6 │ ∙∙∙∙∙ hello
│ ^^^^^
7 │ ∙∙∙∙∙∙ hello
│ ^^^^^
```
## [0.9.4] - 2020-05-18
### Changed
- We have made the caret rendering easier to read when there are multiple
labels on the same line. We also avoid printing trailing borders on the
final source source snippet if no notes are present.
Example
Instead of this:
```text
┌─ one_line.rs:3:5
│
3 │ v.push(v.pop().unwrap());
│ - first borrow later used by call
│ ---- first mutable borrow occurs here
│ ^ second mutable borrow occurs here
│
```
…we now render the following:
```text
┌─ one_line.rs:3:5
│
3 │ v.push(v.pop().unwrap());
│ - ---- ^ second mutable borrow occurs here
│ │ │
│ │ first mutable borrow occurs here
│ first borrow later used by call
```
### Fixed
- Diagnostic rendering no longer panics if label ranges are between UTF-8
character boundaries.
## [0.9.3] - 2020-04-29
### Changed
- Some panics were fixed when invalid unicode boundaries are supplied.
- Labels that marked the same span were originally rendered in reverse order.
This was a mistake! We've now fixed this.
Example
For example, this diagnostic:
```text
┌─ same_range:1:7
│
1 │ ::S { }
│ - Expected '('
│ ^ Unexpected '{'
│
```
…will now be rendered as:
```text
┌─ same_range:1:7
│
1 │ ::S { }
│ ^ Unexpected '{'
│ - Expected '('
│
```
- We've reduced the prominence of the 'locus' on source snippets by
simplifying the border and reducing the spacing around it. This is to help
focus attention on the underlined source snippet and error messages, rather
than the location, which should be a secondary focus.
Example
For example we originally rendered this:
```text
error: unknown builtin: `NATRAL`
┌── Data/Nat.fun:7:13 ───
│
7 │ {-# BUILTIN NATRAL Nat #-}
│ ^^^^^^ unknown builtin
│
= there is a builtin with a similar name: `NATURAL`
```
…and now we render this:
```text
error: unknown builtin: `NATRAL`
┌─ Data/Nat.fun:7:13
│
7 │ {-# BUILTIN NATRAL Nat #-}
│ ^^^^^^ unknown builtin
│
= there is a builtin with a similar name: `NATURAL`
```
## [0.9.2] - 2020-03-29
### Changed
- Render overlapping multiline marks on the same lines of source code.
Example
For example:
```text
error[E0308]: match arms have incompatible types
┌── codespan/src/file.rs:1:9 ───
│
1 │ ╭ match line_index.compare(self.last_line_index()) {
2 │ │ Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),
3 │ │ Ordering::Equal => Ok(self.source_span().end()),
4 │ │ Ordering::Greater => LineIndexOutOfBoundsError {
5 │ │ given: line_index,
6 │ │ max: self.last_line_index(),
7 │ │ },
8 │ │ }
│ ╰─────────' `match` arms have incompatible types
·
2 │ Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),
│ --------------------------------------------- this is found to be of type `Result`
3 │ Ordering::Equal => Ok(self.source_span().end()),
│ ---------------------------- this is found to be of type `Result`
4 │ Ordering::Greater => LineIndexOutOfBoundsError {
│ ╭──────────────────────────────────^
5 │ │ given: line_index,
6 │ │ max: self.last_line_index(),
7 │ │ },
│ ╰─────────────^ expected enum `Result`, found struct `LineIndexOutOfBoundsError`
│
= expected type `Result`
found type `LineIndexOutOfBoundsError`
```
…is now rendered as:
```text
error[E0308]: match arms have incompatible types
┌── codespan/src/file.rs:1:9 ───
│
1 │ ╭ match line_index.compare(self.last_line_index()) {
2 │ │ Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),
│ │ --------------------------------------------- this is found to be of type `Result`
3 │ │ Ordering::Equal => Ok(self.source_span().end()),
│ │ ---------------------------- this is found to be of type `Result`
4 │ │ Ordering::Greater => LineIndexOutOfBoundsError {
│ ╭─│──────────────────────────────────^
5 │ │ │ given: line_index,
6 │ │ │ max: self.last_line_index(),
7 │ │ │ },
│ ╰─│─────────────^ expected enum `Result`, found struct `LineIndexOutOfBoundsError`
8 │ │ }
│ ╰─────────' `match` arms have incompatible types
│
= expected type `Result`
found type `LineIndexOutOfBoundsError`
```
## [0.9.1] - 2020-03-23
### Added
- `codespan_reporting::diagnostic::Diagnostic` now implements `Debug`.
### Changed
- Single-line labels are now rendered together, under the same source line.
Example
For example:
```text
┌── one_line.rs:3:5 ───
│
3 │ v.push(v.pop().unwrap());
│ - first borrow later used by call
·
3 │ v.push(v.pop().unwrap());
│ ---- first mutable borrow occurs here
·
3 │ v.push(v.pop().unwrap());
│ ^ second mutable borrow occurs here
│
```
…is now rendered as:
```text
┌── one_line.rs:3:5 ───
│
3 │ v.push(v.pop().unwrap());
│ - first borrow later used by call
│ ---- first mutable borrow occurs here
│ ^ second mutable borrow occurs here
│
```
## [0.9.0] - 2020-03-11
### Added
- The `codespan_reporting::files` module was added as a way to decouple
`codespan_reporting` from `codespan`.
- `codespan_reporting::files::Files` allows users to implement custom file
databases that work with `codespan_reporting`. This should make it
easier to integrate with libraries like Salsa, and also makes it less
invasive to use `codespan_reporting` on existing projects.
- `codespan_reporting::files::SimpleFile` is a simple implementation of
`codespan_reporting::files::Files` where only a single file is needed.
- `codespan_reporting::files::SimpleFiles` is a simple implementation of
`codespan_reporting::files::Files` where multiple files are needed.
### Changed
- The `codespan_reporting::diagnostic` module has been greatly revamped,
making the builder API format more nicely with rustfmt, and allowing for
multiple primary labels.
- The output of `codespan_reporting::term::emit` was improved,
with the following changes:
- labels on consecutive lines no longer render breaks between them
- source lines are rendered when there is only one line between labels
- the inner gutter of code snippets is now aligned consistently
- the outer gutter of consecutive code snippets are now aligned consistently
- `codespan_reporting::term::emit` now takes writers as a trait object (rather
than using static dispatch) in order to reduce coda bloat and improve
compile times.
- The field names in `codespan_reporting::term::Chars` were tweaked for
consistency.
### Removed
- `codespan_reporting` no longer depends on `codespan`.
Note that `codespan` can _still_ be used with `codespan_reporting`,
as `codespan::Files` now implements `codespan_reporting::files::Files`.
## [0.8.0] - 2020-02-24
## [0.7.0] - 2020-01-06
## [0.6.0] - 2019-12-18
## [0.5.0] - 2019-10-02
## [0.4.1] - 2019-08-25
## [0.4.0] - 2019-08-22
## [0.3.0] - 2019-05-01
## [0.2.1] - 2019-02-26
## [0.2.0] - 2018-10-11
[Unreleased]: https://github.com/brendanzab/codespan/compare/v0.11.1...HEAD
[0.11.1]: https://github.com/brendanzab/codespan/compare/v0.11.0..v0.11.1
[0.11.0]: https://github.com/brendanzab/codespan/compare/v0.9.5...v0.11.0
[0.9.5]: https://github.com/brendanzab/codespan/compare/v0.9.4...v0.9.5
[0.9.4]: https://github.com/brendanzab/codespan/compare/v0.9.3...v0.9.4
[0.9.3]: https://github.com/brendanzab/codespan/compare/v0.9.2...v0.9.3
[0.9.2]: https://github.com/brendanzab/codespan/compare/v0.9.1...v0.9.2
[0.9.1]: https://github.com/brendanzab/codespan/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/brendanzab/codespan/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/brendanzab/codespan/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/brendanzab/codespan/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/brendanzab/codespan/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/brendanzab/codespan/compare/v0.4.1...v0.5.0
[0.4.1]: https://github.com/brendanzab/codespan/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/brendanzab/codespan/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/brendanzab/codespan/compare/v0.2.1...v0.3.0
[0.2.1]: https://github.com/brendanzab/codespan/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/brendanzab/codespan/releases/tag/v0.2.0
codespan-reporting-0.11.1/Cargo.lock 0000644 00000033761 00000000000 0012703 0 ustar # This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]]
name = "anyhow"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cc"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
dependencies = [
"anyhow",
"insta",
"lazy_static",
"peg",
"rustyline",
"serde",
"structopt",
"termcolor",
"unicode-width",
"unindent",
]
[[package]]
name = "console"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cc80946b3480f421c2f17ed1cb841753a371c7c5104f51d507e13f532c856aa"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"terminal_size",
"winapi",
]
[[package]]
name = "dirs-next"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf36e65a80337bea855cd4ef9b8401ffce06a7baedf2e85ec467b1ac3f6e82b6"
dependencies = [
"cfg-if 1.0.0",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "dtoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e"
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi",
]
[[package]]
name = "heck"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
dependencies = [
"libc",
]
[[package]]
name = "insta"
version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd354a2c8c8083d58414597a4ecada1984f9b82ea7e87eeabddc869eaf120992"
dependencies = [
"console",
"lazy_static",
"serde",
"serde_json",
"serde_yaml",
"similar",
"uuid",
]
[[package]]
name = "itoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "memchr"
version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "nix"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
dependencies = [
"bitflags",
"cc",
"cfg-if 0.1.10",
"libc",
]
[[package]]
name = "peg"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f76678828272f177ac33b7e2ac2e3e73cc6c1cd1e3e387928aa69562fa51367"
dependencies = [
"peg-macros",
"peg-runtime",
]
[[package]]
name = "peg-macros"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "636d60acf97633e48d266d7415a9355d4389cea327a193f87df395d88cd2b14d"
dependencies = [
"peg-runtime",
"proc-macro2",
"quote",
]
[[package]]
name = "peg-runtime"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9555b1514d2d99d78150d3c799d4c357a3e2c2a8062cd108e93a06d9057629c5"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
"getrandom",
"redox_syscall",
]
[[package]]
name = "rustyline"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0d5e7b0219a3eadd5439498525d4765c59b7c993ef0c12244865cd2d988413"
dependencies = [
"cfg-if 0.1.10",
"dirs-next",
"libc",
"log",
"memchr",
"nix",
"scopeguard",
"unicode-segmentation",
"unicode-width",
"utf8parse",
"winapi",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23"
dependencies = [
"dtoa",
"linked-hash-map",
"serde",
"yaml-rust",
]
[[package]]
name = "similar"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a04629d2e8ecdcf30e0188e3699ed6d50d5750d0219db146a790065fe92a897"
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "structopt"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "terminal_size"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "unicode-segmentation"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "unindent"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
[[package]]
name = "utf8parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
codespan-reporting-0.11.1/Cargo.toml 0000644 00000002735 00000000000 0012723 0 ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
edition = "2018"
name = "codespan-reporting"
version = "0.11.1"
authors = ["Brendan Zabarauskas "]
exclude = ["assets/**"]
description = "Beautiful diagnostic reporting for text-based programming languages"
homepage = "https://github.com/brendanzab/codespan"
documentation = "https://docs.rs/codespan-reporting"
readme = "../README.md"
license = "Apache-2.0"
repository = "https://github.com/brendanzab/codespan"
[dependencies.serde]
version = "1"
features = ["derive"]
optional = true
[dependencies.termcolor]
version = "1"
[dependencies.unicode-width]
version = "0.1"
[dev-dependencies.anyhow]
version = "1"
[dev-dependencies.insta]
version = "1.6.3"
[dev-dependencies.lazy_static]
version = "1.4"
[dev-dependencies.peg]
version = "0.6"
[dev-dependencies.rustyline]
version = "6"
[dev-dependencies.structopt]
version = "0.3"
[dev-dependencies.unindent]
version = "0.1"
[features]
ascii-only = []
serialization = ["serde", "serde/rc"]
codespan-reporting-0.11.1/Cargo.toml.orig 0000644 0000000 0000000 00000001372 00000000000 0016356 0 ustar 0000000 0000000 [package]
name = "codespan-reporting"
version = "0.11.1"
readme = "../README.md"
license = "Apache-2.0"
authors = ["Brendan Zabarauskas "]
description = "Beautiful diagnostic reporting for text-based programming languages"
homepage = "https://github.com/brendanzab/codespan"
repository = "https://github.com/brendanzab/codespan"
documentation = "https://docs.rs/codespan-reporting"
exclude = ["assets/**"]
edition = "2018"
[dependencies]
serde = { version = "1", optional = true, features = ["derive"] }
termcolor = "1"
unicode-width = "0.1"
[dev-dependencies]
anyhow = "1"
insta = "1.6.3"
lazy_static = "1.4"
peg = "0.6"
rustyline = "6"
structopt = "0.3"
unindent = "0.1"
[features]
serialization = ["serde", "serde/rc"]
ascii-only = []
codespan-reporting-0.11.1/examples/custom_files.rs 0000644 0000000 0000000 00000014027 00000000000 0020350 0 ustar 0000000 0000000 //! An example that shows how to implement a simple custom file database.
//! The database uses 32-bit file-ids, which could be useful for optimizing
//! memory usage.
//!
//! To run this example, execute the following command from the top level of
//! this repository:
//!
//! ```sh
//! cargo run --example custom_files
//! ```
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::term;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use std::ops::Range;
fn main() -> anyhow::Result<()> {
let mut files = files::Files::new();
let file_id0 = files.add("0.greeting", "hello world!").unwrap();
let file_id1 = files.add("1.greeting", "bye world").unwrap();
let messages = vec![
Message::UnwantedGreetings {
greetings: vec![(file_id0, 0..5), (file_id1, 0..3)],
},
Message::OverTheTopExclamations {
exclamations: vec![(file_id0, 11..12)],
},
];
let writer = StandardStream::stderr(ColorChoice::Always);
let config = term::Config::default();
for message in &messages {
let writer = &mut writer.lock();
term::emit(writer, &config, &files, &message.to_diagnostic())?;
}
Ok(())
}
/// A module containing the file implementation
mod files {
use codespan_reporting::files;
use std::ops::Range;
/// A file that is backed by an `Arc`.
#[derive(Debug, Clone)]
struct File {
/// The name of the file.
name: String,
/// The source code of the file.
source: String,
/// The starting byte indices in the source code.
line_starts: Vec,
}
impl File {
fn line_start(&self, line_index: usize) -> Result {
use std::cmp::Ordering;
match line_index.cmp(&self.line_starts.len()) {
Ordering::Less => Ok(self
.line_starts
.get(line_index)
.expect("failed despite previous check")
.clone()),
Ordering::Equal => Ok(self.source.len()),
Ordering::Greater => Err(files::Error::LineTooLarge {
given: line_index,
max: self.line_starts.len() - 1,
}),
}
}
}
/// An opaque file identifier.
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct FileId(u32);
#[derive(Debug, Clone)]
pub struct Files {
files: Vec,
}
impl Files {
/// Create a new files database.
pub fn new() -> Files {
Files { files: Vec::new() }
}
/// Add a file to the database, returning the handle that can be used to
/// refer to it again.
pub fn add(
&mut self,
name: impl Into,
source: impl Into,
) -> Option {
use std::convert::TryFrom;
let file_id = FileId(u32::try_from(self.files.len()).ok()?);
let name = name.into();
let source = source.into();
let line_starts = files::line_starts(&source).collect();
self.files.push(File {
name,
line_starts,
source,
});
Some(file_id)
}
/// Get the file corresponding to the given id.
fn get(&self, file_id: FileId) -> Result<&File, files::Error> {
self.files
.get(file_id.0 as usize)
.ok_or(files::Error::FileMissing)
}
}
impl<'files> files::Files<'files> for Files {
type FileId = FileId;
type Name = &'files str;
type Source = &'files str;
fn name(&self, file_id: FileId) -> Result<&str, files::Error> {
Ok(self.get(file_id)?.name.as_ref())
}
fn source(&self, file_id: FileId) -> Result<&str, files::Error> {
Ok(&self.get(file_id)?.source)
}
fn line_index(&self, file_id: FileId, byte_index: usize) -> Result {
self.get(file_id)?
.line_starts
.binary_search(&byte_index)
.or_else(|next_line| Ok(next_line - 1))
}
fn line_range(
&self,
file_id: FileId,
line_index: usize,
) -> Result, files::Error> {
let file = self.get(file_id)?;
let line_start = file.line_start(line_index)?;
let next_line_start = file.line_start(line_index + 1)?;
Ok(line_start..next_line_start)
}
}
}
/// A Diagnostic message.
enum Message {
UnwantedGreetings {
greetings: Vec<(files::FileId, Range)>,
},
OverTheTopExclamations {
exclamations: Vec<(files::FileId, Range)>,
},
}
impl Message {
fn to_diagnostic(&self) -> Diagnostic {
match self {
Message::UnwantedGreetings { greetings } => Diagnostic::error()
.with_message("greetings are not allowed")
.with_labels(
greetings
.iter()
.map(|(file_id, range)| {
Label::primary(*file_id, range.clone()).with_message("a greeting")
})
.collect(),
)
.with_notes(vec![
"found greetings!".to_owned(),
"pleas no greetings :(".to_owned(),
]),
Message::OverTheTopExclamations { exclamations } => Diagnostic::error()
.with_message("over-the-top exclamations")
.with_labels(
exclamations
.iter()
.map(|(file_id, range)| {
Label::primary(*file_id, range.clone()).with_message("an exclamation")
})
.collect(),
)
.with_notes(vec!["ridiculous!".to_owned()]),
}
}
}
codespan-reporting-0.11.1/examples/peg_calculator.rs 0000644 0000000 0000000 00000004234 00000000000 0020637 0 ustar 0000000 0000000 //! An example of using `peg` with `codespan_reporting`.
//!
//! To run this example, execute the following command from the top level of
//! this repository:
//!
//! ```sh
//! cargo run --example peg_calculator
//! ```
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFile;
use codespan_reporting::term;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use rustyline::error::ReadlineError;
use rustyline::Editor;
peg::parser! {
grammar arithmetic() for str {
rule number() -> i64
= n:$(['0'..='9']+) { n.parse().unwrap() }
pub rule calculate() -> i64 = precedence!{
x:(@) "+" y:@ { x + y }
x:(@) "-" y:@ { x - y }
"-" v:@ { - v }
--
x:(@) "*" y:@ { x * y }
x:(@) "/" y:@ { x / y }
--
x:@ "^" y:(@) { i64::pow(x, y as u32) }
v:@ "!" { (1..v+1).product() }
--
"(" v:calculate() ")" { v }
n:number() { n }
}
}
}
fn main() -> anyhow::Result<()> {
let writer = StandardStream::stderr(ColorChoice::Always);
let config = codespan_reporting::term::Config::default();
let mut editor = Editor::<()>::new();
loop {
let line = match editor.readline("> ") {
Ok(line) => line,
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => return Ok(()),
Err(error) => return Err(error.into()),
};
match arithmetic::calculate(&line) {
Ok(number) => println!("{}", number),
Err(error) => {
let file = SimpleFile::new("", line);
let start = error.location.offset;
let diagnostic = Diagnostic::error()
.with_message("parse error")
.with_labels(vec![
Label::primary((), start..start).with_message("parse error")
])
.with_notes(vec![format!("expected: {}", error.expected)]);
term::emit(&mut writer.lock(), &config, &file, &diagnostic)?;
}
}
}
}
codespan-reporting-0.11.1/examples/readme_preview.rs 0000644 0000000 0000000 00000025171 00000000000 0020654 0 ustar 0000000 0000000 //! Renders the preview SVG for the README.
//!
//! To update the preview, execute the following command from the top level of
//! the repository:
//!
//! ```sh
//! cargo run --example readme_preview svg > codespan-reporting/assets/readme_preview.svg
//! ```
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFile;
use codespan_reporting::term::termcolor::{Color, ColorSpec, StandardStream, WriteColor};
use codespan_reporting::term::{self, ColorArg};
use std::io::{self, Write};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "emit")]
pub enum Opts {
/// Render SVG output
Svg,
/// Render Stderr output
Stderr {
/// Configure coloring of output
#[structopt(
long = "color",
parse(try_from_str),
default_value = "auto",
possible_values = ColorArg::VARIANTS,
case_insensitive = true
)]
color: ColorArg,
},
}
fn main() -> anyhow::Result<()> {
let file = SimpleFile::new(
"FizzBuzz.fun",
unindent::unindent(
r#"
module FizzBuzz where
fizz₁ : Nat → String
fizz₁ num = case (mod num 5) (mod num 3) of
0 0 => "FizzBuzz"
0 _ => "Fizz"
_ 0 => "Buzz"
_ _ => num
fizz₂ : Nat → String
fizz₂ num =
case (mod num 5) (mod num 3) of
0 0 => "FizzBuzz"
0 _ => "Fizz"
_ 0 => "Buzz"
_ _ => num
"#,
),
);
let diagnostics = [Diagnostic::error()
.with_message("`case` clauses have incompatible types")
.with_code("E0308")
.with_labels(vec![
Label::primary((), 328..331).with_message("expected `String`, found `Nat`"),
Label::secondary((), 211..331).with_message("`case` clauses have incompatible types"),
Label::secondary((), 258..268).with_message("this is found to be of type `String`"),
Label::secondary((), 284..290).with_message("this is found to be of type `String`"),
Label::secondary((), 306..312).with_message("this is found to be of type `String`"),
Label::secondary((), 186..192).with_message("expected type `String` found here"),
])
.with_notes(vec![unindent::unindent(
"
expected type `String`
found type `Nat`
",
)])];
// let mut files = SimpleFiles::new();
match Opts::from_args() {
Opts::Svg => {
let mut buffer = Vec::new();
let mut writer = HtmlEscapeWriter::new(SvgWriter::new(&mut buffer));
let config = codespan_reporting::term::Config {
styles: codespan_reporting::term::Styles::with_blue(Color::Blue),
..codespan_reporting::term::Config::default()
};
for diagnostic in &diagnostics {
term::emit(&mut writer, &config, &file, &diagnostic)?;
}
let num_lines = buffer.iter().filter(|byte| **byte == b'\n').count() + 1;
let padding = 10;
let font_size = 12;
let line_spacing = 3;
let width = 882;
let height = padding + num_lines * (font_size + line_spacing) + padding;
let stdout = std::io::stdout();
let writer = &mut stdout.lock();
write!(
writer,
r#"
"
)?;
}
Opts::Stderr { color } => {
let writer = StandardStream::stderr(color.into());
let config = codespan_reporting::term::Config::default();
for diagnostic in &diagnostics {
term::emit(&mut writer.lock(), &config, &file, &diagnostic)?;
}
}
}
Ok(())
}
/// Rudimentary HTML escaper which performs the following conversions:
///
/// - `<` ⇒ `<`
/// - `>` ⇒ `>`
/// - `&` ⇒ `&`
pub struct HtmlEscapeWriter {
upstream: W,
}
impl HtmlEscapeWriter {
pub fn new(upstream: W) -> HtmlEscapeWriter {
HtmlEscapeWriter { upstream }
}
}
impl Write for HtmlEscapeWriter {
fn write(&mut self, buf: &[u8]) -> io::Result {
let mut last_term = 0usize;
for (i, byte) in buf.iter().enumerate() {
let escape = match byte {
b'<' => &b"<"[..],
b'>' => &b">"[..],
b'&' => &b"&"[..],
_ => continue,
};
self.upstream.write_all(&buf[last_term..i])?;
last_term = i + 1;
self.upstream.write_all(escape)?;
}
self.upstream.write_all(&buf[last_term..])?;
Ok(buf.len())
}
fn flush(&mut self) -> io::Result<()> {
self.upstream.flush()
}
}
impl WriteColor for HtmlEscapeWriter {
fn supports_color(&self) -> bool {
self.upstream.supports_color()
}
fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> {
self.upstream.set_color(spec)
}
fn reset(&mut self) -> io::Result<()> {
self.upstream.reset()
}
}
pub struct SvgWriter {
upstream: W,
color: ColorSpec,
}
impl SvgWriter {
pub fn new(upstream: W) -> SvgWriter {
SvgWriter {
upstream,
color: ColorSpec::new(),
}
}
}
impl Write for SvgWriter {
fn write(&mut self, buf: &[u8]) -> io::Result {
self.upstream.write(buf)
}
fn flush(&mut self) -> io::Result<()> {
self.upstream.flush()
}
}
impl WriteColor for SvgWriter {
fn supports_color(&self) -> bool {
true
}
fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> {
#![allow(unused_assignments)]
if self.color == *spec {
return Ok(());
} else {
if !self.color.is_none() {
write!(self, "")?;
}
self.color = spec.clone();
}
if spec.is_none() {
write!(self, "")?;
return Ok(());
} else {
write!(self, "(first: bool, writer: &mut SvgWriter) -> io::Result {
if !first {
write!(writer, " ")?;
}
Ok(false)
};
fn write_color(color: &Color, writer: &mut SvgWriter) -> io::Result<()> {
match color {
Color::Black => write!(writer, "black"),
Color::Blue => write!(writer, "blue"),
Color::Green => write!(writer, "green"),
Color::Red => write!(writer, "red"),
Color::Cyan => write!(writer, "cyan"),
Color::Magenta => write!(writer, "magenta"),
Color::Yellow => write!(writer, "yellow"),
Color::White => write!(writer, "white"),
// TODO: other colors
_ => Ok(()),
}
};
if let Some(fg) = spec.fg() {
first = write_first(first, self)?;
write!(self, "fg ")?;
write_color(fg, self)?;
}
if let Some(bg) = spec.bg() {
first = write_first(first, self)?;
write!(self, "bg ")?;
write_color(bg, self)?;
}
if spec.bold() {
first = write_first(first, self)?;
write!(self, "bold")?;
}
if spec.underline() {
first = write_first(first, self)?;
write!(self, "underline")?;
}
if spec.intense() {
first = write_first(first, self)?;
write!(self, "bright")?;
}
write!(self, "\">")?;
Ok(())
}
fn reset(&mut self) -> io::Result<()> {
let color = self.color.clone();
if color != ColorSpec::new() {
write!(self, "")?;
self.color = ColorSpec::new();
}
Ok(())
}
}
codespan-reporting-0.11.1/examples/reusable_diagnostic.rs 0000644 0000000 0000000 00000006566 00000000000 0021673 0 ustar 0000000 0000000 use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFile;
use codespan_reporting::term::termcolor::StandardStream;
use codespan_reporting::term::{self, ColorArg};
use std::ops::Range;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "emit")]
pub struct Opts {
#[structopt(long = "color",
parse(try_from_str),
default_value = "auto",
possible_values = ColorArg::VARIANTS,
case_insensitive = true
)]
color: ColorArg,
}
fn main() -> anyhow::Result<()> {
let file = SimpleFile::new(
"main.rs",
unindent::unindent(
r#"
fn main() {
let foo: i32 = "hello, world";
foo += 1;
}
"#,
),
);
let errors = [
Error::MismatchType(
Item::new(20..23, "i32"),
Item::new(31..45, "\"hello, world\""),
),
Error::MutatingImmutable(Item::new(20..23, "foo"), Item::new(51..59, "foo += 1")),
];
let opts = Opts::from_args();
let writer = StandardStream::stderr(opts.color.into());
let config = codespan_reporting::term::Config::default();
for diagnostic in errors.iter().map(Error::report) {
term::emit(&mut writer.lock(), &config, &file, &diagnostic)?;
}
Ok(())
}
/// An error enum that represent all possible errors within your program
enum Error {
MismatchType(Item, Item),
MutatingImmutable(Item, Item),
}
impl Error {
fn report(&self) -> Diagnostic<()> {
match self {
Error::MismatchType(left, right) => Diagnostic::error()
.with_code("E0308")
.with_message("mismatch types")
.with_labels(vec![
Label::primary((), right.range.clone()).with_message(format!(
"Expected `{}`, found: `{}`",
left.content, right.content,
)),
Label::secondary((), left.range.clone()).with_message("expected due to this"),
]),
Error::MutatingImmutable(original, mutating) => Diagnostic::error()
.with_code("E0384")
.with_message(format!(
"cannot mutate immutable variable `{}`",
original.content,
))
.with_labels(vec![
Label::secondary((), original.range.clone()).with_message(unindent::unindent(
&format!(
r#"
first assignment to `{0}`
help: make this binding mutable: `mut {0}`
"#,
original.content,
),
)),
Label::primary((), mutating.range.clone())
.with_message("cannot assign twice to immutable variable"),
]),
}
}
}
/// An item in the source code to be used in the `Error` enum.
/// In a more complex program it could also contain a `files::FileId` to handle errors that occur inside multiple files.
struct Item {
range: Range,
content: String,
}
impl Item {
fn new(range: Range, content: impl Into) -> Item {
let content = content.into();
Item { range, content }
}
}
codespan-reporting-0.11.1/examples/term.rs 0000644 0000000 0000000 00000013417 00000000000 0016625 0 ustar 0000000 0000000 //! To run this example, execute the following command from the top level of
//! this repository:
//!
//! ```sh
//! cargo run --example term
//! ```
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term::termcolor::StandardStream;
use codespan_reporting::term::{self, ColorArg};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "emit")]
pub struct Opts {
/// Configure coloring of output
#[structopt(
long = "color",
parse(try_from_str),
default_value = "auto",
possible_values = ColorArg::VARIANTS,
case_insensitive = true
)]
pub color: ColorArg,
}
fn main() -> anyhow::Result<()> {
let opts = Opts::from_args();
let mut files = SimpleFiles::new();
let file_id1 = files.add(
"Data/Nat.fun",
unindent::unindent(
"
module Data.Nat where
data Nat : Type where
zero : Nat
succ : Nat → Nat
{-# BUILTIN NATRAL Nat #-}
infixl 6 _+_ _-_
_+_ : Nat → Nat → Nat
zero + n₂ = n₂
succ n₁ + n₂ = succ (n₁ + n₂)
_-_ : Nat → Nat → Nat
n₁ - zero = n₁
zero - succ n₂ = zero
succ n₁ - succ n₂ = n₁ - n₂
",
),
);
let file_id2 = files.add(
"Test.fun",
unindent::unindent(
r#"
module Test where
_ : Nat
_ = 123 + "hello"
"#,
),
);
let file_id3 = files.add(
"FizzBuzz.fun",
unindent::unindent(
r#"
module FizzBuzz where
fizz₁ : Nat → String
fizz₁ num = case (mod num 5) (mod num 3) of
0 0 => "FizzBuzz"
0 _ => "Fizz"
_ 0 => "Buzz"
_ _ => num
fizz₂ : Nat → String
fizz₂ num =
case (mod num 5) (mod num 3) of
0 0 => "FizzBuzz"
0 _ => "Fizz"
_ 0 => "Buzz"
_ _ => num
"#,
),
);
let diagnostics = [
// Unknown builtin error
Diagnostic::error()
.with_message("unknown builtin: `NATRAL`")
.with_labels(vec![
Label::primary(file_id1, 96..102).with_message("unknown builtin")
])
.with_notes(vec![
"there is a builtin with a similar name: `NATURAL`".to_owned()
]),
// Unused parameter warning
Diagnostic::warning()
.with_message("unused parameter pattern: `n₂`")
.with_labels(vec![
Label::primary(file_id1, 285..289).with_message("unused parameter")
])
.with_notes(vec!["consider using a wildcard pattern: `_`".to_owned()]),
// Unexpected type error
Diagnostic::error()
.with_message("unexpected type in application of `_+_`")
.with_code("E0001")
.with_labels(vec![
Label::primary(file_id2, 37..44).with_message("expected `Nat`, found `String`"),
Label::secondary(file_id1, 130..155)
.with_message("based on the definition of `_+_`"),
])
.with_notes(vec![unindent::unindent(
"
expected type `Nat`
found type `String`
",
)]),
// Incompatible match clause error
Diagnostic::error()
.with_message("`case` clauses have incompatible types")
.with_code("E0308")
.with_labels(vec![
Label::primary(file_id3, 163..166).with_message("expected `String`, found `Nat`"),
Label::secondary(file_id3, 62..166)
.with_message("`case` clauses have incompatible types"),
Label::secondary(file_id3, 41..47)
.with_message("expected type `String` found here"),
])
.with_notes(vec![unindent::unindent(
"
expected type `String`
found type `Nat`
",
)]),
// Incompatible match clause error
Diagnostic::error()
.with_message("`case` clauses have incompatible types")
.with_code("E0308")
.with_labels(vec![
Label::primary(file_id3, 328..331).with_message("expected `String`, found `Nat`"),
Label::secondary(file_id3, 211..331)
.with_message("`case` clauses have incompatible types"),
Label::secondary(file_id3, 258..268)
.with_message("this is found to be of type `String`"),
Label::secondary(file_id3, 284..290)
.with_message("this is found to be of type `String`"),
Label::secondary(file_id3, 306..312)
.with_message("this is found to be of type `String`"),
Label::secondary(file_id3, 186..192)
.with_message("expected type `String` found here"),
])
.with_notes(vec![unindent::unindent(
"
expected type `String`
found type `Nat`
",
)]),
];
let writer = StandardStream::stderr(opts.color.into());
let config = codespan_reporting::term::Config::default();
for diagnostic in &diagnostics {
term::emit(&mut writer.lock(), &config, &files, &diagnostic)?;
}
Ok(())
}
codespan-reporting-0.11.1/src/diagnostic.rs 0000644 0000000 0000000 00000015227 00000000000 0016754 0 ustar 0000000 0000000 //! Diagnostic data structures.
#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};
use std::ops::Range;
/// A severity level for diagnostic messages.
///
/// These are ordered in the following way:
///
/// ```rust
/// use codespan_reporting::diagnostic::Severity;
///
/// assert!(Severity::Bug > Severity::Error);
/// assert!(Severity::Error > Severity::Warning);
/// assert!(Severity::Warning > Severity::Note);
/// assert!(Severity::Note > Severity::Help);
/// ```
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub enum Severity {
/// An unexpected bug.
Bug,
/// An error.
Error,
/// A warning.
Warning,
/// A note.
Note,
/// A help message.
Help,
}
impl Severity {
/// We want bugs to be the maximum severity, errors next, etc...
fn to_cmp_int(self) -> u8 {
match self {
Severity::Bug => 5,
Severity::Error => 4,
Severity::Warning => 3,
Severity::Note => 2,
Severity::Help => 1,
}
}
}
impl PartialOrd for Severity {
fn partial_cmp(&self, other: &Severity) -> Option {
u8::partial_cmp(&self.to_cmp_int(), &other.to_cmp_int())
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub enum LabelStyle {
/// Labels that describe the primary cause of a diagnostic.
Primary,
/// Labels that provide additional context for a diagnostic.
Secondary,
}
/// A label describing an underlined region of code associated with a diagnostic.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct Label {
/// The style of the label.
pub style: LabelStyle,
/// The file that we are labelling.
pub file_id: FileId,
/// The range in bytes we are going to include in the final snippet.
pub range: Range,
/// An optional message to provide some additional information for the
/// underlined code. These should not include line breaks.
pub message: String,
}
impl Label {
/// Create a new label.
pub fn new(
style: LabelStyle,
file_id: FileId,
range: impl Into>,
) -> Label {
Label {
style,
file_id,
range: range.into(),
message: String::new(),
}
}
/// Create a new label with a style of [`LabelStyle::Primary`].
///
/// [`LabelStyle::Primary`]: LabelStyle::Primary
pub fn primary(file_id: FileId, range: impl Into>) -> Label {
Label::new(LabelStyle::Primary, file_id, range)
}
/// Create a new label with a style of [`LabelStyle::Secondary`].
///
/// [`LabelStyle::Secondary`]: LabelStyle::Secondary
pub fn secondary(file_id: FileId, range: impl Into>) -> Label {
Label::new(LabelStyle::Secondary, file_id, range)
}
/// Add a message to the diagnostic.
pub fn with_message(mut self, message: impl Into) -> Label {
self.message = message.into();
self
}
}
/// Represents a diagnostic message that can provide information like errors and
/// warnings to the user.
///
/// The position of a Diagnostic is considered to be the position of the [`Label`] that has the earliest starting position and has the highest style which appears in all the labels of the diagnostic.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct Diagnostic {
/// The overall severity of the diagnostic
pub severity: Severity,
/// An optional code that identifies this diagnostic.
pub code: Option,
/// The main message associated with this diagnostic.
///
/// These should not include line breaks, and in order support the 'short'
/// diagnostic display mod, the message should be specific enough to make
/// sense on its own, without additional context provided by labels and notes.
pub message: String,
/// Source labels that describe the cause of the diagnostic.
/// The order of the labels inside the vector does not have any meaning.
/// The labels are always arranged in the order they appear in the source code.
pub labels: Vec