Define 'ExtraData' trait for errors
This should allow passing some extra information to LSP diagnostic in order to provide quickfix actions, such as auto-imports.
This commit is contained in:
parent
41e26b216b
commit
c4221730bf
|
@ -0,0 +1,3 @@
|
||||||
|
pub trait ExtraData {
|
||||||
|
fn extra_data(&self) -> Option<String>;
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ use std::sync::{
|
||||||
|
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
pub mod builtins;
|
pub mod builtins;
|
||||||
|
pub mod error;
|
||||||
pub mod expr;
|
pub mod expr;
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod gen_uplc;
|
pub mod gen_uplc;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use super::Type;
|
use super::Type;
|
||||||
|
use crate::error::ExtraData;
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Annotation, BinOp, CallArg, LogicalOpChainKind, Span, UntypedPattern},
|
ast::{Annotation, BinOp, CallArg, LogicalOpChainKind, Span, UntypedPattern},
|
||||||
expr::{self, UntypedExpr},
|
expr::{self, UntypedExpr},
|
||||||
|
@ -922,6 +923,63 @@ The best thing to do from here is to remove it."#))]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExtraData for Error {
|
||||||
|
fn extra_data(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Error::CastDataNoAnn { .. }
|
||||||
|
| Error::CouldNotUnify { .. }
|
||||||
|
| Error::CyclicTypeDefinitions { .. }
|
||||||
|
| Error::DuplicateArgument { .. }
|
||||||
|
| Error::DuplicateConstName { .. }
|
||||||
|
| Error::DuplicateField { .. }
|
||||||
|
| Error::DuplicateImport { .. }
|
||||||
|
| Error::DuplicateName { .. }
|
||||||
|
| Error::DuplicateTypeName { .. }
|
||||||
|
| Error::DuplicateVarInPattern { .. }
|
||||||
|
| Error::ExtraVarInAlternativePattern { .. }
|
||||||
|
| Error::FunctionTypeInData { .. }
|
||||||
|
| Error::ImplicitlyDiscardedExpression { .. }
|
||||||
|
| Error::IncorrectFieldsArity { .. }
|
||||||
|
| Error::IncorrectFunctionCallArity { .. }
|
||||||
|
| Error::IncorrectPatternArity { .. }
|
||||||
|
| Error::IncorrectTupleArity { .. }
|
||||||
|
| Error::IncorrectTypeArity { .. }
|
||||||
|
| Error::IncorrectValidatorArity { .. }
|
||||||
|
| Error::KeywordInModuleName { .. }
|
||||||
|
| Error::LastExpressionIsAssignment { .. }
|
||||||
|
| Error::LogicalOpChainMissingExpr { .. }
|
||||||
|
| Error::MissingVarInAlternativePattern { .. }
|
||||||
|
| Error::MultiValidatorEqualArgs { .. }
|
||||||
|
| Error::NonLocalClauseGuardVariable { .. }
|
||||||
|
| Error::NotATuple { .. }
|
||||||
|
| Error::NotExhaustivePatternMatch { .. }
|
||||||
|
| Error::NotFn { .. }
|
||||||
|
| Error::PositionalArgumentAfterLabeled { .. }
|
||||||
|
| Error::PrivateTypeLeak { .. }
|
||||||
|
| Error::RecordAccessUnknownType { .. }
|
||||||
|
| Error::RecordUpdateInvalidConstructor { .. }
|
||||||
|
| Error::RecursiveType { .. }
|
||||||
|
| Error::RedundantMatchClause { .. }
|
||||||
|
| Error::TupleIndexOutOfBound { .. }
|
||||||
|
| Error::UnexpectedLabeledArg { .. }
|
||||||
|
| Error::UnexpectedLabeledArgInPattern { .. }
|
||||||
|
| Error::UnknownLabels { .. }
|
||||||
|
| Error::UnknownModule { .. }
|
||||||
|
| Error::UnknownModuleField { .. }
|
||||||
|
| Error::UnknownModuleType { .. }
|
||||||
|
| Error::UnknownModuleValue { .. }
|
||||||
|
| Error::UnknownRecordField { .. }
|
||||||
|
| Error::UnknownType { .. }
|
||||||
|
| Error::UnknownTypeConstructor { .. }
|
||||||
|
| Error::UnnecessarySpreadOperator { .. }
|
||||||
|
| Error::UpdateMultiConstructorType { .. }
|
||||||
|
| Error::ValidatorImported { .. }
|
||||||
|
| Error::ValidatorMustReturnBool { .. } => None,
|
||||||
|
Error::UnknownVariable { name, .. } => Some(name.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
pub fn call_situation(mut self) -> Self {
|
pub fn call_situation(mut self) -> Self {
|
||||||
if let Error::UnknownRecordField {
|
if let Error::UnknownRecordField {
|
||||||
|
@ -1522,6 +1580,30 @@ pub enum Warning {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExtraData for Warning {
|
||||||
|
fn extra_data(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Warning::AllFieldsRecordUpdate { .. }
|
||||||
|
| Warning::ImplicitlyDiscardedResult { .. }
|
||||||
|
| Warning::NoFieldsRecordUpdate { .. }
|
||||||
|
| Warning::PubInValidatorModule { .. }
|
||||||
|
| Warning::SingleConstructorExpect { .. }
|
||||||
|
| Warning::SingleWhenClause { .. }
|
||||||
|
| Warning::Todo { .. }
|
||||||
|
| Warning::UnexpectedTypeHole { .. }
|
||||||
|
| Warning::UnusedConstructor { .. }
|
||||||
|
| Warning::UnusedImportedModule { .. }
|
||||||
|
| Warning::UnusedImportedValue { .. }
|
||||||
|
| Warning::UnusedPrivateFunction { .. }
|
||||||
|
| Warning::UnusedPrivateModuleConstant { .. }
|
||||||
|
| Warning::UnusedType { .. }
|
||||||
|
| Warning::UnusedVariable { .. }
|
||||||
|
| Warning::Utf8ByteArrayIsValidHexString { .. }
|
||||||
|
| Warning::ValidatorInLibraryModule { .. } => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum UnifyErrorSituation {
|
pub enum UnifyErrorSituation {
|
||||||
/// Clauses in a case expression were found to return different types.
|
/// Clauses in a case expression were found to return different types.
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
ast::{self, BinOp, Span},
|
ast::{self, BinOp, Span},
|
||||||
|
error::ExtraData,
|
||||||
parser::error::ParseError,
|
parser::error::ParseError,
|
||||||
tipo,
|
tipo,
|
||||||
};
|
};
|
||||||
|
@ -172,6 +173,34 @@ impl From<Error> for Vec<Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExtraData for Error {
|
||||||
|
fn extra_data(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Error::DuplicateModule { .. } => None,
|
||||||
|
Error::FileIo { .. } => None,
|
||||||
|
Error::Format { .. } => None,
|
||||||
|
Error::StandardIo { .. } => None,
|
||||||
|
Error::Blueprint { .. } => None,
|
||||||
|
Error::MissingManifest { .. } => None,
|
||||||
|
Error::TomlLoading { .. } => None,
|
||||||
|
Error::ImportCycle { .. } => None,
|
||||||
|
Error::Parse { .. } => None,
|
||||||
|
Error::Type { error, .. } => error.extra_data(),
|
||||||
|
Error::TestFailure { .. } => None,
|
||||||
|
Error::Http { .. } => None,
|
||||||
|
Error::ZipExtract { .. } => None,
|
||||||
|
Error::JoinError { .. } => None,
|
||||||
|
Error::UnknownPackageVersion { .. } => None,
|
||||||
|
Error::UnableToResolvePackage { .. } => None,
|
||||||
|
Error::Json { .. } => None,
|
||||||
|
Error::MalformedStakeAddress { .. } => None,
|
||||||
|
Error::NoValidatorNotFound { .. } => None,
|
||||||
|
Error::MoreThanOneValidatorFound { .. } => None,
|
||||||
|
Error::Module { .. } => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait GetSource {
|
pub trait GetSource {
|
||||||
fn path(&self) -> Option<PathBuf>;
|
fn path(&self) -> Option<PathBuf>;
|
||||||
fn src(&self) -> Option<String>;
|
fn src(&self) -> Option<String>;
|
||||||
|
@ -481,6 +510,16 @@ pub enum Warning {
|
||||||
DependencyAlreadyExists { name: PackageName },
|
DependencyAlreadyExists { name: PackageName },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExtraData for Warning {
|
||||||
|
fn extra_data(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Warning::NoValidators { .. } => None,
|
||||||
|
Warning::DependencyAlreadyExists { .. } => None,
|
||||||
|
Warning::Type { warning, .. } => warning.extra_data(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GetSource for Warning {
|
impl GetSource for Warning {
|
||||||
fn path(&self) -> Option<PathBuf> {
|
fn path(&self) -> Option<PathBuf> {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in New Issue