diff --git a/.gitignore b/.gitignore index 6c7e3e3..838009c 100644 --- a/.gitignore +++ b/.gitignore @@ -192,3 +192,4 @@ Cargo.lock # mkdocs site/ +.aider* diff --git a/crates/djls-server/src/diagnostics.rs b/crates/djls-server/src/diagnostics.rs index 09ce53a..710bcd5 100644 --- a/crates/djls-server/src/diagnostics.rs +++ b/crates/djls-server/src/diagnostics.rs @@ -1,17 +1,16 @@ -use tower_lsp::lsp_types::*; use crate::documents::TextDocument; +use djls_template_ast::ast::{LineOffsets, Node, Span}; use djls_template_ast::{Lexer, Parser}; -use djls_template_ast::ast::{Ast, Node, LineOffsets, Span}; -use djls_template_ast::tokens::TokenStream; +use tower_lsp::lsp_types::*; pub struct Diagnostics; impl Diagnostics { pub fn generate_for_document(document: &TextDocument) -> Vec { let mut diagnostics = Vec::new(); - + let text = document.get_text(); - let lexer = Lexer::new(text); + let mut lexer = Lexer::new(text); let token_stream = match lexer.tokenize() { Ok(tokens) => tokens, Err(e) => { @@ -60,7 +59,7 @@ impl Diagnostics { if let Some(closing) = block.closing() { } else { let span = block.tag().span; - let range = get_range_from_span(&ast.line_offsets(), &span); + let range = get_range_from_span(ast.line_offsets(), &span); diagnostics.push(Diagnostic { range, severity: Some(DiagnosticSeverity::ERROR), @@ -70,9 +69,9 @@ impl Diagnostics { ..Default::default() }); } - }, - Node::Variable { .. } => {}, - _ => {}, + } + Node::Variable { .. } => {} + _ => {} } } @@ -81,8 +80,9 @@ impl Diagnostics { } fn get_range_from_span(line_offsets: &LineOffsets, span: &Span) -> Range { - let (start_line, start_col) = line_offsets.position_to_line_col(span.start as usize); - let (end_line, end_col) = line_offsets.position_to_line_col((span.start + span.length) as usize); + let (start_line, start_col) = line_offsets.position_to_line_col(span.start() as usize); + let (end_line, end_col) = + line_offsets.position_to_line_col((span.start() + span.length()) as usize); Range { start: Position::new(start_line as u32 - 1, start_col as u32), diff --git a/crates/djls-server/src/lib.rs b/crates/djls-server/src/lib.rs index 232384f..b96e7e0 100644 --- a/crates/djls-server/src/lib.rs +++ b/crates/djls-server/src/lib.rs @@ -1,3 +1,4 @@ +mod diagnostics; mod documents; mod server; mod tasks; diff --git a/crates/djls-template-ast/src/lib.rs b/crates/djls-template-ast/src/lib.rs index 4c76429..ceb69e7 100644 --- a/crates/djls-template-ast/src/lib.rs +++ b/crates/djls-template-ast/src/lib.rs @@ -1,8 +1,8 @@ -mod ast; -mod lexer; -mod parser; +pub mod ast; +pub mod lexer; +pub mod parser; mod tagspecs; -mod tokens; +pub mod tokens; -pub use ast::Ast; +pub use lexer::Lexer; pub use parser::Parser; diff --git a/crates/djls-template-ast/src/parser.rs b/crates/djls-template-ast/src/parser.rs index 0ff0f35..ffceffd 100644 --- a/crates/djls-template-ast/src/parser.rs +++ b/crates/djls-template-ast/src/parser.rs @@ -92,7 +92,7 @@ impl Parser { let tag_name = bits.first().ok_or(ParserError::EmptyTag)?.clone(); let span = Span::from(token); - let tag_span = Span::new(*span.start(), tag_name.len() as u32); + let tag_span = Span::new(span.start(), tag_name.len() as u32); let assignment = if bits.len() >= 2 { let second_to_last_index = bits.len() - 2;