Commit Graph

137 Commits

Author SHA1 Message Date
Brendan Zabarauskas a722a97853 Release version 0.11.0
We've skipped some versions for `codespan-reporting` and `codespan` to get the crate versions back in sync with `codespan-lsp`.

Co-authored-by: Johann150 <20990607+Johann150@users.noreply.github.com>
2020-11-30 10:40:38 +11:00
Johann150 4f0753bd9d replace gitter with matrix room
missed in #276
2020-10-08 21:07:55 +02:00
Johann150 8a0fc021bc change error types (#295)
- move error to files module; removed the special error types from codespan-lsp
- use error type in codespan and codespan-lsp
- make dependency on codespan-reporting non-optional
2020-10-07 14:01:20 +02:00
Johann150 97fc1abc75 write changelog
Just looked through all closed pull requests since the last release.
Left out anything related to codespan-lsp since there were already versions released for that.
I assume the changelog for that has been maintained.
2020-10-02 15:48:44 +02:00
Andrew Hickman d9cf655f30 Fix build on wasm with serialization feature`
serde` only implements `Serialize` for `OsString` on
unix and windows.
2020-09-04 12:17:23 +01:00
Johann150 4c4192eb21 Return errors instead of panicking (#275)
Co-authored-by: Markus Westerlind <marwes91@gmail.com>
Co-authored-by: Brendan Zabarauskas <bjzaba@yahoo.com.au>
Co-authored-by: Markus Westerlind <marwes91@gmail.com>
2020-08-31 11:00:36 +10:00
Brendan Zabarauskas a91f8cbce8 Bump cargo version to v0.9.5 2020-06-24 13:34:09 +10:00
Joshua Nelson 42ed4e629e Allow using codespan without codespan-reporting
This copies the implementation of `line_starts` to `codespan`.
2020-06-21 22:53:51 -04:00
Brendan Zabarauskas 48439cbf16 Bump cargo version to v0.9.4 2020-05-18 16:07:30 +10:00
Brendan Zabarauskas 6754918296 Bump cargo version to v0.9.3 2020-04-29 13:27:27 +10:00
Brendan Zabarauskas 41115c2fa8 Bump cargo version to v0.9.2 2020-03-29 13:12:19 +11:00
Brendan Zabarauskas b91716593a Bump cargo version to v0.9.1 2020-03-23 10:32:51 +11:00
Brendan Zabarauskas 84fe919f17 Implement some conversions for indexes and spans 2020-03-20 11:27:59 +11:00
Brendan Zabarauskas c0c8192b0b Bump cargo version to v0.9.0 2020-03-15 16:22:46 +11:00
Brendan Zabarauskas 8eb830f29a Add changelogs to crates
Better late than never!
2020-03-10 12:48:23 +11:00
Brendan Zabarauskas 73fb504127 Remove publish script
I never actually used this! Might as well remove it.
2020-03-10 12:48:11 +11:00
Brendan Zabarauskas 99038f4af4 Rename Files::Origin to Files::Name and improve docs 2020-03-10 09:00:03 +11:00
Brendan Zabarauskas 0acf6d09fe Make codespan-reporting more prominent in README
Since we are trying to now guide people to use `codespan-reporting` directly without relying on codespan, it makes sense to make it more prominent in the README.
2020-03-09 16:24:48 +11:00
Brendan Zabarauskas 25829d80e8 Update cargo dependencies 2020-03-09 15:19:08 +11:00
Brendan Zabarauskas f9c0096042 Remove the Line struct 2020-03-09 15:12:57 +11:00
Brendan Zabarauskas c8f6317fda Remove source field from Line struct
This makes the rendering code a little more clunky, but I think it makes the API of the `Files` trait a bit nicer for implementors of file databases.
2020-03-09 12:36:09 +11:00
Brendan Zabarauskas 33ac2559cd Make line_starts function public
This can make it easier to implement new `Files` implementations.
2020-03-06 17:28:09 +11:00
Brendan Zabarauskas 9cfb5fc0b5 Remove rustfmt config 2020-03-03 16:37:21 +11:00
Brendan Zabarauskas c5525f2e38 Allow references to be returned from lines 2020-02-27 10:46:30 +11:00
Brendan Zabarauskas 8d2a2f29ae Move file-related items into a submodule 2020-02-27 09:54:23 +11:00
Brendan Zabarauskas 9757b938c1 Add reporting feature to codespan crate 2020-02-27 09:21:00 +11:00
Brendan Zabarauskas 3820b9535a Add SimpleFile and SimpleFiles structs
This adds the `SimpleFile` and `SimpleFiles` structures to the `codespan_reporting` crate to get people started with their programming languages. It also inverts the dependency between `codespan` and `codespan_reporting`. That way users of `codespan_reporting` no longer have to depend on `codespan` if they don’t want to.
2020-02-26 21:42:19 +11:00
Brendan Zabarauskas 4c6cf623db Create Files trait 2020-02-24 22:50:33 +11:00
Brendan Zabarauskas 46f9a3c1b8 Merge pull request #166 from brendanzab/reduce-reallocations
Avoid string allocations when printing source snippets
2020-02-24 22:46:51 +11:00
Brendan Zabarauskas 51fe3004c4 Release v0.8.0
Closes #163.
2020-02-24 14:56:11 +11:00
Brendan Zabarauskas b2123ccaab Don’t allocate when measuring line numbers 2020-02-23 14:53:27 +11:00
Brendan Zabarauskas cb451607ef Remove some superfluous type bounds 2020-02-20 14:51:42 +11:00
Brendan Zabarauskas b2322f1925 Merge pull request #151 from jyn514/osstr
String -> OsString
2020-01-15 15:08:52 +11:00
Joshua Nelson 7790785431 String -> OsString
Allows storing arbitrary filenames in `File`

Closes https://github.com/brendanzab/codespan/issues/150
2020-01-14 22:19:17 -05:00
Joshua Nelson 76d00c0ca2 Fix formatting #2
Co-Authored-By: Brendan Zabarauskas <bjzaba@yahoo.com.au>
2020-01-14 07:46:03 -05:00
Joshua Nelson c1aa6a88b2 Fix formatting
Co-Authored-By: Brendan Zabarauskas <bjzaba@yahoo.com.au>
2020-01-14 07:45:43 -05:00
Joshua Nelson ded164ac28 add disjoint() and merge() 2020-01-14 00:05:32 -05:00
Brendan Zabarauskas ef8d92038f Bump cargo version to 0.7.0 2020-01-06 11:14:46 +11:00
Brendan Zabarauskas 65ac1bbb31 Remove memory_usage feature
The `heapsize` crate is now unmaintained (since servo/heapsize#105).

Closes #146.
2020-01-06 11:14:46 +11:00
Brendan Zabarauskas bd2d88f5a3 Improve type inference for Files::{add, update}
This removes the implicit conversions for the `Files::{add, update}` methods now that we parameterise `Files` by the source type (see #144).
2020-01-06 11:06:54 +11:00
Ryan Cumming d1d0837b26 Merge branch 'master' into make-source-type-generic 2020-01-05 14:20:08 +11:00
Brendan Zabarauskas a808b1e3bd Merge pull request #144 from etaoins/make-file-id-nonzero
Make `FileId` non-zero
2020-01-05 12:50:36 +11:00
Brendan Zabarauskas 1efee46b7d Merge pull request #145 from etaoins/have-span-take-self-by-value
Have `Span` take self by value
2020-01-05 12:48:55 +11:00
Ryan Cumming 4c67f2fc14 Make source type generic
**THIS IS A BREAKING CHANGE**

When porting Arret from `codespan` 0.3 (see etaoins/arret#160) one of
the missing features was being able use non-`String` types for storing
source.

Arret has two potential uses for this:

1. When loading native libraries exposing Arret functions (known as RFI
   libraries) their Arret type is specified as a per-function
   `&'static str`. An example can be seen here:

   https://github.com/etaoins/arret/blob/dfc41bed1c992cc57023359743f68c639d667f25/stdlib/rust/list.rs#L8

   With `codespan` 0.3 we used `Cow<'static str>` to avoid allocating a
   new `String` for every RFI function by pointing directly inside the
   loaded library's binary.

2. Arret is multithreaded but needs to maintain a global `Files`
   instance to allocate `FileId`s. It uses a read-write lock for thread
   safety and is sensitive to contention on that lock in some
   circumstances.

   Because we need a `FileId` in our AST we can't parse the source to
   AST until we've added it to `Files`. However, because `Files` takes
   ownership of the source we need to hold a read lock on `Files` to use
   `files.source()`. The effectively serialises loading source files
   across all threads.

   Previously we used `Arc<FileMap>` to drop the lock on `CodeMap` and
   then parse the `FileMap` locklessly. The API doesn't allow this
   anymore but we could use `Source = Arc<str>` to similar effect.

Unfortunately the above two uses are mutually exclusive using standard
library types. However, either one is an improvement over `String` and a
crate type like `supercow` could potentially satisfy both uses.

This is a breaking change due to adding a new generic parameter to
`Files`. I initially attempted to use a default of `String` but this
doesn't work for `Files::new` due to rust-lang/rust#27336. See
rust-lang/wg-allocators#1 for an analogous case to this.
2020-01-05 12:01:57 +11:00
Ryan Cumming d00e5934c4 Implement heapsize::HeapSizeOf for FileId
We can't derive this automatically as `HeapSizeOf` doesn't know about
`NonZeroU32`
2020-01-05 11:11:49 +11:00
Ryan Cumming 06af42a8c0 Have Span take self by value
This was caught by Clippy. `Span` is an 8 byte copy type so it makes
sense to take it by value instead of reference. This is consistent with
what `merge` was already doing.
2020-01-05 10:28:31 +11:00
Ryan Cumming be868a8450 Make FileId non-zero
When porting from `codespan` 0.3 Arret I needed to track the `FileId`
separately from the `Span` now that the file isn't implied in the span
itself. Having a simple struct like this works for 90% of the cases:

```rust
struct Span {
  file_id: codespan::FileId,
  codespan_span: codespan::Span,
}
```

However, this requires that every time we parse any source we require a
`FileId` which requires a `codespan::Files` to create. This is overkill
in a couple of cases:

1. Unit tests that just need to parse simple Arret strings as a
   shorthand for building our AST

2. Syntax highlighting in the REPL

The compromise in etaoins/arret#160 is to use `Option<FileId>`. I'm not
100% happy with that as the ultimate solution but it was the easiest
path to take during porting. However, this makes the size of the above
struct 13 bytes which will typically be rounded up to 16 bytes for
alignment and padding.

We can use `std::num::NonZeroU32` instead and offset all of our indexes
by 1. This allows the Rust compiler to use 0 to represent the `None`
case and bring the size down to 12 bytes. Because the struct only needs
an alignment of 4 bytes this is more likely to stay as 12 bytes in most
contexts.

A nicer solution would be if Rust had e.g. `NonMaxU32` but it appears
the Rust team instead wants to use const generics so arbitrary niche
values can be specified.
2020-01-05 10:16:35 +11:00
Ryan Cumming 57309b448e Make Span::initial() a const fn
In Arret nearly every intermediate data structure contains a `Span` so
our generated code can be mapped back to source location. However,
they're rarely used until we need to report a diagnostic or generate
debugging information.

This led to a common pattern in unit tests where we use a dummy span to
test intermediate transformations where we aren't starting from actual
Arret source. This used to be a `const` called `EMPTY_SPAN` which can be
used to build other `const` data structures used for testing.

In etaoins/arret#160 we needed to switch to an `empty_span()` function
because there is no longer a `const` constructor for `Span`.

We can't make `Span::new` `const` yet because const functions are not
powerful enough. However, `Span::initial` is perfect for this use case.
2020-01-05 09:55:23 +11:00
David Tolnay 67078a1c4b Fix gutter misalignments 2019-12-28 22:24:56 -05:00
Brendan Zabarauskas 68c8cff6e6 Bump version to v0.6.0 2019-12-18 12:03:16 +11:00