Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ djls-ide = { path = "crates/djls-ide" }
djls-project = { path = "crates/djls-project" }
djls-semantic = { path = "crates/djls-semantic" }
djls-server = { path = "crates/djls-server" }
djls-source = { path = "crates/djls-source" }
djls-templates = { path = "crates/djls-templates" }
djls-workspace = { path = "crates/djls-workspace" }

Expand Down
1 change: 1 addition & 0 deletions crates/djls-conf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
anyhow = { workspace = true }
camino = { workspace = true }
config = { workspace = true }
directories = { workspace = true }
serde = { workspace = true }
Expand Down
73 changes: 44 additions & 29 deletions crates/djls-conf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod tagspecs;
use std::fs;
use std::path::Path;

use camino::Utf8Path;
use config::Config;
use config::ConfigError as ExternalConfigError;
use config::File;
Expand Down Expand Up @@ -40,15 +41,15 @@ pub struct Settings {
}

impl Settings {
pub fn new(project_root: &Path) -> Result<Self, ConfigError> {
pub fn new(project_root: &Utf8Path) -> Result<Self, ConfigError> {
let user_config_file = ProjectDirs::from("com.github", "joshuadavidthomas", "djls")
.map(|proj_dirs| proj_dirs.config_dir().join("djls.toml"));

Self::load_from_paths(project_root, user_config_file.as_deref())
}

fn load_from_paths(
project_root: &Path,
project_root: &Utf8Path,
user_config_path: Option<&Path>,
) -> Result<Self, ConfigError> {
let mut builder = Config::builder();
Expand All @@ -74,13 +75,13 @@ impl Settings {
}

builder = builder.add_source(
File::from(project_root.join(".djls.toml"))
File::from(project_root.join(".djls.toml").as_std_path())
.format(FileFormat::Toml)
.required(false),
);

builder = builder.add_source(
File::from(project_root.join("djls.toml"))
File::from(project_root.join("djls.toml").as_std_path())
.format(FileFormat::Toml)
.required(false),
);
Expand Down Expand Up @@ -120,7 +121,7 @@ mod tests {
#[test]
fn test_load_no_files() {
let dir = tempdir().unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
// Add assertions for future default fields here
assert_eq!(
settings,
Expand All @@ -140,7 +141,7 @@ mod tests {
fn test_load_djls_toml_only() {
let dir = tempdir().unwrap();
fs::write(dir.path().join("djls.toml"), "debug = true").unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
assert_eq!(
settings,
Settings {
Expand All @@ -154,7 +155,7 @@ mod tests {
fn test_load_venv_path_config() {
let dir = tempdir().unwrap();
fs::write(dir.path().join("djls.toml"), "venv_path = '/path/to/venv'").unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
assert_eq!(
settings,
Settings {
Expand All @@ -168,7 +169,7 @@ mod tests {
fn test_load_dot_djls_toml_only() {
let dir = tempdir().unwrap();
fs::write(dir.path().join(".djls.toml"), "debug = true").unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
assert_eq!(
settings,
Settings {
Expand All @@ -184,7 +185,7 @@ mod tests {
// Write the setting under [tool.djls]
let content = "[tool.djls]\ndebug = true\n";
fs::write(dir.path().join("pyproject.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
assert_eq!(
settings,
Settings {
Expand All @@ -203,7 +204,7 @@ mod tests {
let dir = tempdir().unwrap();
fs::write(dir.path().join(".djls.toml"), "debug = false").unwrap();
fs::write(dir.path().join("djls.toml"), "debug = true").unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
// djls.toml wins
assert_eq!(
settings,
Expand All @@ -220,7 +221,7 @@ mod tests {
let pyproject_content = "[tool.djls]\ndebug = false\n";
fs::write(dir.path().join("pyproject.toml"), pyproject_content).unwrap();
fs::write(dir.path().join(".djls.toml"), "debug = true").unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
// .djls.toml wins
assert_eq!(
settings,
Expand All @@ -238,7 +239,7 @@ mod tests {
fs::write(dir.path().join("pyproject.toml"), pyproject_content).unwrap();
fs::write(dir.path().join(".djls.toml"), "debug = false").unwrap();
fs::write(dir.path().join("djls.toml"), "debug = true").unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();
// djls.toml wins
assert_eq!(
settings,
Expand All @@ -258,8 +259,11 @@ mod tests {
let pyproject_content = "[tool.djls]\ndebug = false\n"; // Project: false
fs::write(project_dir.path().join("pyproject.toml"), pyproject_content).unwrap();

let settings =
Settings::load_from_paths(project_dir.path(), Some(&user_conf_path)).unwrap();
let settings = Settings::load_from_paths(
Utf8Path::from_path(project_dir.path()).unwrap(),
Some(&user_conf_path),
)
.unwrap();
// pyproject.toml overrides user
assert_eq!(
settings,
Expand All @@ -278,8 +282,11 @@ mod tests {
fs::write(&user_conf_path, "debug = true").unwrap(); // User: true
fs::write(project_dir.path().join("djls.toml"), "debug = false").unwrap(); // Project: false

let settings =
Settings::load_from_paths(project_dir.path(), Some(&user_conf_path)).unwrap();
let settings = Settings::load_from_paths(
Utf8Path::from_path(project_dir.path()).unwrap(),
Some(&user_conf_path),
)
.unwrap();
// djls.toml overrides user
assert_eq!(
settings,
Expand All @@ -301,8 +308,11 @@ mod tests {
let user_conf_path = user_dir.path().join("config.toml");
fs::write(&user_conf_path, "debug = true").unwrap();

let settings =
Settings::load_from_paths(project_dir.path(), Some(&user_conf_path)).unwrap();
let settings = Settings::load_from_paths(
Utf8Path::from_path(project_dir.path()).unwrap(),
Some(&user_conf_path),
)
.unwrap();
assert_eq!(
settings,
Settings {
Expand All @@ -321,8 +331,11 @@ mod tests {
fs::write(project_dir.path().join("pyproject.toml"), pyproject_content).unwrap();

// Should load project settings fine, ignoring non-existent user config
let settings =
Settings::load_from_paths(project_dir.path(), Some(&user_conf_path)).unwrap();
let settings = Settings::load_from_paths(
Utf8Path::from_path(project_dir.path()).unwrap(),
Some(&user_conf_path),
)
.unwrap();
assert_eq!(
settings,
Settings {
Expand All @@ -339,7 +352,9 @@ mod tests {
fs::write(project_dir.path().join("djls.toml"), "debug = true").unwrap();

// Call helper with None for user path
let settings = Settings::load_from_paths(project_dir.path(), None).unwrap();
let settings =
Settings::load_from_paths(Utf8Path::from_path(project_dir.path()).unwrap(), None)
.unwrap();
assert_eq!(
settings,
Settings {
Expand All @@ -358,7 +373,7 @@ mod tests {
let dir = tempdir().unwrap();
fs::write(dir.path().join("djls.toml"), "debug = not_a_boolean").unwrap();
// Need to call Settings::new here as load_from_paths doesn't involve ProjectDirs
let result = Settings::new(dir.path());
let result = Settings::new(Utf8Path::from_path(dir.path()).unwrap());
assert!(result.is_err());
assert!(matches!(result.unwrap_err(), ConfigError::Config(_)));
}
Expand Down Expand Up @@ -390,7 +405,7 @@ args = [
]
"#;
fs::write(dir.path().join("djls.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();

assert_eq!(settings.tagspecs().len(), 2);

Expand Down Expand Up @@ -423,7 +438,7 @@ args = [
]
"#;
fs::write(dir.path().join("pyproject.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();

assert_eq!(settings.tagspecs().len(), 1);
let cache = &settings.tagspecs()[0];
Expand All @@ -446,7 +461,7 @@ args = [
]
"#;
fs::write(dir.path().join("djls.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();

let test = &settings.tagspecs()[0];
assert_eq!(test.args.len(), 3);
Expand Down Expand Up @@ -485,7 +500,7 @@ args = [
]
"#;
fs::write(dir.path().join("djls.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();

let if_tag = &settings.tagspecs()[0];
assert_eq!(if_tag.name, "if");
Expand All @@ -508,7 +523,7 @@ args = [
]
"#;
fs::write(dir.path().join("djls.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();

let block_tag = &settings.tagspecs()[0];
assert_eq!(block_tag.name, "block");
Expand All @@ -532,7 +547,7 @@ module = "myapp.tags"
args = []
"#;
fs::write(dir.path().join("djls.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();

assert!(settings.debug());
assert_eq!(settings.venv_path(), Some("/path/to/venv"));
Expand All @@ -557,7 +572,7 @@ args = [
]
"#;
fs::write(dir.path().join("djls.toml"), content).unwrap();
let settings = Settings::new(dir.path()).unwrap();
let settings = Settings::new(Utf8Path::from_path(dir.path()).unwrap()).unwrap();

let test = &settings.tagspecs()[0];
assert_eq!(test.args.len(), 6);
Expand Down
1 change: 1 addition & 0 deletions crates/djls-ide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
djls-project = { workspace = true }
djls-semantic = { workspace = true }
djls-source = { workspace = true }
djls-templates = { workspace = true }
djls-workspace = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/djls-ide/src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use djls_project::TemplateTags;
use djls_semantic::TagArg;
use djls_semantic::TagSpecs;
use djls_workspace::FileKind;
use djls_source::FileKind;
use djls_workspace::PositionEncoding;
use djls_workspace::TextDocument;
use tower_lsp_server::lsp_types;
Expand Down
6 changes: 3 additions & 3 deletions crates/djls-ide/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use djls_semantic::ValidationError;
use djls_source::File;
use djls_source::Span;
use djls_templates::LineOffsets;
use djls_templates::Span;
use djls_templates::TemplateError;
use djls_templates::TemplateErrorAccumulator;
use djls_workspace::SourceFile;
use tower_lsp_server::lsp_types;

trait DiagnosticError: std::fmt::Display {
Expand Down Expand Up @@ -126,7 +126,7 @@ fn error_to_diagnostic(
#[must_use]
pub fn collect_diagnostics(
db: &dyn djls_semantic::Db,
file: SourceFile,
file: File,
nodelist: Option<djls_templates::NodeList<'_>>,
) -> Vec<lsp_types::Diagnostic> {
let mut diagnostics = Vec::new();
Expand Down
Loading