From 747fa7dd6ec269ce25a44f67a13450b393a15f9e Mon Sep 17 00:00:00 2001 From: homersimpsons Date: Sun, 7 Jan 2024 14:25:42 +0100 Subject: [PATCH 1/2] line-index: Create README.md --- lib/line-index/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/line-index/README.md diff --git a/lib/line-index/README.md b/lib/line-index/README.md new file mode 100644 index 0000000000000..c0d310c857cd2 --- /dev/null +++ b/lib/line-index/README.md @@ -0,0 +1,28 @@ +# line-index + +This crate is developped as part of `rust-analyzer`. + +line-index is a library to convert between text offset and its corresponding line/column. + +## Installation + +To add this crate to a project simply run `cargo add line-index`. + +## Usage + +The main structure is `LineIndex`. It is constructed with an utf-8 text then various utility functions can be used on it. + +### Example + +```rust +use line_index::LineIndex; + +let line_index = LineIndex::new("This is a\nmulti-line\ntext."); +line_index.line_col(3.into()); // LineCol { line: 0, col: 3 } +line_index.line_col(13.into()); // LineCol { line: 1, col: 3 } +line_index.offset(LineCol { line: 2, col: 3 }); // Some (24) +``` + +## SemVer + +This crate follows [semver principles]([url](https://semver.org/)https://semver.org/). From 0f69276e60cd9636e6ad2c76dcc9f68619cc6851 Mon Sep 17 00:00:00 2001 From: homersimpsons Date: Sun, 7 Jan 2024 15:38:40 +0100 Subject: [PATCH 2/2] line-index: Update README.md with suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Laurențiu Nicola --- lib/line-index/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/line-index/README.md b/lib/line-index/README.md index c0d310c857cd2..93ac03696a0d3 100644 --- a/lib/line-index/README.md +++ b/lib/line-index/README.md @@ -1,8 +1,8 @@ # line-index -This crate is developped as part of `rust-analyzer`. +This crate is developed as part of `rust-analyzer`. -line-index is a library to convert between text offset and its corresponding line/column. +line-index is a library to convert between text offsets and corresponding line/column coordinates. ## Installation @@ -10,7 +10,9 @@ To add this crate to a project simply run `cargo add line-index`. ## Usage -The main structure is `LineIndex`. It is constructed with an utf-8 text then various utility functions can be used on it. +The main structure is `LineIndex`. + +It is constructed with an UTF-8 string, but also supports UTF-16 and UTF-32 offsets. ### Example @@ -25,4 +27,4 @@ line_index.offset(LineCol { line: 2, col: 3 }); // Some (24) ## SemVer -This crate follows [semver principles]([url](https://semver.org/)https://semver.org/). +This crate uses [semver](https://semver.org/) versioning.