mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-24 10:26:18 +04:00
chore: clean up clippy lints (#11377)
Using clippy 1.80.0. Also cleans up some that were windows only.
This commit is contained in:
parent
3fcf168c33
commit
86aecc96a1
@ -75,9 +75,9 @@ fn from((open, close): (&char, &char)) -> Self {
|
|||||||
|
|
||||||
impl AutoPairs {
|
impl AutoPairs {
|
||||||
/// Make a new AutoPairs set with the given pairs and default conditions.
|
/// Make a new AutoPairs set with the given pairs and default conditions.
|
||||||
pub fn new<'a, V: 'a, A>(pairs: V) -> Self
|
pub fn new<'a, V, A>(pairs: V) -> Self
|
||||||
where
|
where
|
||||||
V: IntoIterator<Item = A>,
|
V: IntoIterator<Item = A> + 'a,
|
||||||
A: Into<Pair>,
|
A: Into<Pair>,
|
||||||
{
|
{
|
||||||
let mut auto_pairs = HashMap::new();
|
let mut auto_pairs = HashMap::new();
|
||||||
|
@ -265,7 +265,7 @@ fn is_first_in_line(node: Node, text: RopeSlice, new_line_byte_pos: Option<usize
|
|||||||
/// This is usually constructed in one of 2 ways:
|
/// This is usually constructed in one of 2 ways:
|
||||||
/// - Successively add indent captures to get the (added) indent from a single line
|
/// - Successively add indent captures to get the (added) indent from a single line
|
||||||
/// - Successively add the indent results for each line
|
/// - Successively add the indent results for each line
|
||||||
/// The string that this indentation defines starts with the string contained in the align field (unless it is None), followed by:
|
/// The string that this indentation defines starts with the string contained in the align field (unless it is None), followed by:
|
||||||
/// - max(0, indent - outdent) tabs, if tabs are used for indentation
|
/// - max(0, indent - outdent) tabs, if tabs are used for indentation
|
||||||
/// - max(0, indent - outdent)*indent_width spaces, if spaces are used for indentation
|
/// - max(0, indent - outdent)*indent_width spaces, if spaces are used for indentation
|
||||||
#[derive(Default, Debug, PartialEq, Eq, Clone)]
|
#[derive(Default, Debug, PartialEq, Eq, Clone)]
|
||||||
@ -457,7 +457,7 @@ fn query_indents<'a>(
|
|||||||
// Skip matches where not all custom predicates are fulfilled
|
// Skip matches where not all custom predicates are fulfilled
|
||||||
if !query.general_predicates(m.pattern_index).iter().all(|pred| {
|
if !query.general_predicates(m.pattern_index).iter().all(|pred| {
|
||||||
match pred.operator.as_ref() {
|
match pred.operator.as_ref() {
|
||||||
"not-kind-eq?" => match (pred.args.get(0), pred.args.get(1)) {
|
"not-kind-eq?" => match (pred.args.first(), pred.args.get(1)) {
|
||||||
(
|
(
|
||||||
Some(QueryPredicateArg::Capture(capture_idx)),
|
Some(QueryPredicateArg::Capture(capture_idx)),
|
||||||
Some(QueryPredicateArg::String(kind)),
|
Some(QueryPredicateArg::String(kind)),
|
||||||
@ -473,7 +473,7 @@ fn query_indents<'a>(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"same-line?" | "not-same-line?" => {
|
"same-line?" | "not-same-line?" => {
|
||||||
match (pred.args.get(0), pred.args.get(1)) {
|
match (pred.args.first(), pred.args.get(1)) {
|
||||||
(
|
(
|
||||||
Some(QueryPredicateArg::Capture(capt1)),
|
Some(QueryPredicateArg::Capture(capt1)),
|
||||||
Some(QueryPredicateArg::Capture(capt2))
|
Some(QueryPredicateArg::Capture(capt2))
|
||||||
@ -495,7 +495,7 @@ fn query_indents<'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"one-line?" | "not-one-line?" => match pred.args.get(0) {
|
"one-line?" | "not-one-line?" => match pred.args.first() {
|
||||||
Some(QueryPredicateArg::Capture(capture_idx)) => {
|
Some(QueryPredicateArg::Capture(capture_idx)) => {
|
||||||
let node = m.nodes_for_capture_index(*capture_idx).next();
|
let node = m.nodes_for_capture_index(*capture_idx).next();
|
||||||
|
|
||||||
@ -786,6 +786,7 @@ fn init_indent_query<'a, 'b>(
|
|||||||
/// - The line after the node. This is defined by:
|
/// - The line after the node. This is defined by:
|
||||||
/// - The scope `tail`.
|
/// - The scope `tail`.
|
||||||
/// - The scope `all` if this node is not the first node on its line.
|
/// - The scope `all` if this node is not the first node on its line.
|
||||||
|
///
|
||||||
/// Intuitively, `all` applies to everything contained in this node while `tail` applies to everything except for the first line of the node.
|
/// Intuitively, `all` applies to everything contained in this node while `tail` applies to everything except for the first line of the node.
|
||||||
/// The indents from different nodes for the same line are then combined.
|
/// The indents from different nodes for the same line are then combined.
|
||||||
/// The result [Indentation] is simply the sum of the [Indentation] for all lines.
|
/// The result [Indentation] is simply the sum of the [Indentation] for all lines.
|
||||||
|
@ -1431,8 +1431,11 @@ pub fn highlight_iter<'a>(
|
|||||||
// The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
|
// The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
|
||||||
// prevents them from being moved. But both of these values are really just
|
// prevents them from being moved. But both of these values are really just
|
||||||
// pointers, so it's actually ok to move them.
|
// pointers, so it's actually ok to move them.
|
||||||
let cursor_ref =
|
let cursor_ref = unsafe {
|
||||||
unsafe { mem::transmute::<_, &'static mut QueryCursor>(&mut cursor) };
|
mem::transmute::<&mut tree_sitter::QueryCursor, &mut tree_sitter::QueryCursor>(
|
||||||
|
&mut cursor,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
// if reusing cursors & no range this resets to whole range
|
// if reusing cursors & no range this resets to whole range
|
||||||
cursor_ref.set_byte_range(range.clone().unwrap_or(0..usize::MAX));
|
cursor_ref.set_byte_range(range.clone().unwrap_or(0..usize::MAX));
|
||||||
@ -1737,7 +1740,7 @@ fn traverse(point: Point, text: &Tendril) -> Point {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::{iter, mem, ops, str, usize};
|
use std::{iter, mem, ops, str};
|
||||||
use tree_sitter::{
|
use tree_sitter::{
|
||||||
Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
|
Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
|
||||||
QueryMatch, Range, TextProvider, Tree,
|
QueryMatch, Range, TextProvider, Tree,
|
||||||
|
@ -295,21 +295,21 @@ fn eaccess(p: &Path, mut mode: FILE_ACCESS_RIGHTS) -> io::Result<()> {
|
|||||||
let mut privileges_length = std::mem::size_of::<PRIVILEGE_SET>() as u32;
|
let mut privileges_length = std::mem::size_of::<PRIVILEGE_SET>() as u32;
|
||||||
let mut result = 0;
|
let mut result = 0;
|
||||||
|
|
||||||
let mut mapping = GENERIC_MAPPING {
|
let mapping = GENERIC_MAPPING {
|
||||||
GenericRead: FILE_GENERIC_READ,
|
GenericRead: FILE_GENERIC_READ,
|
||||||
GenericWrite: FILE_GENERIC_WRITE,
|
GenericWrite: FILE_GENERIC_WRITE,
|
||||||
GenericExecute: FILE_GENERIC_EXECUTE,
|
GenericExecute: FILE_GENERIC_EXECUTE,
|
||||||
GenericAll: FILE_ALL_ACCESS,
|
GenericAll: FILE_ALL_ACCESS,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe { MapGenericMask(&mut mode, &mut mapping) };
|
unsafe { MapGenericMask(&mut mode, &mapping) };
|
||||||
|
|
||||||
if unsafe {
|
if unsafe {
|
||||||
AccessCheck(
|
AccessCheck(
|
||||||
*sd.descriptor(),
|
*sd.descriptor(),
|
||||||
*token.as_handle(),
|
*token.as_handle(),
|
||||||
mode,
|
mode,
|
||||||
&mut mapping,
|
&mapping,
|
||||||
&mut privileges,
|
&mut privileges,
|
||||||
&mut privileges_length,
|
&mut privileges_length,
|
||||||
&mut granted_access,
|
&mut granted_access,
|
||||||
|
@ -66,18 +66,16 @@ fn find_rc_exe() -> io::Result<PathBuf> {
|
|||||||
.output();
|
.output();
|
||||||
|
|
||||||
match find_reg_key {
|
match find_reg_key {
|
||||||
Err(find_reg_key) => {
|
Err(find_reg_key) => Err(io::Error::new(
|
||||||
return Err(io::Error::new(
|
io::ErrorKind::Other,
|
||||||
io::ErrorKind::Other,
|
format!("Failed to run registry query: {}", find_reg_key),
|
||||||
format!("Failed to run registry query: {}", find_reg_key),
|
)),
|
||||||
))
|
|
||||||
}
|
|
||||||
Ok(find_reg_key) => {
|
Ok(find_reg_key) => {
|
||||||
if find_reg_key.status.code().unwrap() != 0 {
|
if find_reg_key.status.code().unwrap() != 0 {
|
||||||
return Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"Can not find Windows SDK",
|
"Can not find Windows SDK",
|
||||||
));
|
))
|
||||||
} else {
|
} else {
|
||||||
let lines = String::from_utf8(find_reg_key.stdout)
|
let lines = String::from_utf8(find_reg_key.stdout)
|
||||||
.expect("Should be able to parse the output");
|
.expect("Should be able to parse the output");
|
||||||
|
@ -35,7 +35,9 @@
|
|||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
use std::{collections::btree_map::Entry, io::stdin, path::Path, sync::Arc};
|
use std::{collections::btree_map::Entry, io::stdin, path::Path, sync::Arc};
|
||||||
|
|
||||||
use anyhow::{Context, Error};
|
#[cfg(not(windows))]
|
||||||
|
use anyhow::Context;
|
||||||
|
use anyhow::Error;
|
||||||
|
|
||||||
use crossterm::{event::Event as CrosstermEvent, tty::IsTty};
|
use crossterm::{event::Event as CrosstermEvent, tty::IsTty};
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::{BTreeMap, HashSet},
|
collections::{BTreeMap, HashSet},
|
||||||
fmt::Write,
|
fmt::{Display, Write},
|
||||||
future::Future,
|
future::Future,
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
@ -832,13 +832,13 @@ pub enum ApplyEditErrorKind {
|
|||||||
// InvalidEdit,
|
// InvalidEdit,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for ApplyEditErrorKind {
|
impl Display for ApplyEditErrorKind {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ApplyEditErrorKind::DocumentChanged => "document has changed".to_string(),
|
ApplyEditErrorKind::DocumentChanged => f.write_str("document has changed"),
|
||||||
ApplyEditErrorKind::FileNotFound => "file not found".to_string(),
|
ApplyEditErrorKind::FileNotFound => f.write_str("file not found"),
|
||||||
ApplyEditErrorKind::UnknownURISchema => "URI schema not supported".to_string(),
|
ApplyEditErrorKind::UnknownURISchema => f.write_str("URI schema not supported"),
|
||||||
ApplyEditErrorKind::IoError(err) => err.to_string(),
|
ApplyEditErrorKind::IoError(err) => f.write_str(&format!("{err}")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2498,7 +2498,7 @@ fn read(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->
|
|||||||
ensure!(!args.is_empty(), "file name is expected");
|
ensure!(!args.is_empty(), "file name is expected");
|
||||||
ensure!(args.len() == 1, "only the file name is expected");
|
ensure!(args.len() == 1, "only the file name is expected");
|
||||||
|
|
||||||
let filename = args.get(0).unwrap();
|
let filename = args.first().unwrap();
|
||||||
let path = PathBuf::from(filename.to_string());
|
let path = PathBuf::from(filename.to_string());
|
||||||
ensure!(
|
ensure!(
|
||||||
path.exists() && path.is_file(),
|
path.exists() && path.is_file(),
|
||||||
|
@ -117,10 +117,9 @@ async fn main_impl() -> Result<i32> {
|
|||||||
setup_logging(args.verbosity).context("failed to initialize logging")?;
|
setup_logging(args.verbosity).context("failed to initialize logging")?;
|
||||||
|
|
||||||
// Before setting the working directory, resolve all the paths in args.files
|
// Before setting the working directory, resolve all the paths in args.files
|
||||||
for (path, _) in args.files.iter_mut() {
|
for (path, _) in &mut args.files {
|
||||||
*path = helix_stdx::path::canonicalize(&path);
|
*path = helix_stdx::path::canonicalize(&*path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Set the working directory early so the correct configuration is loaded. Be aware that
|
// NOTE: Set the working directory early so the correct configuration is loaded. Be aware that
|
||||||
// Application::new() depends on this logic so it must be updated if this changes.
|
// Application::new() depends on this logic so it must be updated if this changes.
|
||||||
if let Some(path) = &args.working_directory {
|
if let Some(path) = &args.working_directory {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
//! - A single line string where all graphemes have the same style is represented by a [`Span`].
|
//! - A single line string where all graphemes have the same style is represented by a [`Span`].
|
||||||
//! - A single line string where each grapheme may have its own style is represented by [`Spans`].
|
//! - A single line string where each grapheme may have its own style is represented by [`Spans`].
|
||||||
//! - A multiple line string where each grapheme may have its own style is represented by a
|
//! - A multiple line string where each grapheme may have its own style is represented by a
|
||||||
//! [`Text`].
|
//! [`Text`].
|
||||||
//!
|
//!
|
||||||
//! These types form a hierarchy: [`Spans`] is a collection of [`Span`] and each line of [`Text`]
|
//! These types form a hierarchy: [`Spans`] is a collection of [`Span`] and each line of [`Text`]
|
||||||
//! is a [`Spans`].
|
//! is a [`Spans`].
|
||||||
|
@ -1245,7 +1245,7 @@ pub fn reset_selection(&mut self, view_id: ViewId) {
|
|||||||
/// Initializes a new selection and view_data for the given view
|
/// Initializes a new selection and view_data for the given view
|
||||||
/// if it does not already have them.
|
/// if it does not already have them.
|
||||||
pub fn ensure_view_init(&mut self, view_id: ViewId) {
|
pub fn ensure_view_init(&mut self, view_id: ViewId) {
|
||||||
if self.selections.get(&view_id).is_none() {
|
if !self.selections.contains_key(&view_id) {
|
||||||
self.reset_selection(view_id);
|
self.reset_selection(view_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ pub async fn select_thread_id(editor: &mut Editor, thread_id: ThreadId, force: b
|
|||||||
debugger.thread_id = Some(thread_id);
|
debugger.thread_id = Some(thread_id);
|
||||||
fetch_stack_trace(debugger, thread_id).await;
|
fetch_stack_trace(debugger, thread_id).await;
|
||||||
|
|
||||||
let frame = debugger.stack_frames[&thread_id].get(0).cloned();
|
let frame = debugger.stack_frames[&thread_id].first().cloned();
|
||||||
if let Some(frame) = &frame {
|
if let Some(frame) = &frame {
|
||||||
jump_to_stack_frame(editor, frame);
|
jump_to_stack_frame(editor, frame);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use crate::editor::Action;
|
use crate::editor::Action;
|
||||||
use crate::Editor;
|
use crate::Editor;
|
||||||
use crate::{DocumentId, ViewId};
|
use crate::{DocumentId, ViewId};
|
||||||
@ -73,13 +75,13 @@ fn from(err: helix_core::uri::UrlConversionError) -> Self {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for ApplyEditErrorKind {
|
impl Display for ApplyEditErrorKind {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ApplyEditErrorKind::DocumentChanged => "document has changed".to_string(),
|
ApplyEditErrorKind::DocumentChanged => f.write_str("document has changed"),
|
||||||
ApplyEditErrorKind::FileNotFound => "file not found".to_string(),
|
ApplyEditErrorKind::FileNotFound => f.write_str("file not found"),
|
||||||
ApplyEditErrorKind::InvalidUrl(err) => err.to_string(),
|
ApplyEditErrorKind::InvalidUrl(err) => f.write_str(&format!("{err}")),
|
||||||
ApplyEditErrorKind::IoError(err) => err.to_string(),
|
ApplyEditErrorKind::IoError(err) => f.write_str(&format!("{err}")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user