mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-08-04 10:08:30 +00:00
lint fix
This commit is contained in:
parent
621832f506
commit
0cf736ad76
15 changed files with 46 additions and 38 deletions
|
@ -79,10 +79,12 @@ impl Settings {
|
|||
Ok(settings)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn debug(&self) -> bool {
|
||||
self.debug
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn venv_path(&self) -> Option<&str> {
|
||||
self.venv_path.as_deref()
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub fn setup_python_linking() {
|
|||
// Only link libpython explicitly if we are NOT building an extension module.
|
||||
if !is_extension_module {
|
||||
if let Some(lib_name) = &config.lib_name {
|
||||
println!("cargo:rustc-link-lib=dylib={}", lib_name);
|
||||
println!("cargo:rustc-link-lib=dylib={lib_name}");
|
||||
} else {
|
||||
// Warn only if linking is actually needed but we can't find the lib name
|
||||
println!("cargo:warning=Python library name not found in config (needed for non-extension module
|
||||
|
@ -43,9 +43,9 @@ builds).");
|
|||
// These are needed for test executables and potential future standalone binaries,
|
||||
// and generally harmless for extension modules.
|
||||
if let Some(lib_dir) = &config.lib_dir {
|
||||
println!("cargo:rustc-link-search=native={}", lib_dir);
|
||||
println!("cargo:rustc-link-search=native={lib_dir}");
|
||||
#[cfg(not(windows))]
|
||||
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir);
|
||||
println!("cargo:rustc-link-arg=-Wl,-rpath,{lib_dir}");
|
||||
} else {
|
||||
// Warn only if linking is actually needed but we can't find the lib dir
|
||||
if !is_extension_module {
|
||||
|
|
|
@ -23,6 +23,7 @@ pub struct DjangoProject {
|
|||
}
|
||||
|
||||
impl DjangoProject {
|
||||
#[must_use]
|
||||
pub fn new(path: PathBuf) -> Self {
|
||||
Self {
|
||||
path,
|
||||
|
@ -64,17 +65,19 @@ impl DjangoProject {
|
|||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to import Django: {}", e);
|
||||
eprintln!("Failed to import Django: {e}");
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn template_tags(&self) -> Option<&TemplateTags> {
|
||||
self.template_tags.as_ref()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn path(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
|
@ -84,7 +87,7 @@ impl fmt::Display for DjangoProject {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f, "Project path: {}", self.path.display())?;
|
||||
if let Some(py_env) = &self.env {
|
||||
write!(f, "{}", py_env)?;
|
||||
write!(f, "{py_env}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -141,7 +144,7 @@ mod tests {
|
|||
|
||||
let project = DjangoProject::new(project_path.clone());
|
||||
|
||||
let display_str = format!("{}", project);
|
||||
let display_str = format!("{project}");
|
||||
assert!(display_str.contains(&format!("Project path: {}", project_path.display())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ impl TemplateTags {
|
|||
let library_name = if module_name.is_empty() {
|
||||
"builtins".to_string()
|
||||
} else {
|
||||
module_name.split('.').last().unwrap_or("").to_string()
|
||||
module_name.split('.').next_back().unwrap_or("").to_string()
|
||||
};
|
||||
|
||||
tags.push(TemplateTag::new(tag_name, library_name, doc));
|
||||
|
|
|
@ -104,7 +104,7 @@ impl Store {
|
|||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_version_valid(&self, uri: &str, version: i32) -> bool {
|
||||
self.get_version(uri).map_or(false, |v| v == version)
|
||||
self.get_version(uri) == Some(version)
|
||||
}
|
||||
|
||||
pub fn get_completions(
|
||||
|
|
|
@ -45,7 +45,7 @@ impl LineOffsets {
|
|||
}
|
||||
|
||||
pub fn position_to_line_col(&self, position: usize) -> (usize, usize) {
|
||||
let position = position as u32;
|
||||
let position = u32::try_from(position).unwrap_or_default();
|
||||
let line = match self.0.binary_search(&position) {
|
||||
Ok(exact_line) => exact_line, // Position is at start of this line
|
||||
Err(0) => 0, // Before first line start
|
||||
|
@ -120,7 +120,7 @@ impl Span {
|
|||
impl From<Token> for Span {
|
||||
fn from(token: Token) -> Self {
|
||||
let start = token.start().unwrap_or(0);
|
||||
let length = token.content().len() as u32;
|
||||
let length = u32::try_from(token.content().len()).unwrap_or(0);
|
||||
Span::new(start, length)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ impl From<std::io::Error> for TemplateError {
|
|||
}
|
||||
|
||||
impl TemplateError {
|
||||
#[must_use]
|
||||
pub fn span(&self) -> Option<Span> {
|
||||
match self {
|
||||
TemplateError::Validation(AstError::InvalidTagStructure { span, .. }) => Some(*span),
|
||||
|
@ -51,6 +52,7 @@ impl TemplateError {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn severity(&self) -> lsp_types::DiagnosticSeverity {
|
||||
match self {
|
||||
TemplateError::Lexer(_) | TemplateError::Parser(_) => {
|
||||
|
@ -61,6 +63,7 @@ impl TemplateError {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn code(&self) -> &'static str {
|
||||
match self {
|
||||
TemplateError::Lexer(_) => "LEX",
|
||||
|
|
|
@ -23,6 +23,7 @@ impl Lexer {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn tokenize(&mut self) -> Result<TokenStream, LexerError> {
|
||||
let mut tokens = TokenStream::default();
|
||||
|
||||
|
@ -76,8 +77,8 @@ impl Lexer {
|
|||
TokenType::ScriptTagOpen(tag)
|
||||
} else if tag.starts_with("style") {
|
||||
TokenType::StyleTagOpen(tag)
|
||||
} else if tag.ends_with("/") {
|
||||
TokenType::HtmlTagVoid(tag.trim_end_matches("/").to_string())
|
||||
} else if tag.ends_with('/') {
|
||||
TokenType::HtmlTagVoid(tag.trim_end_matches('/').to_string())
|
||||
} else {
|
||||
TokenType::HtmlTagOpen(tag)
|
||||
}
|
||||
|
@ -310,7 +311,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_tokenize_comments() {
|
||||
let source = r#"<!-- HTML comment -->
|
||||
let source = r"<!-- HTML comment -->
|
||||
{# Django comment #}
|
||||
<script>
|
||||
// JS single line comment
|
||||
|
@ -319,7 +320,7 @@ mod tests {
|
|||
</script>
|
||||
<style>
|
||||
/* CSS comment */
|
||||
</style>"#;
|
||||
</style>";
|
||||
let mut lexer = Lexer::new(source);
|
||||
let tokens = lexer.tokenize().unwrap();
|
||||
insta::assert_yaml_snapshot!(tokens);
|
||||
|
@ -368,11 +369,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_tokenize_nested_delimiters() {
|
||||
let source = r#"{{ user.name }}
|
||||
let source = r"{{ user.name }}
|
||||
{% if true %}
|
||||
{# comment #}
|
||||
<!-- html comment -->
|
||||
<div>text</div>"#;
|
||||
<div>text</div>";
|
||||
assert!(Lexer::new(source).tokenize().is_ok());
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ pub struct Parser {
|
|||
}
|
||||
|
||||
impl Parser {
|
||||
#[must_use]
|
||||
pub fn new(tokens: TokenStream) -> Self {
|
||||
Self {
|
||||
tokens,
|
||||
|
@ -36,7 +37,7 @@ impl Parser {
|
|||
Err(err) => {
|
||||
if !self.is_at_end() {
|
||||
self.errors.push(err);
|
||||
self.synchronize()?
|
||||
self.synchronize()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +71,7 @@ impl Parser {
|
|||
// Only treat Django comments as Comment nodes
|
||||
if open != "{#" {
|
||||
return self.parse_text();
|
||||
};
|
||||
}
|
||||
|
||||
let token = self.peek_previous()?;
|
||||
|
||||
|
@ -501,7 +502,7 @@ mod tests {
|
|||
let mut parser = Parser::new(tokens);
|
||||
let (nodelist, errors) = parser.parse().unwrap();
|
||||
insta::assert_yaml_snapshot!(nodelist);
|
||||
eprintln!("{:?}", errors);
|
||||
eprintln!("{errors:?}");
|
||||
assert!(errors.is_empty());
|
||||
}
|
||||
}
|
||||
|
@ -636,7 +637,7 @@ mod tests {
|
|||
let (nodelist, errors) = parser.parse().unwrap();
|
||||
|
||||
let offsets = nodelist.line_offsets();
|
||||
eprintln!("{:?}", offsets);
|
||||
eprintln!("{offsets:?}");
|
||||
assert_eq!(offsets.position_to_line_col(0), (1, 0)); // Start of line 1
|
||||
assert_eq!(offsets.position_to_line_col(6), (2, 0)); // Start of line 2
|
||||
assert!(errors.is_empty());
|
||||
|
|
|
@ -92,7 +92,7 @@ impl TagSpecs {
|
|||
Ok(TagSpecs(specs))
|
||||
}
|
||||
|
||||
/// Merge another TagSpecs into this one, with the other taking precedence
|
||||
/// Merge another `TagSpecs` into this one, with the other taking precedence
|
||||
#[allow(dead_code)]
|
||||
pub fn merge(&mut self, other: TagSpecs) -> &mut Self {
|
||||
self.0.extend(other.0);
|
||||
|
@ -138,8 +138,7 @@ impl TagSpec {
|
|||
is_spec_node = true;
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Invalid prefix '{}' resulted in empty tag name component.",
|
||||
p
|
||||
"Invalid prefix '{p}' resulted in empty tag name component."
|
||||
));
|
||||
}
|
||||
} else {
|
||||
|
@ -163,10 +162,10 @@ impl TagSpec {
|
|||
// Otherwise, if it's a table, recurse into its children.
|
||||
if !is_spec_node {
|
||||
if let Some(table) = value.as_table() {
|
||||
for (key, inner_value) in table.iter() {
|
||||
for (key, inner_value) in table {
|
||||
let new_prefix = match prefix {
|
||||
None => key.clone(),
|
||||
Some(p) => format!("{}.{}", p, key),
|
||||
Some(p) => format!("{p}.{key}"),
|
||||
};
|
||||
Self::extract_specs(inner_value, Some(&new_prefix), specs)?;
|
||||
}
|
||||
|
@ -244,14 +243,13 @@ mod tests {
|
|||
];
|
||||
|
||||
for tag in expected_tags {
|
||||
assert!(specs.get(tag).is_some(), "{} tag should be present", tag);
|
||||
assert!(specs.get(tag).is_some(), "{tag} tag should be present");
|
||||
}
|
||||
|
||||
for tag in missing_tags {
|
||||
assert!(
|
||||
specs.get(tag).is_none(),
|
||||
"{} tag should not be present yet",
|
||||
tag
|
||||
"{tag} tag should not be present yet"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ impl Token {
|
|||
| TokenType::StyleTagClose(s) => s.to_string(),
|
||||
TokenType::Whitespace(len) => " ".repeat(*len),
|
||||
TokenType::Newline => "\n".to_string(),
|
||||
TokenType::Eof => "".to_string(),
|
||||
TokenType::Eof => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn run(args: Vec<String>) -> Result<()> {
|
|||
Err(e) => {
|
||||
let mut msg = e.to_string();
|
||||
if let Some(source) = e.source() {
|
||||
msg += &format!(", caused by {}", source);
|
||||
msg += &format!(", caused by {source}");
|
||||
}
|
||||
Exit::error().with_message(msg).process_exit()
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ impl From<ExitStatus> for i32 {
|
|||
impl fmt::Display for ExitStatus {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let msg = self.as_str();
|
||||
write!(f, "{}", msg)
|
||||
write!(f, "{msg}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ impl Exit {
|
|||
|
||||
pub fn process_exit(self) -> ! {
|
||||
if let Some(message) = self.message {
|
||||
println!("{}", message)
|
||||
println!("{message}");
|
||||
}
|
||||
std::process::exit(self.status.as_raw())
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ impl fmt::Display for Exit {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let status_str = self.status.as_str();
|
||||
match &self.message {
|
||||
Some(msg) => write!(f, "{}: {}", status_str, msg),
|
||||
None => write!(f, "{}", status_str),
|
||||
Some(msg) => write!(f, "{status_str}: {msg}"),
|
||||
None => write!(f, "{status_str}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/// PyO3 entrypoint for the Django Language Server CLI.
|
||||
/// `PyO3` entrypoint for the Django Language Server CLI.
|
||||
///
|
||||
/// This module provides a Python interface using PyO3 to solve Python runtime
|
||||
/// interpreter linking issues. The PyO3 approach avoids complexities with
|
||||
/// This module provides a Python interface using `PyO3` to solve Python runtime
|
||||
/// interpreter linking issues. The `PyO3` approach avoids complexities with
|
||||
/// static/dynamic linking when building binaries that interact with Python.
|
||||
mod args;
|
||||
mod cli;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/// Binary interface for local development only.
|
||||
///
|
||||
/// This binary exists for development and testing with `cargo run`.
|
||||
/// The production CLI is distributed through the PyO3 interface in lib.rs.
|
||||
/// The production CLI is distributed through the `PyO3` interface in lib.rs.
|
||||
mod args;
|
||||
mod cli;
|
||||
mod commands;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue