mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Implement ${count()}
metavariable expression
This commit is contained in:
parent
9ebaa85d37
commit
0d4d1d7e3b
7 changed files with 389 additions and 29 deletions
|
@ -19,6 +19,7 @@ mod benchmark;
|
|||
mod token_map;
|
||||
|
||||
use ::tt::token_id as tt;
|
||||
use stdx::impl_from;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
|
@ -77,8 +78,11 @@ pub enum ExpandError {
|
|||
LimitExceeded,
|
||||
NoMatchingRule,
|
||||
UnexpectedToken,
|
||||
CountError(CountError),
|
||||
}
|
||||
|
||||
impl_from!(CountError for ExpandError);
|
||||
|
||||
impl ExpandError {
|
||||
fn binding_error(e: impl Into<Box<str>>) -> ExpandError {
|
||||
ExpandError::BindingError(Box::new(e.into()))
|
||||
|
@ -94,6 +98,23 @@ impl fmt::Display for ExpandError {
|
|||
ExpandError::ConversionError => f.write_str("could not convert tokens"),
|
||||
ExpandError::LimitExceeded => f.write_str("Expand exceed limit"),
|
||||
ExpandError::LeftoverTokens => f.write_str("leftover tokens"),
|
||||
ExpandError::CountError(e) => e.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Showing these errors could be nicer.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
||||
pub enum CountError {
|
||||
OutOfBounds,
|
||||
Misplaced,
|
||||
}
|
||||
|
||||
impl fmt::Display for CountError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
CountError::OutOfBounds => f.write_str("${count} out of bounds"),
|
||||
CountError::Misplaced => f.write_str("${count} misplaced"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue