Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings from clippy #7013

Merged
merged 2 commits into from
May 11, 2023
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
7 changes: 1 addition & 6 deletions helix-core/src/surround.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,10 @@ mod test {

let selections: SmallVec<[Range; 1]> = spec
.match_indices('^')
.into_iter()
.map(|(i, _)| Range::point(i))
.collect();

let expectations: Vec<usize> = spec
.match_indices('_')
.into_iter()
.map(|(i, _)| i)
.collect();
let expectations: Vec<usize> = spec.match_indices('_').map(|(i, _)| i).collect();

(rope, Selection::new(selections, 0), expectations)
}
Expand Down
9 changes: 6 additions & 3 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ impl<'de> Deserialize<'de> for FileType {
M: serde::de::MapAccess<'de>,
{
match map.next_entry::<String, String>()? {
Some((key, suffix)) if key == "suffix" => Ok(FileType::Suffix(
suffix.replace('/', &std::path::MAIN_SEPARATOR.to_string()),
)),
Some((key, suffix)) if key == "suffix" => Ok(FileType::Suffix({
// FIXME: use `suffix.replace('/', std::path::MAIN_SEPARATOR_STR)`
// if MSRV is updated to 1.68
let mut seperator = [0; 1];
suffix.replace('/', std::path::MAIN_SEPARATOR.encode_utf8(&mut seperator))
})),
Some((key, _value)) => Err(serde::de::Error::custom(format!(
"unknown key in `file-types` list: {}",
key
Expand Down
36 changes: 18 additions & 18 deletions helix-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ pub fn merge_toml_values(left: toml::Value, right: toml::Value, merge_depth: usi
}
}

/// Finds the current workspace folder.
/// Used as a ceiling dir for LSP root resolution, the filepicker and potentially as a future filewatching root
///
/// This function starts searching the FS upward from the CWD
/// and returns the first directory that contains either `.git` or `.helix`.
/// If no workspace was found returns (CWD, true).
/// Otherwise (workspace, false) is returned
pub fn find_workspace() -> (PathBuf, bool) {
let current_dir = std::env::current_dir().expect("unable to determine current directory");
for ancestor in current_dir.ancestors() {
if ancestor.join(".git").exists() || ancestor.join(".helix").exists() {
return (ancestor.to_owned(), false);
}
}

(current_dir, true)
}

#[cfg(test)]
mod merge_toml_tests {
use std::str;
Expand Down Expand Up @@ -281,21 +299,3 @@ mod merge_toml_tests {
)
}
}

/// Finds the current workspace folder.
/// Used as a ceiling dir for LSP root resolution, the filepicker and potentially as a future filewatching root
///
/// This function starts searching the FS upward from the CWD
/// and returns the first directory that contains either `.git` or `.helix`.
/// If no workspace was found returns (CWD, true).
/// Otherwise (workspace, false) is returned
pub fn find_workspace() -> (PathBuf, bool) {
let current_dir = std::env::current_dir().expect("unable to determine current directory");
for ancestor in current_dir.ancestors() {
if ancestor.join(".git").exists() || ancestor.join(".helix").exists() {
return (ancestor.to_owned(), false);
}
}

(current_dir, true)
}
Comment on lines -284 to -301
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change here?

Copy link
Contributor Author

@zjp-CN zjp-CN May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy says the normal items should avoid being declared after testing mod: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module

So I just move the testing mod down, but git diff shows the changes on find_workspace instead.

warning: items were found after the testing module
   --> helix-loader\src\lib.rs:213:1
    |
213 | / mod merge_toml_tests {
214 | |     use std::str;
215 | |
216 | |     use super::merge_toml_values;
...   |
300 | |     (current_dir, true)
301 | | }
    | |_^
    |
    = help: move the items to before the testing module was defined
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
    = note: `#[warn(clippy::items_after_test_module)]` on by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think the reason why I meet clippy complaints is that I use a rustc/cargo in a higher verion.

items_after_test_module hasn't been in clippy1.65 yet.

So the Github action doesn't catch them for now.

If this PR is not appropriate for now, feel free to close.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah all these are future lints that don't trigger in current version yet but it's good to fix them ahead of time 👍🏻

2 changes: 1 addition & 1 deletion helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl EditorView {

// Set DAP highlights, if needed.
if let Some(frame) = editor.current_stack_frame() {
let dap_line = frame.line.saturating_sub(1) as usize;
let dap_line = frame.line.saturating_sub(1);
let style = theme.get("ui.highlight.frameline");
let line_decoration = move |renderer: &mut TextRenderer, pos: LinePos| {
if pos.doc_line != dap_line {
Expand Down
2 changes: 1 addition & 1 deletion helix-tui/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl Buffer {
let mut x_offset = x as usize;
let max_offset = min(self.area.right(), width.saturating_add(x));
let mut start_index = self.index_of(x, y);
let mut index = self.index_of(max_offset as u16, y);
let mut index = self.index_of(max_offset, y);

let content_width = spans.width();
let truncated = content_width > width as usize;
Expand Down
2 changes: 1 addition & 1 deletion helix-view/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ macro_rules! command_provider {

#[cfg(windows)]
pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
Box::new(provider::WindowsProvider::default())
Box::<provider::WindowsProvider>::default()
}

#[cfg(target_os = "macos")]
Expand Down
3 changes: 1 addition & 2 deletions helix-view/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,11 @@ mod test {
tree.focus = l0;
let view = View::new(DocumentId::default(), GutterConfig::default());
tree.split(view, Layout::Vertical);
let l2 = tree.focus;

// Tree in test
// | L0 | L2 | |
// | L1 | R0 |
tree.focus = l2;
let l2 = tree.focus;
assert_eq!(Some(l0), tree.find_split_in_direction(l2, Direction::Left));
assert_eq!(Some(l1), tree.find_split_in_direction(l2, Direction::Down));
assert_eq!(Some(r0), tree.find_split_in_direction(l2, Direction::Right));
Expand Down