Skip to content

Investigate template file extension detection #465

Description

@joshuadavidthomas

What

When files are passed explicitly to djls check (e.g., by pre-commit), they still go through walk_files() with the is_template predicate, which filters based on FileKind — hardcoded to .html, .htm, .djhtml. A .txt or .xml template passed directly would be silently dropped.

The filtering happens in discover_files() in crates/djls/src/commands/check.rs (line ~163):

let resolved: Vec<Utf8PathBuf> = paths.iter().map(|p| { ... }).collect();
return walk_files(&resolved, is_template, options);

The deeper analysis pipeline (check_file_with_source, check_file) doesn't care about extensions — the gate is purely at the file discovery/walk layer.

The same FileKind::Template check is also used in the LSP server (did_open, did_change, completions, diagnostics) to decide whether to activate features for a file.

Investigation needed

  1. Should explicitly-passed files bypass the extension filter? (Probably yes — if a user passes a file, check it.)
  2. What's the right default set of extensions for directory walking when no project config is available?
  3. Should this be user-configurable in djls.toml / pyproject.toml?
  4. How does this interact with the static settings extraction work (Replace Python inspector subprocess with static settings extraction #401)? Parsing TEMPLATES from settings could inform which extensions to treat as templates.
  5. Audit all FileKind::Template / is_template usage sites — the LSP server uses it too.

Key files

  • crates/djls-source/src/file.rsFileKind enum, hardcoded extensions
  • crates/djls/src/commands/check.rsdiscover_files(), is_template()
  • crates/djls-server/src/server.rs — LSP feature gating
  • crates/djls-templates/src/lib.rs — parser entry point guard

Related

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions