93 Commits

Author SHA1 Message Date
CAD97
a39847804d Add test for indexing 2020-03-26 17:03:04 -04:00
CAD97
fe3fe80fa2 Re-add Index<TextRange> for String 2020-03-25 21:41:48 -04:00
CAD97
bf18e9f445 Bump dev version 2020-03-25 20:39:02 -04:00
bors[bot]
be44120d49 Merge rust-analyzer/text-size#31
31: Use standard generics for TextSize::of r=CAD97 a=CAD97

There is no specific reason to use APIT here, so prefer the form that allows more control for the user, in the form of the turbofish.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-26 00:18:03 +00:00
CAD97
9cca8e26f0 Use standard generics for TextSize::of
There is no specific reason to use APIT here, so prefer the form that allows more control for the user, in the form of the turbofish.
2020-03-25 20:17:35 -04:00
bors[bot]
d19a5a3b40 Merge rust-analyzer/text-size#30
30: Don't use decimal numbers when str length overflows TextSize. r=matklad a=CAD97

Since the string is necessarily longer than 4,294,967,296 bytes,
it is probably more useful to output the length in hexadecimal.

For additional niceness, we output the first and last 10 characters.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-26 00:16:03 +00:00
CAD97
0f09f1d10d Just unwrap in LenTextSize for &str 2020-03-25 20:15:28 -04:00
bors[bot]
84d071b33d Merge rust-analyzer/text-size#33
33: Fix broken intra doc link r=CAD97 a=CAD97

---
bors: r+
🤖

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-26 00:09:27 +00:00
CAD97
cda9765cae Fix broken intra doc link 2020-03-25 20:05:18 -04:00
Aleksey Kladov
8c3d31f4f2 Merge pull request rust-analyzer/text-size#27 from CAD97/ci-docs
Ensure docs build
2020-03-24 17:21:11 +01:00
bors[bot]
128f45fb10 Merge rust-analyzer/text-size#29
29: TextSized is not meant to be used directly... r=matklad a=CAD97

so rename it to a name more distinct from TextSize.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-24 08:58:25 +00:00
bors[bot]
d1b05966c6 Merge rust-analyzer/text-size#28
28: Add doctests to things r=matklad a=CAD97

This also includes a test to make sure the types implement the common std traits.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-24 08:55:32 +00:00
CAD97
ade5c7b7d6 TextSized is not meant to be used directly...
so rename it to a name more distinct from TextSize.
2020-03-23 21:36:09 -04:00
CAD97
e497041625 Make sure docs build on CI 2020-03-23 21:31:39 -04:00
CAD97
9aa3cabcef Add doc examples to things 2020-03-23 21:30:39 -04:00
CAD97
211ae81ad0 Tests to ensure common and auto trait presence 2020-03-23 17:03:43 -04:00
bors[bot]
3d1a768d29 Merge rust-analyzer/text-size#23
23: Add a deref-removing impl for TextSized r=CAD97 a=CAD97

Notably, given `s: &SmolStr`, `TextSize::of(s)` does not work, where `TextUnit::of_str(s)` did, because the concrete type could be deref-coerced to. (It's probably a limitation of the language that deref coersion does not apply here, but it's one we have to live with.)

So we provide a blanket impl for any type that derefs (directly) to `str`.

Alternatively, we can provide a deeper blanket impl that derefs any number of references recursively [[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=008b5e0c2edd332b34b3efa42ce2a40a)]:

```rust
impl<D> TextSized for &'_ D
where
    D: Deref,
    for<'a> &'a D::Target: TextSized,
{
    #[inline]
    fn text_size(self) -> TextSize {
        self.deref().text_size()
    }
}
```

This is "only" at the cost of a little extra impl complexity.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-23 20:46:13 +00:00
CAD97
5468ef0a9f Move construction tests into a test 2020-03-23 16:45:18 -04:00
CAD97
3b9d00e65d Add assertion for TextSized impls 2020-03-23 16:38:34 -04:00
CAD97
ba1fd73c12 target the TextSized blanket impl more tightly" 2020-03-23 16:38:34 -04:00
CAD97
5f3a2c2aec add recursive impl for TextSized 2020-03-23 16:38:34 -04:00
bors[bot]
3f4556b103 Merge rust-analyzer/text-size#26
26: Make TextRange constructors more boring r=matklad a=matklad

Remove `fn TextRange(` as that's slightly unusual and surprising,
which will add up to a lot of confusion over the long run.

Instead add:

* `new` as the biased, canonical way to create range from bounds
* `from_len` as an alternative ctor from starting position and len
* `empty` for empty ranges at a given offset
* `up_to` for ranges at zero offset with given length
* `default` for an empty range at zero

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-03-22 08:24:04 +00:00
Aleksey Kladov
8d9a1a4192 Make TextRange constructors more boring
Remove `fn TextRange(` as that's slightly unusual and surprising,
which will add up to a lot of confusion over the long run.

Instead add:

* `new` as the biased, canonical way to create range from bounds
* `from_len` as an alternative ctor from starting position and len
* `empty` for empty ranges at a given offset
* `up_to` for ranges at zero offset with given length
* `default` for an empty range at zero
2020-03-22 09:23:43 +01:00
bors[bot]
c69d303414 Merge rust-analyzer/text-size#25
25: Add licensing text to README r=matklad a=CAD97



Co-authored-by: Christopher Durham <cad97@cad97.com>
2020-03-21 23:01:33 +00:00
Christopher Durham
16334551bd Add licensing text to README 2020-03-20 20:21:44 -04:00
bors[bot]
4bcf23e99d Merge rust-analyzer/text-size#22
22: Make intersect and cover into methods r=matklad a=matklad

r? @CAD97 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-03-20 23:43:44 +00:00
Aleksey Kladov
6c8c54ef15 Update src/range.rs
Co-Authored-By: Christopher Durham <cad97@cad97.com>
2020-03-21 00:43:20 +01:00
Aleksey Kladov
5ae5d6e1fc Swithc to GitHub actions 2020-03-20 17:17:40 +01:00
Aleksey Kladov
d8b8a9854b Rename repo 2020-03-20 17:12:32 +01:00
Aleksey Kladov
0edd20912e Make intersect and cover into methods 2020-03-20 09:46:15 +01:00
bors[bot]
f56596b771 Merge rust-analyzer/text-size#21
21: Add ops for TextRange r=matklad a=CAD97

Alright, let's see what the ops looks like.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-19 18:19:05 +00:00
CAD97
8e7c7d3589 correct translation table 2020-03-19 13:55:11 -04:00
CAD97
2053ee9633 Add ops for TextRange 2020-03-19 13:52:56 -04:00
bors[bot]
c5d662e46b Merge rust-analyzer/text-size#18
18: minor improvements everywhere r=matklad a=CAD97

Because none of this was quite specific enough to break into its own PR

- Update translation docs
- Officially `compiler_error!`-forbid `cfg(target_pointer_width = "16")`
- `TextRange::before` (alt options: `TextRange::to`, `TextRange::up_to`, `TextRangeTo`, `TextSize::prefix`)
- `TextRange::after` (alt options: `TextSize::suffix`)
- `TextRange::offset` (alt options: `TextRange::add`, `Add::add`, `TextRange::reanchor`)
- `TextSize::one` (alt options: )
- `TextSize::ONE` (alt options: `TextSize::ASCII`
- `#[inline]` capability for a bunch of things

This PR is mainly just to get opinions on all of these little things, then I'll re-force-push with a commit just with those.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-19 16:50:42 +00:00
CAD97
b87db0e34f Remove unneeded import 2020-03-19 12:38:54 -04:00
CAD97
e8011ac880 Remove TextRange::offset (for now?) 2020-03-19 11:35:52 -04:00
CAD97
a3d5d63208 Remove TextSize::ASCII 2020-03-19 11:30:40 -04:00
CAD97
14a1f78557 Remove incorrect doc comment 2020-03-19 11:29:54 -04:00
CAD97
156f423434 rename TextRange::before to up_to 2020-03-19 11:29:36 -04:00
CAD97
347db5a780 remove TextRange::after 2020-03-18 17:23:37 -04:00
CAD97
e89c6e8b1b replace one with ascii 2020-03-18 17:22:00 -04:00
CAD97
0c77efb0c5 Add #[inline] to most things 2020-03-18 17:21:02 -04:00
CAD97
6d6e97e901 minor improvements everywhere 2020-03-18 17:21:02 -04:00
bors[bot]
951853a9d0 Merge rust-analyzer/text-size#20
20: Don't silently wrap for too-large str r=matklad a=CAD97

Closes rust-analyzer/text-size#19 

Co-authored-by: CAD97 <cad97@cad97.com>
Co-authored-by: Christopher Durham <cad97@cad97.com>
2020-03-15 15:19:08 +00:00
Christopher Durham
d988daaedc Add missing _ 2020-03-15 11:15:37 -04:00
CAD97
a5f9151896 Don't silently wrap for too-large str 2020-03-14 22:17:24 -04:00
CAD97
e9f7d87ee6 minor serde style fix 2020-03-14 21:50:15 -04:00
Aleksey Kladov
bb763ae76a Check invariant during deserialization 2020-03-13 21:28:14 +01:00
bors[bot]
41299f705e Merge rust-analyzer/text-size#13
13: Alternative set of contains function r=CAD97 a=matklad

Motivation:

TextRange is a set, it contains elements (TextSize). For this reason,
for range-range op we use a more verbose `contains_range` name.

In stdlib, there's `HashSet::is_subset`. We used a similar design with
`is_subrage` before, but it was very confusing in practice -- you'll
have to lookup docs for which of lhs and rhs is sub and super set.

Additionally, exclusive semantics is a clear default with better
properties (if you have a partitioning of a range into subranges, only
one of the parts contains any given offset), so it make sense to call
it `contains` and reserve `contains_inclusive` for another op.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-03-13 15:40:03 +00:00
bors[bot]
481494f76d Merge rust-analyzer/text-size#8
8: Provide ref-transparent ops for TextSize r=matklad a=CAD97

Counter-proposal to rust-analyzer/text-size#7. Basically the same set of impls, but set up slightly differently.

Co-authored-by: CAD97 <cad97@cad97.com>
2020-03-13 14:43:59 +00:00