Skip to content

Commit cb6ca58

Browse files
committed
refactor diagnostic system
1 parent 288cb6b commit cb6ca58

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/code_analysis/src/compilation/analyzer/doc/infer_type.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pub fn infer_type(analyzer: &mut DocAnalyzer, node: LuaDocType) -> LuaType {
9898
}
9999
_ => {} // LuaDocType::Conditional(lua_doc_conditional_type) => todo!(),
100100
// LuaDocType::Variadic(lua_doc_variadic_type) => todo!(),
101-
// LuaDocType::StrTpl(lua_doc_str_tpl_type) => todo!(),
102101
}
103102
LuaType::Unknown
104103
}

crates/code_analysis/src/diagnostic/checker/duplicate_type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::DiagnosticCode;
33
use super::{DiagnosticContext, LuaChecker};
44

55
#[derive(Debug)]
6-
pub struct DuplicateTypeChecker();
6+
pub struct Checker();
77

8-
impl LuaChecker for DuplicateTypeChecker {
8+
impl LuaChecker for Checker {
99
fn check(&self, context: &mut DiagnosticContext) -> Option<()> {
1010
let errors = {
1111
let db = context.get_db();
@@ -14,7 +14,7 @@ impl LuaChecker for DuplicateTypeChecker {
1414
let errors = diagnostic_index.get_diagnostics(file_id)?;
1515
let mut analyze_errs = Vec::new();
1616
for error in errors {
17-
if error.kind == DiagnosticCode::DuplicateType {
17+
if error.kind == self.get_code() {
1818
analyze_errs.push((error.message.clone(), error.range.clone()));
1919
}
2020
}

crates/code_analysis/src/diagnostic/checker/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ pub trait LuaChecker: Debug + Send + Sync {
1616
fn get_code(&self) -> DiagnosticCode;
1717
}
1818

19+
macro_rules! checker {
20+
($name:ident) => {
21+
Box::new($name::Checker())
22+
};
23+
}
24+
1925
pub fn init_checkers() -> Vec<Box<dyn LuaChecker>> {
2026
vec![
21-
Box::new(syntax_error::SyntaxErrorChecker()),
22-
Box::new(type_not_found::TypeNotFoundChecker()),
23-
Box::new(duplicate_type::DuplicateTypeChecker()),
27+
checker!(syntax_error),
28+
checker!(type_not_found),
29+
checker!(duplicate_type),
2430
]
2531
}
2632

crates/code_analysis/src/diagnostic/checker/syntax_error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::DiagnosticCode;
33
use super::{DiagnosticContext, LuaChecker};
44

55
#[derive(Debug)]
6-
pub struct SyntaxErrorChecker();
6+
pub struct Checker();
77

8-
impl LuaChecker for SyntaxErrorChecker {
8+
impl LuaChecker for Checker {
99
fn check(&self, context: &mut DiagnosticContext) -> Option<()> {
1010
let semantic_model = &context.semantic_model;
1111
if let Some(parse_errors) = semantic_model.get_file_parse_error() {

crates/code_analysis/src/diagnostic/checker/type_not_found.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::DiagnosticCode;
33
use super::{DiagnosticContext, LuaChecker};
44

55
#[derive(Debug)]
6-
pub struct TypeNotFoundChecker();
6+
pub struct Checker();
77

8-
impl LuaChecker for TypeNotFoundChecker {
8+
impl LuaChecker for Checker {
99
fn check(&self, context: &mut DiagnosticContext) -> Option<()> {
1010
let errors = {
1111
let db = context.get_db();

crates/emmylua_ls/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "emmylua_ls"
3-
version = "0.1.0"
3+
version = "0.1.3"
44
edition = "2021"
55

66
[dependencies]
@@ -20,4 +20,4 @@ notify.workspace = true
2020
tokio-util.workspace = true
2121
rowan.workspace = true
2222
emmylua_codestyle.workspace = true
23-
walkdir.workspace = true
23+
walkdir.workspace = true

0 commit comments

Comments
 (0)