on master help sign in
clippy lint
commitceea5eacd814c5bbd8c6789610c87a882e3d72cf authorBlaž Hrastnik <blaz@mxxn.io> dateWed 31 Mar 2021, 23:42 (6 years ago) parent15c9a33
12 files changed+45−58
helix-lsp/src/client.rs+11−11 helix-lsp/src/transport.rs+4−4 helix-term/src/application.rs+1−1 helix-term/src/commands.rs+8−9 helix-term/src/main.rs+1−1 helix-term/src/ui/editor.rs+3−3 helix-term/src/ui/menu.rs+2−2 helix-term/src/ui/mod.rs+1−4 helix-term/src/ui/prompt.rs+2−7 helix-view/src/document.rs+3−5 helix-view/src/editor.rs+1 helix-view/src/tree.rs+8−11
helix-lsp/src/client.rs+11−11
@@ -384,11 +384,13 @@ impl Client {
384384 let capabilities = self.capabilities.as_ref().unwrap();
385385
386386 let sync_capabilities = match capabilities.text_document_sync {
387− Some(lsp::TextDocumentSyncCapability::Kind(kind)) => kind,
388− Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
389− change: Some(kind),
390− ..
391− })) => kind,
387+ Some(
388+ lsp::TextDocumentSyncCapability::Kind(kind)
389+ | lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
390+ change: Some(kind),
391+ ..
392+ }),
393+ ) => kind,
392394 // None | SyncOptions { changes: None }
393395 _ => return Ok(()),
394396 };
@@ -537,9 +539,8 @@ impl Client {
537539 let capabilities = self.capabilities.as_ref().unwrap();
538540
539541 // check if we're able to format
540− let _capabilities = match capabilities.document_formatting_provider {
541− Some(lsp::OneOf::Left(true)) => (),
542− Some(lsp::OneOf::Right(_)) => (),
542+ match capabilities.document_formatting_provider {
543+ Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) => (),
543544 // None | Some(false)
544545 _ => return Ok(Vec::new()),
545546 };
@@ -567,9 +568,8 @@ impl Client {
567568 let capabilities = self.capabilities.as_ref().unwrap();
568569
569570 // check if we're able to format
570− let _capabilities = match capabilities.document_range_formatting_provider {
571− Some(lsp::OneOf::Left(true)) => (),
572− Some(lsp::OneOf::Right(_)) => (),
571+ match capabilities.document_range_formatting_provider {
572+ Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) => (),
573573 // None | Some(false)
574574 _ => return Ok(Vec::new()),
575575 };
helix-lsp/src/transport.rs+4−4
@@ -19,7 +19,7 @@ use smol::{
1919 Executor,
2020};
2121
22−pub(crate) enum Payload {
22+pub enum Payload {
2323 Request {
2424 chan: Sender<Result<Value>>,
2525 value: jsonrpc::MethodCall,
@@ -40,7 +40,7 @@ enum Message {
4040 Call(jsonrpc::Call),
4141}
4242
43−pub(crate) struct Transport {
43+pub struct Transport {
4444 incoming: Sender<jsonrpc::Call>,
4545 outgoing: Receiver<Payload>,
4646
@@ -68,8 +68,8 @@ impl Transport {
6868 stderr,
6969 incoming,
7070 outgoing,
71− pending_requests: Default::default(),
72− headers: Default::default(),
71+ pending_requests: HashMap::default(),
72+ headers: HashMap::default(),
7373 };
7474
7575 ex.spawn(transport.duplex()).detach();
helix-term/src/application.rs+1−1
@@ -122,7 +122,7 @@ impl Application {
122122 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
123123 let mut cx = crate::compositor::Context {
124124 editor: &mut self.editor,
125− executor: &self.executor,
125+ executor: self.executor,
126126 callbacks: &mut self.callbacks,
127127 scroll: None,
128128 };
helix-term/src/commands.rs+8−9
@@ -14,6 +14,7 @@ use crate::{
1414 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
1515};
1616
17+use std::borrow::Cow;
1718use std::path::{Path, PathBuf};
1819
1920use helix_view::{
@@ -333,7 +334,7 @@ where
333334 let text = doc.text().slice(..);
334335
335336 let selection = doc.selection(view_id).transform(|mut range| {
336− if let Some(pos) = search::find_nth_next(text, ch, range.head, count, inclusive) {
337+ search::find_nth_next(text, ch, range.head, count, inclusive).map_or(range, |pos| {
337338 if extend {
338339 Range::new(range.anchor, pos)
339340 } else {
@@ -341,9 +342,7 @@ where
341342 Range::new(range.head, pos)
342343 }
343344 // or (pos, pos) to move to found val
344− } else {
345− range
346− }
345+ })
347346 });
348347
349348 doc.set_selection(view_id, selection);
@@ -642,7 +641,7 @@ fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) {
642641 let start = doc.selection(view_id).cursor();
643642
644643 // TODO: use find_at to find the next match after the cursor, loop around the end
645− if let Some(mat) = regex.find_at(&contents, start) {
644+ if let Some(mat) = regex.find_at(contents, start) {
646645 let start = text.byte_to_char(mat.start());
647646 let end = text.byte_to_char(mat.end());
648647 let selection = Selection::single(start, end - 1);
@@ -859,15 +858,15 @@ pub fn command_mode(cx: &mut Context) {
859858 let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
860859
861860 match *parts.as_slice() {
862− ["q"] | ["quit"] => {
861+ ["q" | "quit"] => {
863862 editor.close(editor.view().id);
864863 // editor.should_close = true,
865864 }
866− ["o", path] | ["open", path] => {
865+ ["o" | "open", path] => {
867866 use helix_view::editor::Action;
868867 editor.open(path.into(), Action::Replace);
869868 }
870− ["w"] | ["write"] => {
869+ ["w" | "write"] => {
871870 // TODO: non-blocking via save() command
872871 let id = editor.view().doc;
873872 let doc = &mut editor.documents[id];
@@ -1487,7 +1486,7 @@ pub fn yank(cx: &mut Context) {
14871486 let values: Vec<String> = doc
14881487 .selection(view_id)
14891488 .fragments(doc.text().slice(..))
1490− .map(|cow| cow.into_owned())
1489+ .map(Cow::into_owned)
14911490 .collect();
14921491
14931492 // TODO: allow specifying reg
helix-term/src/main.rs+1−1
@@ -77,7 +77,7 @@ fn main() {
7777 use helix_core::syntax::{Loader, LOADER};
7878 let toml = include_str!("../../languages.toml");
7979 LOADER.get_or_init(|| {
80− let config = toml::from_str(&toml).expect("Could not parse languages.toml");
80+ let config = toml::from_str(toml).expect("Could not parse languages.toml");
8181 Loader::new(config)
8282 });
8383
helix-term/src/ui/editor.rs+3−3
@@ -58,13 +58,13 @@ impl EditorView {
5858 viewport.width - OFFSET,
5959 viewport.height.saturating_sub(1),
6060 ); // - 1 for statusline
61− self.render_buffer(&doc, view, area, surface, theme, is_focused);
61+ self.render_buffer(doc, view, area, surface, theme, is_focused);
6262
6363 // clear with background color
6464 // TODO: this seems to prevent setting style later
6565 // surface.set_style(viewport, theme.get("ui.background"));
6666
67− self.render_diagnostics(&doc, view, area, surface, theme, is_focused);
67+ self.render_diagnostics(doc, view, area, surface, theme, is_focused);
6868
6969 let area = Rect::new(
7070 viewport.x,
@@ -72,7 +72,7 @@ impl EditorView {
7272 viewport.width,
7373 1,
7474 );
75− self.render_statusline(&doc, area, surface, theme, is_focused);
75+ self.render_statusline(doc, area, surface, theme, is_focused);
7676
7777 // render status
7878 if let Some(status_msg) = &self.status_msg {
helix-term/src/ui/menu.rs+2−2
@@ -90,13 +90,13 @@ impl<T> Menu<T> {
9090
9191 pub fn move_up(&mut self) {
9292 // TODO: wrap around to end
93− let pos = self.cursor.map(|i| i.saturating_sub(1)).unwrap_or(0) % self.options.len();
93+ let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.options.len();
9494 self.cursor = Some(pos);
9595 self.adjust_scroll();
9696 }
9797
9898 pub fn move_down(&mut self) {
99− let pos = self.cursor.map(|i| i + 1).unwrap_or(0) % self.options.len();
99+ let pos = self.cursor.map_or(0, |i| i + 1) % self.options.len();
100100 self.cursor = Some(pos);
101101 self.adjust_scroll();
102102 }
helix-term/src/ui/mod.rs+1−4
@@ -149,10 +149,7 @@ pub mod completers {
149149 .build()
150150 .filter_map(|file| {
151151 file.ok().map(|entry| {
152− let is_dir = entry
153− .file_type()
154− .map(|entry| entry.is_dir())
155− .unwrap_or(false);
152+ let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
156153
157154 let mut path = entry.path().strip_prefix(&dir).unwrap().to_path_buf();
158155
helix-term/src/ui/prompt.rs+2−7
@@ -81,8 +81,7 @@ impl Prompt {
8181 if self.completion.is_empty() {
8282 return;
8383 }
84− let index =
85− self.completion_selection_index.map(|i| i + 1).unwrap_or(0) % self.completion.len();
84+ let index = self.completion_selection_index.map_or(0, |i| i + 1) % self.completion.len();
8685 self.completion_selection_index = Some(index);
8786
8887 let (range, item) = &self.completion[index];
@@ -183,11 +182,7 @@ impl Component for Prompt {
183182 // char or shift char
184183 KeyEvent {
185184 code: KeyCode::Char(c),
186− modifiers: KeyModifiers::NONE,
187− }
188− | KeyEvent {
189− code: KeyCode::Char(c),
190− modifiers: KeyModifiers::SHIFT,
185+ modifiers: KeyModifiers::NONE | KeyModifiers::SHIFT,
191186 } => {
192187 self.insert_char(c);
193188 (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
helix-view/src/document.rs+3−5
@@ -242,7 +242,7 @@ impl Document {
242242 });
243243 }
244244
245− let success = self._apply(&transaction, view_id);
245+ let success = self._apply(transaction, view_id);
246246
247247 self.modified = true;
248248 // TODO: be smarter about modified by keeping track of saved version instead. That way if
@@ -342,8 +342,7 @@ impl Document {
342342 self.language
343343 .as_ref()
344344 .and_then(|config| config.indent.as_ref())
345− .map(|config| config.tab_width)
346− .unwrap_or(4) // fallback to 4 columns
345+ .map_or(4, |config| config.tab_width) // fallback to 4 columns
347346 }
348347
349348 /// Returns a string containing a single level of indentation.
@@ -351,8 +350,7 @@ impl Document {
351350 self.language
352351 .as_ref()
353352 .and_then(|config| config.indent.as_ref())
354− .map(|config| config.unit.as_str())
355− .unwrap_or(" ") // fallback to 2 spaces
353+ .map_or(" ", |config| config.unit.as_str()) // fallback to 2 spaces
356354
357355 // " ".repeat(TAB_WIDTH)
358356 }
helix-view/src/editor.rs+1
@@ -16,6 +16,7 @@ pub struct Editor {
1616 pub executor: &'static smol::Executor<'static>,
1717}
1818
19+#[derive(Copy, Clone)]
1920pub enum Action {
2021 Replace,
2122 HorizontalSplit,
helix-view/src/tree.rs+8−11
@@ -29,14 +29,14 @@ pub enum Content {
2929
3030impl Node {
3131 pub fn container(layout: Layout) -> Self {
32− Node {
32+ Self {
3333 parent: ViewId::default(),
3434 content: Content::Container(Box::new(Container::new(layout))),
3535 }
3636 }
3737
3838 pub fn view(view: View) -> Self {
39− Node {
39+ Self {
4040 parent: ViewId::default(),
4141 content: Content::View(Box::new(view)),
4242 }
@@ -414,15 +414,12 @@ impl Tree {
414414 let mut iter = iter.skip_while(|&(key, _view)| key != self.focus);
415415 iter.next(); // take the focused value
416416
417− match iter.next() {
418− Some((key, _)) => {
419− self.focus = key;
420− }
421− None => {
422− // extremely crude, take the first item again
423− let (key, _) = self.traverse().next().unwrap();
424− self.focus = key;
425− }
417+ if let Some((key, _)) = iter.next() {
418+ self.focus = key;
419+ } else {
420+ // extremely crude, take the first item again
421+ let (key, _) = self.traverse().next().unwrap();
422+ self.focus = key;
426423 }
427424 }
428425}