mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-07-07 20:55:02 +00:00
use nightly rustfmt and sort imports (#145)
Some checks are pending
lint / pre-commit (push) Waiting to run
release / build (push) Waiting to run
release / test (push) Waiting to run
release / release (push) Blocked by required conditions
test / generate-matrix (push) Waiting to run
test / Python , Django () (push) Blocked by required conditions
test / tests (push) Blocked by required conditions
zizmor 🌈 / zizmor latest via PyPI (push) Waiting to run
Some checks are pending
lint / pre-commit (push) Waiting to run
release / build (push) Waiting to run
release / test (push) Waiting to run
release / release (push) Blocked by required conditions
test / generate-matrix (push) Waiting to run
test / Python , Django () (push) Blocked by required conditions
test / tests (push) Blocked by required conditions
zizmor 🌈 / zizmor latest via PyPI (push) Waiting to run
This commit is contained in:
parent
00140c58ca
commit
e87c917cb6
25 changed files with 143 additions and 60 deletions
6
.github/workflows/lint.yml
vendored
6
.github/workflows/lint.yml
vendored
|
@ -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:
|
||||
|
|
|
@ -29,7 +29,7 @@ repos:
|
|||
types:
|
||||
- rust
|
||||
language: rust
|
||||
entry: cargo fmt
|
||||
entry: cargo +nightly fmt
|
||||
args:
|
||||
- --
|
||||
- id: check
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
group_imports = "StdExternalCrate"
|
||||
imports_granularity = "Item"
|
||||
imports_layout = "Vertical"
|
||||
reorder_imports = true
|
||||
unstable_features = true
|
|
@ -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)]
|
||||
|
@ -85,10 +90,12 @@ impl Settings {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
|
||||
use tempfile::tempdir;
|
||||
|
||||
use super::*;
|
||||
|
||||
mod defaults {
|
||||
use super::*;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
|
|
@ -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> {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -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> {
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
|
|
@ -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>);
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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<()>`.
|
||||
|
@ -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();
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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}")]
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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()?;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
mod serve;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Subcommand;
|
||||
|
||||
use crate::args::Args;
|
||||
use crate::exit::Exit;
|
||||
use anyhow::Result;
|
||||
use clap::Subcommand;
|
||||
|
||||
pub trait Command {
|
||||
fn execute(&self, args: &Args) -> Result<Exit>;
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use clap::ValueEnum;
|
||||
use djls_server::DjangoLanguageServer;
|
||||
use tower_lsp_server::LspService;
|
||||
use tower_lsp_server::Server;
|
||||
|
||||
use crate::args::Args;
|
||||
use crate::commands::Command;
|
||||
use crate::exit::Exit;
|
||||
use anyhow::Result;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use djls_server::DjangoLanguageServer;
|
||||
use tower_lsp_server::{LspService, Server};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Serve {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use anyhow::Result;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
type ExitMessage = Option<String>;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -8,9 +8,10 @@ mod cli;
|
|||
mod commands;
|
||||
mod exit;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use std::env;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[pyfunction]
|
||||
/// Entry point called by Python when the CLI is invoked.
|
||||
/// This function handles argument parsing from Python and routes to the Rust CLI logic.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue