aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-25 04:10:55 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-25 04:10:55 +0000
commit42d8e387418f0160a7a32ea72c2325bc42f741f6 (patch)
treeaab9afc7cdb1b88ac756d68386384cbc46be6210
parent2341c38b4cb8f9a6059cdf833aa21dcafac9fae2 (diff)
parent157ad63d05ba9a5ac1ec749688d92550cf6b5c46 (diff)
downloadannotate-snippets-android14-qpr2-s2-release.tar.gz
Change-Id: I91382c026b7bc4902766f7ecb73c0ef532a2883d
-rw-r--r--.cargo_vcs_info.json7
-rw-r--r--.github/workflows/ci.yml24
-rw-r--r--Android.bp2
-rw-r--r--CHANGELOG.md5
-rw-r--r--Cargo.toml22
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA27
-rw-r--r--README.md2
-rw-r--r--src/display_list/from_snippet.rs33
-rw-r--r--tests/dl_from_snippet.rs18
-rw-r--r--tests/fixtures/no-color/issue_52.toml16
-rw-r--r--tests/fixtures/no-color/issue_52.txt7
12 files changed, 104 insertions, 61 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 59e14f0..5cdcd16 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,6 @@
{
"git": {
- "sha1": "77bd1c8e03466ff290c15dc025eac13088c244ee"
- }
-}
+ "sha1": "bc504bc3ef6c856152d63d6304845014d046a2bd"
+ },
+ "path_in_vcs": ""
+} \ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..f40ab58
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,24 @@
+name: CI
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+env:
+ CARGO_TERM_COLOR: always
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Run rustfmt
+ run: cargo fmt -- --check
+ - name: Build
+ run: cargo build --verbose
+ - name: Run tests
+ run: cargo test --verbose
diff --git a/Android.bp b/Android.bp
index 0fec223..3b4ff69 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5,7 +5,7 @@ rust_library_host {
name: "libannotate_snippets",
crate_name: "annotate_snippets",
cargo_env_compat: true,
- cargo_pkg_version: "0.9.1",
+ cargo_pkg_version: "0.9.2",
srcs: ["src/lib.rs"],
edition: "2018",
features: ["default"],
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 21e5f2f..c66ad41 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@
- …
+## annotate-snippets 0.9.2 (October 30, 2023)
+
+ - Remove parsing of __ in title strings, fixes (#53)
+ - Origin line number is not correct when using a slice with fold: true (#52)
+
## annotate-snippets 0.9.1 (September 4, 2021)
- Fix character split when strip code. (#37)
diff --git a/Cargo.toml b/Cargo.toml
index e2bccd9..1f5e46a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,33 +3,40 @@
# 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
+# 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)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "annotate-snippets"
-version = "0.9.1"
+version = "0.9.2"
authors = ["Zibi Braniecki <gandalf@mozilla.com>"]
description = "Library for building code annotations"
readme = "README.md"
-keywords = ["code", "analysis", "ascii", "errors", "debug"]
+keywords = [
+ "code",
+ "analysis",
+ "ascii",
+ "errors",
+ "debug",
+]
license = "Apache-2.0/MIT"
repository = "https://github.com/rust-lang/annotate-snippets-rs"
[[bench]]
name = "simple"
harness = false
+
[dependencies.unicode-width]
version = "0.1"
[dependencies.yansi-term]
version = "0.1"
optional = true
+
[dev-dependencies.criterion]
version = "0.3"
@@ -52,6 +59,7 @@ version = "0.1"
[features]
color = ["yansi-term"]
default = []
+
[badges.coveralls]
branch = "master"
repository = "rust-lang/annotate-snippets-rs"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index b7a97fd..e4a2351 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "annotate-snippets"
-version = "0.9.1"
+version = "0.9.2"
edition = "2018"
authors = ["Zibi Braniecki <gandalf@mozilla.com>"]
description = "Library for building code annotations"
diff --git a/METADATA b/METADATA
index 383f04e..1c9e894 100644
--- a/METADATA
+++ b/METADATA
@@ -1,20 +1,23 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update rust/crates/annotate-snippets
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "annotate-snippets"
description: "Library for building code annotations"
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/annotate-snippets"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/annotate-snippets/annotate-snippets-0.9.1.crate"
- }
- version: "0.9.1"
- # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
license_type: NOTICE
last_upgrade_date {
year: 2023
- month: 6
- day: 12
+ month: 11
+ day: 24
+ }
+ identifier {
+ type: "HOMEPAGE"
+ value: "https://crates.io/crates/annotate-snippets"
+ }
+ identifier {
+ type: "ARCHIVE"
+ value: "https://static.crates.io/crates/annotate-snippets/annotate-snippets-0.9.2.crate"
+ version: "0.9.2"
}
}
diff --git a/README.md b/README.md
index a3e1683..f60c96e 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
`annotate-snippets` is a Rust library for annotation of programming code slices.
[![crates.io](https://img.shields.io/crates/v/annotate-snippets.svg)](https://crates.io/crates/annotate-snippets)
-[![Build Status](https://travis-ci.com/rust-lang/annotate-snippets-rs.svg?branch=master)](https://travis-ci.com/rust-lang/annotate-snippets-rs)
+![build status](https://github.com/rust-lang/annotate-snippets-rs/actions/workflows/ci.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/rust-lang/annotate-snippets-rs/badge.svg?branch=master)](https://coveralls.io/github/rust-lang/annotate-snippets-rs?branch=master)
The library helps visualize meta information annotating source code slices.
diff --git a/src/display_list/from_snippet.rs b/src/display_list/from_snippet.rs
index faf48f2..d7c1ac0 100644
--- a/src/display_list/from_snippet.rs
+++ b/src/display_list/from_snippet.rs
@@ -53,22 +53,11 @@ fn format_label(
) -> Vec<DisplayTextFragment<'_>> {
let mut result = vec![];
if let Some(label) = label {
- for (idx, element) in label.split("__").enumerate() {
- let element_style = match style {
- Some(s) => s,
- None => {
- if idx % 2 == 0 {
- DisplayTextStyle::Regular
- } else {
- DisplayTextStyle::Emphasis
- }
- }
- };
- result.push(DisplayTextFragment {
- content: element,
- style: element_style,
- });
- }
+ let element_style = style.unwrap_or(DisplayTextStyle::Regular);
+ result.push(DisplayTextFragment {
+ content: label,
+ style: element_style,
+ });
}
result
}
@@ -111,10 +100,9 @@ fn format_slice(
) -> Vec<DisplayLine<'_>> {
let main_range = slice.annotations.get(0).map(|x| x.range.0);
let origin = slice.origin;
- let line_start = slice.line_start;
let need_empty_header = origin.is_some() || is_first;
let mut body = format_body(slice, need_empty_header, has_footer, margin);
- let header = format_header(origin, main_range, line_start, &body, is_first);
+ let header = format_header(origin, main_range, &body, is_first);
let mut result = vec![];
if let Some(header) = header {
@@ -133,7 +121,6 @@ fn zip_opt<A, B>(a: Option<A>, b: Option<B>) -> Option<(A, B)> {
fn format_header<'a>(
origin: Option<&'a str>,
main_range: Option<usize>,
- mut row: usize,
body: &[DisplayLine<'_>],
is_first: bool,
) -> Option<DisplayLine<'a>> {
@@ -145,24 +132,26 @@ fn format_header<'a>(
if let Some((main_range, path)) = zip_opt(main_range, origin) {
let mut col = 1;
+ let mut line_offset = 1;
for item in body {
if let DisplayLine::Source {
line: DisplaySourceLine::Content { range, .. },
+ lineno,
..
} = item
{
if main_range >= range.0 && main_range <= range.1 {
col = main_range - range.0 + 1;
+ line_offset = lineno.unwrap_or(1);
break;
}
- row += 1;
}
}
return Some(DisplayLine::Raw(DisplayRawLine::Origin {
path,
- pos: Some((row, col)),
+ pos: Some((line_offset, col)),
header_type: display_header,
}));
}
@@ -307,7 +296,7 @@ fn format_body(
let char_widths = line
.chars()
.map(|c| unicode_width::UnicodeWidthChar::width(c).unwrap_or(0))
- .chain(std::iter::once(1)) // treat the end of line as signle-width
+ .chain(std::iter::once(1)) // treat the end of line as single-width
.collect::<Vec<_>>();
body.push(DisplayLine::Source {
lineno: Some(current_line),
diff --git a/tests/dl_from_snippet.rs b/tests/dl_from_snippet.rs
index 0dcfcfa..d6b79ff 100644
--- a/tests/dl_from_snippet.rs
+++ b/tests/dl_from_snippet.rs
@@ -262,20 +262,10 @@ fn test_format_label() {
annotation: dl::Annotation {
annotation_type: dl::DisplayAnnotationType::Error,
id: None,
- label: vec![
- dl::DisplayTextFragment {
- content: "This ",
- style: dl::DisplayTextStyle::Regular,
- },
- dl::DisplayTextFragment {
- content: "is",
- style: dl::DisplayTextStyle::Emphasis,
- },
- dl::DisplayTextFragment {
- content: " a title",
- style: dl::DisplayTextStyle::Regular,
- },
- ],
+ label: vec![dl::DisplayTextFragment {
+ content: "This __is__ a title",
+ style: dl::DisplayTextStyle::Regular,
+ }],
},
source_aligned: true,
continuation: false,
diff --git a/tests/fixtures/no-color/issue_52.toml b/tests/fixtures/no-color/issue_52.toml
new file mode 100644
index 0000000..8d54613
--- /dev/null
+++ b/tests/fixtures/no-color/issue_52.toml
@@ -0,0 +1,16 @@
+[title]
+annotation_type = "Error"
+
+[[slices]]
+source = """
+
+
+invalid syntax
+"""
+line_start = 1
+origin = "path/to/error.rs"
+fold = true
+[[slices.annotations]]
+label = "error here"
+annotation_type = "Warning"
+range = [2,16]
diff --git a/tests/fixtures/no-color/issue_52.txt b/tests/fixtures/no-color/issue_52.txt
new file mode 100644
index 0000000..b1c6bf2
--- /dev/null
+++ b/tests/fixtures/no-color/issue_52.txt
@@ -0,0 +1,7 @@
+error
+ --> path/to/error.rs:3:1
+ |
+...
+3 | invalid syntax
+ | -------------- error here
+ | \ No newline at end of file