on master help sign in
Fix warnings from clippy (#7013)

* Fix warnings from clippy * revert MAIN_SEPARATOR_STR

commit3b8c15618f51889ffd2f2f4be32f8404c1517956 authorZJPzjp <jiping_zhou@foxmail.com> dateThu 11 May 2023, 13:44 (3 years ago) parent1e5997d
7 files changed+29−32
helix-core/src/surround.rs+1−6 helix-core/src/syntax.rs+6−3 helix-loader/src/lib.rs+18−18 helix-term/src/ui/editor.rs+1−1 helix-tui/src/buffer.rs+1−1 helix-view/src/clipboard.rs+1−1 helix-view/src/tree.rs+1−2
helix-core/src/surround.rs+1−6
@@ -397,15 +397,10 @@ mod test {
397397
398398 let selections: SmallVec<[Range; 1]> = spec
399399 .match_indices('^')
400− .into_iter()
401400 .map(|(i, _)| Range::point(i))
402401 .collect();
403402
404− let expectations: Vec<usize> = spec
405− .match_indices('_')
406− .into_iter()
407− .map(|(i, _)| i)
408− .collect();
403+ let expectations: Vec<usize> = spec.match_indices('_').map(|(i, _)| i).collect();
409404
410405 (rope, Selection::new(selections, 0), expectations)
411406 }
helix-core/src/syntax.rs+6−3
@@ -187,9 +187,12 @@ impl<'de> Deserialize<'de> for FileType {
187187 M: serde::de::MapAccess<'de>,
188188 {
189189 match map.next_entry::<String, String>()? {
190− Some((key, suffix)) if key == "suffix" => Ok(FileType::Suffix(
191− suffix.replace('/', &std::path::MAIN_SEPARATOR.to_string()),
192− )),
190+ Some((key, suffix)) if key == "suffix" => Ok(FileType::Suffix({
191+ // FIXME: use `suffix.replace('/', std::path::MAIN_SEPARATOR_STR)`
192+ // if MSRV is updated to 1.68
193+ let mut seperator = [0; 1];
194+ suffix.replace('/', std::path::MAIN_SEPARATOR.encode_utf8(&mut seperator))
195+ })),
193196 Some((key, _value)) => Err(serde::de::Error::custom(format!(
194197 "unknown key in `file-types` list: {}",
195198 key
helix-loader/src/lib.rs+18−18
@@ -209,6 +209,24 @@ pub fn merge_toml_values(left: toml::Value, right: toml::Value, merge_depth: usi
209209 }
210210}
211211
212+/// Finds the current workspace folder.
213+/// Used as a ceiling dir for LSP root resolution, the filepicker and potentially as a future filewatching root
214+///
215+/// This function starts searching the FS upward from the CWD
216+/// and returns the first directory that contains either `.git` or `.helix`.
217+/// If no workspace was found returns (CWD, true).
218+/// Otherwise (workspace, false) is returned
219+pub fn find_workspace() -> (PathBuf, bool) {
220+ let current_dir = std::env::current_dir().expect("unable to determine current directory");
221+ for ancestor in current_dir.ancestors() {
222+ if ancestor.join(".git").exists() || ancestor.join(".helix").exists() {
223+ return (ancestor.to_owned(), false);
224+ }
225+ }
226+
227+ (current_dir, true)
228+}
229+
212230#[cfg(test)]
213231mod merge_toml_tests {
214232 use std::str;
@@ -281,21 +299,3 @@ mod merge_toml_tests {
281299 )
282300 }
283301}
284−
285−/// Finds the current workspace folder.
286−/// Used as a ceiling dir for LSP root resolution, the filepicker and potentially as a future filewatching root
287−///
288−/// This function starts searching the FS upward from the CWD
289−/// and returns the first directory that contains either `.git` or `.helix`.
290−/// If no workspace was found returns (CWD, true).
291−/// Otherwise (workspace, false) is returned
292−pub fn find_workspace() -> (PathBuf, bool) {
293− let current_dir = std::env::current_dir().expect("unable to determine current directory");
294− for ancestor in current_dir.ancestors() {
295− if ancestor.join(".git").exists() || ancestor.join(".helix").exists() {
296− return (ancestor.to_owned(), false);
297− }
298− }
299−
300− (current_dir, true)
301−}
helix-term/src/ui/editor.rs+1−1
@@ -103,7 +103,7 @@ impl EditorView {
103103
104104 // Set DAP highlights, if needed.
105105 if let Some(frame) = editor.current_stack_frame() {
106− let dap_line = frame.line.saturating_sub(1) as usize;
106+ let dap_line = frame.line.saturating_sub(1);
107107 let style = theme.get("ui.highlight.frameline");
108108 let line_decoration = move |renderer: &mut TextRenderer, pos: LinePos| {
109109 if pos.doc_line != dap_line {
helix-tui/src/buffer.rs+1−1
@@ -442,7 +442,7 @@ impl Buffer {
442442 let mut x_offset = x as usize;
443443 let max_offset = min(self.area.right(), width.saturating_add(x));
444444 let mut start_index = self.index_of(x, y);
445− let mut index = self.index_of(max_offset as u16, y);
445+ let mut index = self.index_of(max_offset, y);
446446
447447 let content_width = spans.width();
448448 let truncated = content_width > width as usize;
helix-view/src/clipboard.rs+1−1
@@ -68,7 +68,7 @@ macro_rules! command_provider {
6868
6969#[cfg(windows)]
7070pub fn get_clipboard_provider() -> Box<dyn ClipboardProvider> {
71− Box::new(provider::WindowsProvider::default())
71+ Box::<provider::WindowsProvider>::default()
7272}
7373
7474#[cfg(target_os = "macos")]
helix-view/src/tree.rs+1−2
@@ -728,12 +728,11 @@ mod test {
728728 tree.focus = l0;
729729 let view = View::new(DocumentId::default(), GutterConfig::default());
730730 tree.split(view, Layout::Vertical);
731− let l2 = tree.focus;
732731
733732 // Tree in test
734733 // | L0 | L2 | |
735734 // | L1 | R0 |
736− tree.focus = l2;
735+ let l2 = tree.focus;
737736 assert_eq!(Some(l0), tree.find_split_in_direction(l2, Direction::Left));
738737 assert_eq!(Some(l1), tree.find_split_in_direction(l2, Direction::Down));
739738 assert_eq!(Some(r0), tree.find_split_in_direction(l2, Direction::Right));