Remove quickerror in favor of thiserror

This commit is contained in:
2025-12-09 11:32:14 -07:00
parent 23c2ba4134
commit c531f673a5
13 changed files with 97 additions and 136 deletions

View File

@@ -5,11 +5,10 @@ edition = "2024"
[dependencies]
rust_decimal = { workspace = true }
quick-error = { workspace = true }
lsp-types = { workspace = true }
thiserror = { workspace = true }
helpers = { path = "../helpers" }
logos = "0.16"
thiserror = "2"
[dev-dependencies]
anyhow = { version = "^1" }

View File

@@ -1,26 +1,20 @@
pub mod token;
use logos::{Lexer, Logos};
use quick_error::quick_error;
use std::{
cmp::Ordering,
collections::VecDeque,
io::{Read, Seek, SeekFrom},
};
use thiserror::Error;
use token::{Token, TokenType};
quick_error! {
#[derive(Debug)]
pub enum Error {
IOError(err: std::io::Error) {
from()
display("IO Error: {}", err)
source(err)
}
LexError(err: token::LexError) {
from()
}
}
#[derive(Error, Debug)]
pub enum Error {
#[error("IO Error: {0}")]
IOError(#[from()] std::io::Error),
#[error(transparent)]
LexError(#[from] token::LexError),
}
impl From<Error> for lsp_types::Diagnostic {

View File

@@ -7,7 +7,7 @@ use thiserror::Error;
#[derive(Debug, Error, Default, Clone, PartialEq)]
pub enum LexError {
#[error("Attempted to parse an invalid number: {2}")]
NumberParseError(usize, Span, String),
NumberParse(usize, Span, String),
#[error("An invalid character was found in token stream: {2}")]
InvalidInput(usize, Span, String),
@@ -20,7 +20,7 @@ pub enum LexError {
impl From<LexError> for Diagnostic {
fn from(value: LexError) -> Self {
match value {
LexError::NumberParseError(line, col, str) | LexError::InvalidInput(line, col, str) => {
LexError::NumberParse(line, col, str) | LexError::InvalidInput(line, col, str) => {
Diagnostic {
range: Range {
start: Position {
@@ -281,13 +281,13 @@ fn parse_number<'a>(lexer: &mut Lexer<'a, TokenType>) -> Result<Number, LexError
Number::Decimal(
clean_str
.parse::<Decimal>()
.map_err(|_| LexError::NumberParseError(line, span, slice.to_string()))?,
.map_err(|_| LexError::NumberParse(line, span, slice.to_string()))?,
)
} else {
Number::Integer(
clean_str
.parse::<i128>()
.map_err(|_| LexError::NumberParseError(line, span, slice.to_string()))?,
.map_err(|_| LexError::NumberParse(line, span, slice.to_string()))?,
)
};