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
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
with:
persist-credentials: false

- name: Install nightly toolchain for rustfmt
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b
with:
toolchain: nightly
components: rustfmt

- name: Install uv
uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
types:
- rust
language: rust
entry: cargo fmt
entry: cargo +nightly fmt
args:
- --
- id: check
Expand Down
5 changes: 5 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
group_imports = "StdExternalCrate"
imports_granularity = "Item"
imports_layout = "Vertical"
reorder_imports = true
unstable_features = true
13 changes: 10 additions & 3 deletions crates/djls-conf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use config::{Config, ConfigError as ExternalConfigError, File, FileFormat};
use std::fs;
use std::path::Path;

use config::Config;
use config::ConfigError as ExternalConfigError;
use config::File;
use config::FileFormat;
use directories::ProjectDirs;
use serde::Deserialize;
use std::{fs, path::Path};
use thiserror::Error;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -85,10 +90,12 @@ impl Settings {

#[cfg(test)]
mod tests {
use super::*;
use std::fs;

use tempfile::tempdir;

use super::*;

mod defaults {
use super::*;

Expand Down
16 changes: 10 additions & 6 deletions crates/djls-project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ mod python;
mod system;
mod templatetags;

use std::fmt;
use std::path::Path;
use std::path::PathBuf;

use db::ProjectDatabase;
use meta::ProjectMetadata;
use python::{find_python_environment, PythonEnvironment};
pub use templatetags::TemplateTags;

use pyo3::prelude::*;
use std::fmt;
use std::path::{Path, PathBuf};
use python::find_python_environment;
use python::PythonEnvironment;
pub use templatetags::TemplateTags;

#[derive(Debug)]
pub struct DjangoProject {
Expand Down Expand Up @@ -90,10 +92,12 @@ impl fmt::Display for DjangoProject {

#[cfg(test)]
mod tests {
use super::*;
use std::fs;

use tempfile::tempdir;

use super::*;

fn create_mock_django_project(dir: &Path) -> PathBuf {
let project_path = dir.to_path_buf();
fs::create_dir_all(&project_path).unwrap();
Expand Down
21 changes: 15 additions & 6 deletions crates/djls-project/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::fmt;
use std::path::Path;
use std::path::PathBuf;

use pyo3::prelude::*;

use crate::db::Db;
use crate::system;
use pyo3::prelude::*;
use std::fmt;
use std::path::{Path, PathBuf};

#[salsa::tracked]
pub fn find_python_environment(db: &dyn Db) -> Option<PythonEnvironment> {
Expand Down Expand Up @@ -152,12 +155,14 @@ impl fmt::Display for PythonEnvironment {

#[cfg(test)]
mod tests {
use super::*;
use std::fs;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;

use tempfile::tempdir;

use super::*;

fn create_mock_venv(dir: &Path, version: Option<&str>) -> PathBuf {
let prefix = dir.to_path_buf();

Expand Down Expand Up @@ -200,10 +205,14 @@ mod tests {
}

mod env_discovery {
use super::*;
use crate::system::mock::{self as sys_mock, MockGuard};
use which::Error as WhichError;

use super::*;
use crate::system::mock::MockGuard;
use crate::system::mock::{
self as sys_mock,
};

#[test]
fn test_explicit_venv_path_found() {
let project_dir = tempdir().unwrap();
Expand Down
13 changes: 10 additions & 3 deletions crates/djls-project/src/system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env::VarError;
use std::path::PathBuf;

use which::Error as WhichError;

pub fn find_executable(name: &str) -> Result<PathBuf, WhichError> {
Expand All @@ -26,11 +27,12 @@ pub fn env_var(key: &str) -> Result<String, VarError> {

#[cfg(test)]
pub mod mock {
use super::*;
use std::cell::RefCell;
use std::collections::HashMap;
use std::thread_local;

use super::*;

thread_local! {
static MOCK_EXEC_RESULTS: RefCell<HashMap<String, Result<PathBuf, WhichError>>> = RefCell::new(HashMap::new());
static MOCK_ENV_RESULTS: RefCell<HashMap<String, Result<String, VarError>>> = RefCell::new(HashMap::new());
Expand Down Expand Up @@ -95,12 +97,17 @@ pub mod mock {

#[cfg(test)]
mod tests {
use super::mock::{self as sys_mock, MockGuard};
use super::*;
use std::env::VarError;
use std::path::PathBuf;

use which::Error as WhichError;

use super::mock::MockGuard;
use super::mock::{
self as sys_mock,
};
use super::*;

#[test]
fn test_exec_mock_path_retrieval() {
let _guard = MockGuard;
Expand Down
6 changes: 4 additions & 2 deletions crates/djls-project/src/templatetags.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyList};
use std::ops::Deref;

use pyo3::prelude::*;
use pyo3::types::PyDict;
use pyo3::types::PyList;

#[derive(Debug, Default, Clone)]
pub struct TemplateTags(Vec<TemplateTag>);

Expand Down
6 changes: 4 additions & 2 deletions crates/djls-server/src/documents.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::{anyhow, Result};
use djls_project::TemplateTags;
use std::collections::HashMap;

use anyhow::anyhow;
use anyhow::Result;
use djls_project::TemplateTags;
use tower_lsp_server::lsp_types::*;

#[derive(Debug, Default)]
Expand Down
16 changes: 11 additions & 5 deletions crates/djls-server/src/queue.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use anyhow::{anyhow, Result};
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use tokio::sync::{mpsc, oneshot};

use anyhow::anyhow;
use anyhow::Result;
use tokio::sync::mpsc;
use tokio::sync::oneshot;

/// Type alias for a type-erased, pinned, heap-allocated, Send-able future
/// that resolves to `Result<()>`.
Expand Down Expand Up @@ -186,12 +189,15 @@ impl Drop for QueueInner {

#[cfg(test)]
mod tests {
use super::*;
use anyhow::anyhow;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::time::Duration;

use anyhow::anyhow;
use tokio::time::sleep;

use super::*;

#[tokio::test]
async fn test_submit_and_process() {
let queue = Queue::new();
Expand Down
9 changes: 6 additions & 3 deletions crates/djls-server/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::queue::Queue;
use crate::session::Session;
use std::sync::Arc;

use tokio::sync::RwLock;
use tower_lsp_server::jsonrpc::Result as LspResult;
use tower_lsp_server::lsp_types::*;
use tower_lsp_server::{Client, LanguageServer};
use tower_lsp_server::Client;
use tower_lsp_server::LanguageServer;

use crate::queue::Queue;
use crate::session::Session;

const SERVER_NAME: &str = "Django Language Server";
const SERVER_VERSION: &str = "0.1.0";
Expand Down
3 changes: 2 additions & 1 deletion crates/djls-server/src/session.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::documents::Store;
use djls_conf::Settings;
use djls_project::DjangoProject;
use tower_lsp_server::lsp_types::ClientCapabilities;

use crate::documents::Store;

#[derive(Debug, Default)]
pub struct Session {
client_capabilities: Option<ClientCapabilities>,
Expand Down
6 changes: 4 additions & 2 deletions crates/djls-server/src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use percent_encoding::percent_decode_str;
use std::path::PathBuf;
use tower_lsp_server::lsp_types::{InitializeParams, Uri};

use percent_encoding::percent_decode_str;
use tower_lsp_server::lsp_types::InitializeParams;
use tower_lsp_server::lsp_types::Uri;

/// Determines the project root path from initialization parameters.
///
Expand Down
5 changes: 4 additions & 1 deletion crates/djls-templates/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::tokens::{Token, TokenStream, TokenType};
use serde::Serialize;
use thiserror::Error;

use crate::tokens::Token;
use crate::tokens::TokenStream;
use crate::tokens::TokenType;

#[derive(Clone, Debug, Default, Serialize)]
pub struct Ast {
nodelist: Vec<Node>,
Expand Down
8 changes: 5 additions & 3 deletions crates/djls-templates/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::ast::{AstError, Span};
use crate::lexer::LexerError;
use crate::parser::ParserError;
use serde::Serialize;
use thiserror::Error;
use tower_lsp_server::lsp_types;

use crate::ast::AstError;
use crate::ast::Span;
use crate::lexer::LexerError;
use crate::parser::ParserError;

#[derive(Debug, Error, Serialize)]
pub enum TemplateError {
#[error("Lexer error: {0}")]
Expand Down
5 changes: 4 additions & 1 deletion crates/djls-templates/src/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::tokens::{Token, TokenStream, TokenType};
use thiserror::Error;

use crate::tokens::Token;
use crate::tokens::TokenStream;
use crate::tokens::TokenType;

pub struct Lexer {
source: String,
chars: Vec<char>,
Expand Down
8 changes: 5 additions & 3 deletions crates/djls-templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ mod tagspecs;
mod tokens;

use ast::Ast;
pub use error::{to_lsp_diagnostic, QuickFix, TemplateError};

pub use error::to_lsp_diagnostic;
pub use error::QuickFix;
pub use error::TemplateError;
use lexer::Lexer;
pub use parser::{Parser, ParserError};
pub use parser::Parser;
pub use parser::ParserError;

/// Parses a Django template and returns the AST and any parsing errors.
///
Expand Down
12 changes: 9 additions & 3 deletions crates/djls-templates/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use crate::ast::{Ast, AstError, Node, Span};
use crate::lexer::LexerError;
use crate::tokens::{Token, TokenStream, TokenType};
use thiserror::Error;

use crate::ast::Ast;
use crate::ast::AstError;
use crate::ast::Node;
use crate::ast::Span;
use crate::lexer::LexerError;
use crate::tokens::Token;
use crate::tokens::TokenStream;
use crate::tokens::TokenType;

pub struct Parser {
tokens: TokenStream,
current: usize,
Expand Down
9 changes: 6 additions & 3 deletions crates/djls-templates/src/tagspecs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::path::Path;

use anyhow::Result;
use serde::Deserialize;
use serde::Serialize;
use thiserror::Error;
use toml::Value;

Expand Down Expand Up @@ -184,9 +186,10 @@ pub struct EndTag {

#[cfg(test)]
mod tests {
use super::*;
use std::fs;

use super::*;

#[test]
fn test_can_load_builtins() -> Result<(), anyhow::Error> {
let specs = TagSpecs::load_builtin_specs()?;
Expand Down
4 changes: 3 additions & 1 deletion crates/djls-templates/src/tokens.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::ops::Deref;
use std::ops::DerefMut;

use serde::Serialize;
use std::ops::{Deref, DerefMut};

#[derive(Clone, Debug, Serialize, PartialEq)]
pub enum TokenType {
Expand Down
8 changes: 5 additions & 3 deletions crates/djls/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::args::Args;
use crate::commands::{Command, DjlsCommand};
use crate::exit::Exit;
use anyhow::Result;
use clap::Parser;

use crate::args::Args;
use crate::commands::Command;
use crate::commands::DjlsCommand;
use crate::exit::Exit;

/// Main CLI structure that defines the command-line interface
#[derive(Parser)]
#[command(name = "djls")]
Expand Down
Loading