chore: Update .gitignore and refactor diagnostics and parser modules

This commit is contained in:
Josh Thomas 2025-01-07 14:45:07 -06:00 committed by Josh (aider)
parent b9ace15050
commit c4b6bafc49
5 changed files with 19 additions and 17 deletions

1
.gitignore vendored
View file

@ -192,3 +192,4 @@ Cargo.lock
# mkdocs
site/
.aider*

View file

@ -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<Diagnostic> {
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),

View file

@ -1,3 +1,4 @@
mod diagnostics;
mod documents;
mod server;
mod tasks;

View file

@ -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;

View file

@ -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;