diff --git a/crates/djls-workspace/src/db.rs b/crates/djls-workspace/src/db.rs index deaccc7..0290897 100644 --- a/crates/djls-workspace/src/db.rs +++ b/crates/djls-workspace/src/db.rs @@ -61,6 +61,7 @@ pub trait Db: salsa::Database { pub struct Database { storage: salsa::Storage, + // TODO: does this need to be an Option? /// File system for reading file content (checks buffers first, then disk). fs: Option>, @@ -98,7 +99,6 @@ impl Default for Database { } impl Database { - /// Create a new database with fresh storage. pub fn new(file_system: Arc, files: Arc>) -> Self { Self { storage: salsa::Storage::new(None), @@ -109,8 +109,6 @@ impl Database { } } - /// Create a database instance from an existing storage. - /// This preserves both the file system and files Arc across database operations. pub fn from_storage( storage: salsa::Storage, file_system: Arc, @@ -136,9 +134,8 @@ impl Database { /// Get or create a [`SourceFile`] for the given path. /// - /// This method implements Ruff's pattern for lazy file creation. Files are created - /// with an initial revision of 0 and tracked in the [`Database`]'s `DashMap`. The `Arc` - /// ensures cheap cloning while maintaining thread safety. + /// Files are created with an initial revision of 0 and tracked in the [`Database`]'s + /// `DashMap`. The `Arc` ensures cheap cloning while maintaining thread safety. pub fn get_or_create_file(&mut self, path: PathBuf) -> SourceFile { if let Some(file_ref) = self.files.get(&path) { // Copy the value (SourceFile is Copy) and drop the guard immediately @@ -242,9 +239,6 @@ pub struct SourceFile { } /// Read file content, creating a Salsa dependency on the file's revision. -/// -/// **Critical**: The call to `file.revision(db)` creates the dependency chain. -/// Without it, revision changes won't trigger query invalidation. #[salsa::tracked] pub fn source_text(db: &dyn Db, file: SourceFile) -> Arc { // This line creates the Salsa dependency on revision! Without this call, @@ -260,18 +254,6 @@ pub fn source_text(db: &dyn Db, file: SourceFile) -> Arc { } } -/// Global input configuring ordered template loader roots. -/// -/// [`TemplateLoaderOrder`] represents the Django `TEMPLATES[n]['DIRS']` configuration, -/// defining the search order for template resolution. This is a global input that -/// affects template name resolution across the entire project. -#[salsa::input] -pub struct TemplateLoaderOrder { - /// Ordered list of template root directories - #[returns(ref)] - pub roots: Arc<[String]>, -} - /// Represents a file path for Salsa tracking. /// /// [`FilePath`] is a Salsa input entity that tracks a file path for use in @@ -347,7 +329,8 @@ pub fn parse_template_by_path(db: &dyn Db, file_path: FilePath) -> Option { // Convert errors to strings @@ -367,31 +350,6 @@ pub fn parse_template_by_path(db: &dyn Db, file_path: FilePath) -> Option Arc<[String]> { - parse_template_by_path(db, file_path) - .map_or_else(|| Arc::from(vec![]), |ast| Arc::from(ast.errors.clone())) -} - -/// Get template parsing errors for a file. -/// -/// This Salsa tracked function extracts just the errors from the parsed template, -/// useful for diagnostics without needing the full AST. -/// -/// Returns an empty vector for non-template files. -#[salsa::tracked] -pub fn template_errors(db: &dyn Db, file: SourceFile) -> Arc<[String]> { - parse_template(db, file).map_or_else(|| Arc::from(vec![]), |ast| Arc::from(ast.errors.clone())) -} - #[cfg(test)] mod tests { use dashmap::DashMap; diff --git a/crates/djls-workspace/src/document.rs b/crates/djls-workspace/src/document.rs index 60c70bb..eb67d47 100644 --- a/crates/djls-workspace/src/document.rs +++ b/crates/djls-workspace/src/document.rs @@ -30,7 +30,6 @@ pub struct TextDocument { } impl TextDocument { - /// Create a new [`TextDocument`] with the given content #[must_use] pub fn new(content: String, version: i32, language_id: LanguageId) -> Self { let line_index = LineIndex::new(&content); @@ -42,19 +41,16 @@ impl TextDocument { } } - /// Get the document's content #[must_use] pub fn content(&self) -> &str { &self.content } - /// Get the version number #[must_use] pub fn version(&self) -> i32 { self.version } - /// Get the language identifier #[must_use] pub fn language_id(&self) -> LanguageId { self.language_id.clone() @@ -65,6 +61,7 @@ impl TextDocument { &self.line_index } + #[must_use] pub fn get_line(&self, line: u32) -> Option { let line_start = *self.line_index.line_starts.get(line as usize)?; let line_end = self @@ -77,6 +74,7 @@ impl TextDocument { Some(self.content[line_start as usize..line_end as usize].to_string()) } + #[must_use] pub fn get_text_range(&self, range: Range) -> Option { let start_offset = self.line_index.offset(range.start)? as usize; let end_offset = self.line_index.offset(range.end)? as usize; @@ -100,6 +98,7 @@ impl TextDocument { self.version = version; } + #[must_use] pub fn get_template_tag_context(&self, position: Position) -> Option { let start = self.line_index.line_starts.get(position.line as usize)?; let end = self @@ -135,10 +134,12 @@ impl TextDocument { }) } + #[must_use] pub fn position_to_offset(&self, position: Position) -> Option { self.line_index.offset(position) } + #[must_use] pub fn offset_to_position(&self, offset: u32) -> Position { self.line_index.position(offset) } diff --git a/crates/djls-workspace/src/fs.rs b/crates/djls-workspace/src/fs.rs index b0e7ac3..00b5cb1 100644 --- a/crates/djls-workspace/src/fs.rs +++ b/crates/djls-workspace/src/fs.rs @@ -1,4 +1,4 @@ -//! File system abstraction following Ruff's pattern +//! Virtual file system abstraction //! //! This module provides the [`FileSystem`] trait that abstracts file I/O operations. //! This allows the LSP to work with both real files and in-memory overlays. @@ -121,7 +121,7 @@ impl FileSystem for OsFileSystem { /// LSP file system that intercepts reads for buffered files. /// -/// This implements Ruff's two-layer architecture where Layer 1 (open [`Buffers`]) +/// This implements a two-layer architecture where Layer 1 (open [`Buffers`]) /// takes precedence over Layer 2 (Salsa database). When a file is read, /// this system first checks for a buffer (in-memory content from /// [`TextDocument`](crate::document::TextDocument)) and returns that content. @@ -137,7 +137,6 @@ pub struct WorkspaceFileSystem { } impl WorkspaceFileSystem { - /// Create a new [`WorkspaceFileSystem`] with the given buffer storage and fallback #[must_use] pub fn new(buffers: Buffers, disk: Arc) -> Self { Self { buffers, disk } diff --git a/crates/djls-workspace/src/template.rs b/crates/djls-workspace/src/template.rs index 2ebc324..b2bd44b 100644 --- a/crates/djls-workspace/src/template.rs +++ b/crates/djls-workspace/src/template.rs @@ -3,6 +3,8 @@ //! Detects cursor position context within Django template tags to provide //! appropriate completions and auto-closing behavior. +// TODO: is this module in the right spot or even needed? + /// Tracks what closing characters are needed to complete a template tag. /// /// Used to determine whether the completion system needs to insert