jmacdonald / scribe

Text editor components
MIT License
173 stars 7 forks source link

Syntect upgrade #23

Closed jmacdonald closed 9 months ago

jmacdonald commented 9 months ago

This PR upgrades the syntect dependency to the latest version. Since there are several major version bumps from the current version, there are breaking changes that ultimately affect the public API of scribe. The most notable changes are described below.

TL;DR

Removed

Added

Changed

Buffer tokenization

Tokenization previously only required a syntax definition, but now requires a SyntaxSet too. As a result, buffers are no longer able to produce a TokenSet using only their own fields. Given this added dependency, setting up tokenization is now the responsibility of Workspace::current_buffer_tokens.

Current workspace buffer

Accessing the workspace's current buffer was previously done using Workspace::current_buffer(&mut self). Despite the encapsulation benefits this accessor approach provides, Rust isn't smart enough to infer that we're only borrowing one field, and the entire workspace is borrowed for the given lifetime. This was incompatible with the new tokenization requirements, which use both the syntax set from the workspace and the definition from the buffer; calling current_buffer() on the workspace would make accessing its syntax_set impossible.

To solve this, the current buffer is now accessed directly as a field.

Error propagation

Syntect now returns proper errors instead of panicking. To make proper use of these, the TokenIterator type has been updated to handle Result-based returns. When an error is discovered, iteration is halted, and the error is stored in a public field on the iterator. This allows consumers to check for errors after iterating, rather than on every returned value during iteration.