Skip to content

Commit

Permalink
chore: clean up some lints (bergercookie#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis authored Oct 15, 2024
1 parent 34a4dfd commit 5dd94d8
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 239 deletions.
59 changes: 56 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ publish = true
exclude = ["samples/*", "demo/*"]
license = "BSD-2-Clause"

[lints.clippy]
# Using the URI type to identify open files is kind of unavoidable, tell clippy everything's gonna be ok
mutable_key_type = "allow"

[lib]
name = "asm_lsp"
Expand All @@ -29,6 +26,62 @@ path = "src/lib.rs"
name = "asm-lsp"
path = "src/bin/main.rs"

[lints.clippy]
dbg_macro = "deny"
todo = "deny"
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }

# Taken from tree-sitter's `Cargo.toml`
# The lints below are a specific subset of the pedantic+nursery lints
# that we explicitly allow in the tree-sitter codebase because they either:
#
# 1. Contain false positives,
# 2. Are unnecessary, or
# 3. Worsen the code

# Using the URI type to identify open files is kind of unavoidable, tell clippy everything's gonna be ok
mutable_key_type = "allow"

branches_sharing_code = "allow"
cast_lossless = "allow"
cast_possible_truncation = "allow"
cast_possible_wrap = "allow"
cast_precision_loss = "allow"
cast_sign_loss = "allow"
checked_conversions = "allow"
cognitive_complexity = "allow"
collection_is_never_read = "allow"
fallible_impl_from = "allow"
fn_params_excessive_bools = "allow"
inline_always = "allow"
if_not_else = "allow"
items_after_statements = "allow"
match_wildcard_for_single_variants = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
module_name_repetitions = "allow"
multiple_crate_versions = "allow"
option_if_let_else = "allow"
or_fun_call = "allow"
range_plus_one = "allow"
redundant_clone = "allow"
redundant_closure_for_method_calls = "allow"
# Only on nightly for now
# ref_option = "allow"
similar_names = "allow"
string_lit_as_bytes = "allow"
struct_excessive_bools = "allow"
struct_field_names = "allow"
transmute_undefined_repr = "allow"
too_many_lines = "allow"
unnecessary_wraps = "allow"
unused_self = "allow"
implicit_hasher = "allow"
# Only on nightly for now
# used_underscore_items = "allow"

[dependencies]
anyhow = "1.0.70"
# write to stderr instead of stdout
Expand Down
14 changes: 12 additions & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ use log::{error, info};
use lsp_server::{Connection, Message, Notification, Request, RequestId};
use lsp_textdocument::TextDocuments;

// main -------------------------------------------------------------------------------------------
/// Entry point of the server. Connects to the client, loads documentation resources,
/// and then enters the main loop
///
/// # Errors
///
/// Returns `Err` if the server fails to connect to the lsp client
///
/// # Panics
///
/// Panics if JSON serialization of the server capabilities fails
#[allow(clippy::too_many_lines)]
pub fn main() -> Result<()> {
// initialisation -----------------------------------------------------------------------------
// Set up logging. Because `stdio_transport` gets a lock on stdout and stdin, we must have our
Expand Down Expand Up @@ -401,7 +411,7 @@ pub fn main() -> Result<()> {
Ok(())
}

#[allow(clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments, clippy::too_many_lines)]
fn main_loop(
connection: &Connection,
config: &Config,
Expand Down
1 change: 0 additions & 1 deletion src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ pub fn handle_references_request(

/// Produces diagnostics and sends a `PublishDiagnostics` notification to the client
/// Diagnostics are only produced for the file specified by `uri`
/// Returns 'Err' if the response fails to send via `connection`
///
/// # Errors
///
Expand Down
13 changes: 9 additions & 4 deletions src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,12 @@ fn get_compilation_db_files(path: &Path) -> Option<CompilationDatabase> {
None
}

/// Returns a default `CompileCommand` for the provided `uri`. If the user specified
/// a compiler in their config, it will be used. Otherwise, the command will be constructed
/// with a single flag consisting of the provided `uri`
/// Returns a default `CompileCommand` for the provided `uri`.
///
/// - If the user specified a compiler in their config, it will be used.
/// - Otherwise, the command will be constructed with a single flag consisting of
/// the provided `uri`
///
/// NOTE: Several fields within the returned `CompileCommand` are intentionally left
/// uninitialized to avoid unnecessary allocations. If you're using this function
/// in a new place, please reconsider this assumption
Expand Down Expand Up @@ -522,6 +525,7 @@ fn get_diagnostics(diagnostics: &mut Vec<Diagnostic>, tool_output: &str) {
}

/// Function allowing us to connect tree sitter's logging with the log crate
#[allow(clippy::needless_pass_by_value)]
pub fn tree_sitter_logger(log_type: tree_sitter::LogType, message: &str) {
// map tree-sitter log types to log levels, for now set everything to Trace
let log_level = match log_type {
Expand Down Expand Up @@ -972,6 +976,7 @@ macro_rules! cursor_matches {
}};
}

#[allow(clippy::too_many_lines)]
pub fn get_comp_resp(
curr_doc: &str,
tree_entry: &mut TreeEntry,
Expand Down Expand Up @@ -1165,7 +1170,7 @@ pub fn get_comp_resp(
None
}

fn lsp_pos_of_point(pos: tree_sitter::Point) -> lsp_types::Position {
const fn lsp_pos_of_point(pos: tree_sitter::Point) -> lsp_types::Position {
Position {
line: pos.row as u32,
character: pos.column as u32,
Expand Down
Loading

0 comments on commit 5dd94d8

Please sign in to comment.