Add quickfix for unknown alias & data types.
This commit is contained in:
parent
d965467a53
commit
5986163ba7
|
@ -81,10 +81,10 @@ impl TypedModule {
|
|||
pub fn has_definition(&self, name: &str) -> bool {
|
||||
self.definitions.iter().any(|def| match def {
|
||||
Definition::Fn(f) => f.public && f.name == name,
|
||||
Definition::TypeAlias(_) => false,
|
||||
Definition::DataType(_) => false,
|
||||
Definition::TypeAlias(alias) => alias.public && alias.alias == name,
|
||||
Definition::ModuleConstant(cst) => cst.public && cst.name == name,
|
||||
Definition::DataType(t) => t.public && t.name == name,
|
||||
Definition::Use(_) => false,
|
||||
Definition::ModuleConstant(_) => false,
|
||||
Definition::Test(_) => false,
|
||||
Definition::Validator(_) => false,
|
||||
})
|
||||
|
|
|
@ -968,15 +968,15 @@ impl ExtraData for Error {
|
|||
| Error::UnknownModuleType { .. }
|
||||
| Error::UnknownModuleValue { .. }
|
||||
| Error::UnknownRecordField { .. }
|
||||
| Error::UnknownType { .. }
|
||||
| Error::UnknownTypeConstructor { .. }
|
||||
| Error::UnnecessarySpreadOperator { .. }
|
||||
| Error::UpdateMultiConstructorType { .. }
|
||||
| Error::ValidatorImported { .. }
|
||||
| Error::ValidatorMustReturnBool { .. } => None,
|
||||
Error::UnknownVariable { name, .. } | Error::UnknownModule { name, .. } => {
|
||||
Some(name.clone())
|
||||
}
|
||||
|
||||
Error::UnknownType { name, .. }
|
||||
| Error::UnknownTypeConstructor { name, .. }
|
||||
| Error::UnknownVariable { name, .. }
|
||||
| Error::UnknownModule { name, .. } => Some(name.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::{
|
|||
use std::collections::HashMap;
|
||||
|
||||
const UNKNOWN_VARIABLE: &str = "aiken::check::unknown::variable";
|
||||
|
||||
const UNKNOWN_MODULE: &str = "aiken::check::unknown::module";
|
||||
const UNKNOWN_TYPE: &str = "aiken::check::unknown::type";
|
||||
|
||||
/// Errors for which we can provide quickfixes
|
||||
pub enum Quickfix {
|
||||
|
@ -23,11 +23,19 @@ fn match_code(diagnostic: &lsp_types::Diagnostic, expected: &str) -> bool {
|
|||
pub fn assert(diagnostic: &lsp_types::Diagnostic) -> Option<Quickfix> {
|
||||
let is_error = diagnostic.severity == Some(lsp_types::DiagnosticSeverity::ERROR);
|
||||
|
||||
if is_error && match_code(diagnostic, UNKNOWN_VARIABLE) {
|
||||
if !is_error {
|
||||
return None;
|
||||
}
|
||||
|
||||
if match_code(diagnostic, UNKNOWN_VARIABLE) {
|
||||
return Some(Quickfix::UnknownIdentifier);
|
||||
}
|
||||
|
||||
if is_error && match_code(diagnostic, UNKNOWN_MODULE) {
|
||||
if match_code(diagnostic, UNKNOWN_TYPE) {
|
||||
return Some(Quickfix::UnknownIdentifier);
|
||||
}
|
||||
|
||||
if match_code(diagnostic, UNKNOWN_MODULE) {
|
||||
return Some(Quickfix::UnknownModule);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue