Add quickfix for unknown alias & data types.

This commit is contained in:
KtorZ 2023-10-21 13:57:06 +02:00
parent d965467a53
commit 5986163ba7
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 19 additions and 11 deletions

View File

@ -81,10 +81,10 @@ impl TypedModule {
pub fn has_definition(&self, name: &str) -> bool { pub fn has_definition(&self, name: &str) -> bool {
self.definitions.iter().any(|def| match def { self.definitions.iter().any(|def| match def {
Definition::Fn(f) => f.public && f.name == name, Definition::Fn(f) => f.public && f.name == name,
Definition::TypeAlias(_) => false, Definition::TypeAlias(alias) => alias.public && alias.alias == name,
Definition::DataType(_) => false, Definition::ModuleConstant(cst) => cst.public && cst.name == name,
Definition::DataType(t) => t.public && t.name == name,
Definition::Use(_) => false, Definition::Use(_) => false,
Definition::ModuleConstant(_) => false,
Definition::Test(_) => false, Definition::Test(_) => false,
Definition::Validator(_) => false, Definition::Validator(_) => false,
}) })

View File

@ -968,15 +968,15 @@ impl ExtraData for Error {
| Error::UnknownModuleType { .. } | Error::UnknownModuleType { .. }
| Error::UnknownModuleValue { .. } | Error::UnknownModuleValue { .. }
| Error::UnknownRecordField { .. } | Error::UnknownRecordField { .. }
| Error::UnknownType { .. }
| Error::UnknownTypeConstructor { .. }
| Error::UnnecessarySpreadOperator { .. } | Error::UnnecessarySpreadOperator { .. }
| Error::UpdateMultiConstructorType { .. } | Error::UpdateMultiConstructorType { .. }
| Error::ValidatorImported { .. } | Error::ValidatorImported { .. }
| Error::ValidatorMustReturnBool { .. } => None, | 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()),
} }
} }
} }

View File

@ -5,8 +5,8 @@ use crate::{
use std::collections::HashMap; use std::collections::HashMap;
const UNKNOWN_VARIABLE: &str = "aiken::check::unknown::variable"; const UNKNOWN_VARIABLE: &str = "aiken::check::unknown::variable";
const UNKNOWN_MODULE: &str = "aiken::check::unknown::module"; const UNKNOWN_MODULE: &str = "aiken::check::unknown::module";
const UNKNOWN_TYPE: &str = "aiken::check::unknown::type";
/// Errors for which we can provide quickfixes /// Errors for which we can provide quickfixes
pub enum Quickfix { 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> { pub fn assert(diagnostic: &lsp_types::Diagnostic) -> Option<Quickfix> {
let is_error = diagnostic.severity == Some(lsp_types::DiagnosticSeverity::ERROR); 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); 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); return Some(Quickfix::UnknownModule);
} }