on master help sign in
clippy lint
ceea5eaBlaž Hrastnik
helix-lsp/src/client.rs+11−11
@@ -384,11 +384,13 @@ impl Client {
384 let capabilities = self.capabilities.as_ref().unwrap();
384 let capabilities = self.capabilities.as_ref().unwrap();
385
385
386 let sync_capabilities = match capabilities.text_document_sync {
386 let sync_capabilities = match capabilities.text_document_sync {
387+ Some(
387− Some(lsp::TextDocumentSyncCapability::Kind(kind)) => kind,
388+ lsp::TextDocumentSyncCapability::Kind(kind)
388− Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
389+ | lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
389− change: Some(kind),
390+ change: Some(kind),
390− ..
391+ ..
392+ }),
391− })) => kind,
393+ ) => kind,
392 // None | SyncOptions { changes: None }
394 // None | SyncOptions { changes: None }
393 _ => return Ok(()),
395 _ => return Ok(()),
394 };
396 };
@@ -537,9 +539,8 @@ impl Client {
537 let capabilities = self.capabilities.as_ref().unwrap();
539 let capabilities = self.capabilities.as_ref().unwrap();
538
540
539 // check if we're able to format
541 // check if we're able to format
540− let _capabilities = match capabilities.document_formatting_provider {
542+ match capabilities.document_formatting_provider {
541− Some(lsp::OneOf::Left(true)) => (),
543+ Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) => (),
542− Some(lsp::OneOf::Right(_)) => (),
543 // None | Some(false)
544 // None | Some(false)
544 _ => return Ok(Vec::new()),
545 _ => return Ok(Vec::new()),
545 };
546 };
@@ -567,9 +568,8 @@ impl Client {
567 let capabilities = self.capabilities.as_ref().unwrap();
568 let capabilities = self.capabilities.as_ref().unwrap();
568
569
569 // check if we're able to format
570 // check if we're able to format
570− let _capabilities = match capabilities.document_range_formatting_provider {
571+ match capabilities.document_range_formatting_provider {
571− Some(lsp::OneOf::Left(true)) => (),
572+ Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) => (),
572− Some(lsp::OneOf::Right(_)) => (),
573 // None | Some(false)
573 // None | Some(false)
574 _ => return Ok(Vec::new()),
574 _ => return Ok(Vec::new()),
575 };
575 };
helix-lsp/src/transport.rs+4−4
@@ -19,7 +19,7 @@ use smol::{
19 Executor,
19 Executor,
20};
20};
21
21
22−pub(crate) enum Payload {
22+pub enum Payload {
23 Request {
23 Request {
24 chan: Sender<Result<Value>>,
24 chan: Sender<Result<Value>>,
25 value: jsonrpc::MethodCall,
25 value: jsonrpc::MethodCall,
@@ -40,7 +40,7 @@ enum Message {
40 Call(jsonrpc::Call),
40 Call(jsonrpc::Call),
41}
41}
42
42
43−pub(crate) struct Transport {
43+pub struct Transport {
44 incoming: Sender<jsonrpc::Call>,
44 incoming: Sender<jsonrpc::Call>,
45 outgoing: Receiver<Payload>,
45 outgoing: Receiver<Payload>,
46
46
@@ -68,8 +68,8 @@ impl Transport {
68 stderr,
68 stderr,
69 incoming,
69 incoming,
70 outgoing,
70 outgoing,
71− pending_requests: Default::default(),
71+ pending_requests: HashMap::default(),
72− headers: Default::default(),
72+ headers: HashMap::default(),
73 };
73 };
74
74
75 ex.spawn(transport.duplex()).detach();
75 ex.spawn(transport.duplex()).detach();
helix-term/src/application.rs+1−1
@@ -122,7 +122,7 @@ impl Application {
122 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
122 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
123 let mut cx = crate::compositor::Context {
123 let mut cx = crate::compositor::Context {
124 editor: &mut self.editor,
124 editor: &mut self.editor,
125− executor: &self.executor,
125+ executor: self.executor,
126 callbacks: &mut self.callbacks,
126 callbacks: &mut self.callbacks,
127 scroll: None,
127 scroll: None,
128 };
128 };
helix-term/src/commands.rs+8−9
@@ -14,6 +14,7 @@ use crate::{
14 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
14 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
15};
15};
16
16
17+use std::borrow::Cow;
17use std::path::{Path, PathBuf};
18use std::path::{Path, PathBuf};
18
19
19use helix_view::{
20use helix_view::{
@@ -333,7 +334,7 @@ where
333 let text = doc.text().slice(..);
334 let text = doc.text().slice(..);
334
335
335 let selection = doc.selection(view_id).transform(|mut range| {
336 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| {
337 if extend {
338 if extend {
338 Range::new(range.anchor, pos)
339 Range::new(range.anchor, pos)
339 } else {
340 } else {
@@ -341,9 +342,7 @@ where
341 Range::new(range.head, pos)
342 Range::new(range.head, pos)
342 }
343 }
343 // or (pos, pos) to move to found val
344 // or (pos, pos) to move to found val
344− } else {
345+ })
345− range
346− }
347 });
346 });
348
347
349 doc.set_selection(view_id, selection);
348 doc.set_selection(view_id, selection);
@@ -642,7 +641,7 @@ fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) {
642 let start = doc.selection(view_id).cursor();
641 let start = doc.selection(view_id).cursor();
643
642
644 // TODO: use find_at to find the next match after the cursor, loop around the end
643 // 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) {
646 let start = text.byte_to_char(mat.start());
645 let start = text.byte_to_char(mat.start());
647 let end = text.byte_to_char(mat.end());
646 let end = text.byte_to_char(mat.end());
648 let selection = Selection::single(start, end - 1);
647 let selection = Selection::single(start, end - 1);
@@ -859,15 +858,15 @@ pub fn command_mode(cx: &mut Context) {
859 let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
858 let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
860
859
861 match *parts.as_slice() {
860 match *parts.as_slice() {
862− ["q"] | ["quit"] => {
861+ ["q" | "quit"] => {
863 editor.close(editor.view().id);
862 editor.close(editor.view().id);
864 // editor.should_close = true,
863 // editor.should_close = true,
865 }
864 }
866− ["o", path] | ["open", path] => {
865+ ["o" | "open", path] => {
867 use helix_view::editor::Action;
866 use helix_view::editor::Action;
868 editor.open(path.into(), Action::Replace);
867 editor.open(path.into(), Action::Replace);
869 }
868 }
870− ["w"] | ["write"] => {
869+ ["w" | "write"] => {
871 // TODO: non-blocking via save() command
870 // TODO: non-blocking via save() command
872 let id = editor.view().doc;
871 let id = editor.view().doc;
873 let doc = &mut editor.documents[id];
872 let doc = &mut editor.documents[id];
@@ -1487,7 +1486,7 @@ pub fn yank(cx: &mut Context) {
1487 let values: Vec<String> = doc
1486 let values: Vec<String> = doc
1488 .selection(view_id)
1487 .selection(view_id)
1489 .fragments(doc.text().slice(..))
1488 .fragments(doc.text().slice(..))
1490− .map(|cow| cow.into_owned())
1489+ .map(Cow::into_owned)
1491 .collect();
1490 .collect();
1492
1491
1493 // TODO: allow specifying reg
1492 // TODO: allow specifying reg
helix-term/src/main.rs+1−1
@@ -77,7 +77,7 @@ fn main() {
77 use helix_core::syntax::{Loader, LOADER};
77 use helix_core::syntax::{Loader, LOADER};
78 let toml = include_str!("../../languages.toml");
78 let toml = include_str!("../../languages.toml");
79 LOADER.get_or_init(|| {
79 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");
81 Loader::new(config)
81 Loader::new(config)
82 });
82 });
83
83
helix-term/src/ui/editor.rs+3−3
@@ -58,13 +58,13 @@ impl EditorView {
58 viewport.width - OFFSET,
58 viewport.width - OFFSET,
59 viewport.height.saturating_sub(1),
59 viewport.height.saturating_sub(1),
60 ); // - 1 for statusline
60 ); // - 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);
62
62
63 // clear with background color
63 // clear with background color
64 // TODO: this seems to prevent setting style later
64 // TODO: this seems to prevent setting style later
65 // surface.set_style(viewport, theme.get("ui.background"));
65 // surface.set_style(viewport, theme.get("ui.background"));
66
66
67− self.render_diagnostics(&doc, view, area, surface, theme, is_focused);
67+ self.render_diagnostics(doc, view, area, surface, theme, is_focused);
68
68
69 let area = Rect::new(
69 let area = Rect::new(
70 viewport.x,
70 viewport.x,
@@ -72,7 +72,7 @@ impl EditorView {
72 viewport.width,
72 viewport.width,
73 1,
73 1,
74 );
74 );
75− self.render_statusline(&doc, area, surface, theme, is_focused);
75+ self.render_statusline(doc, area, surface, theme, is_focused);
76
76
77 // render status
77 // render status
78 if let Some(status_msg) = &self.status_msg {
78 if let Some(status_msg) = &self.status_msg {
helix-term/src/ui/menu.rs+2−2
@@ -90,13 +90,13 @@ impl<T> Menu<T> {
90
90
91 pub fn move_up(&mut self) {
91 pub fn move_up(&mut self) {
92 // TODO: wrap around to end
92 // 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();
94 self.cursor = Some(pos);
94 self.cursor = Some(pos);
95 self.adjust_scroll();
95 self.adjust_scroll();
96 }
96 }
97
97
98 pub fn move_down(&mut self) {
98 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();
100 self.cursor = Some(pos);
100 self.cursor = Some(pos);
101 self.adjust_scroll();
101 self.adjust_scroll();
102 }
102 }
helix-term/src/ui/mod.rs+1−4
@@ -149,10 +149,7 @@ pub mod completers {
149 .build()
149 .build()
150 .filter_map(|file| {
150 .filter_map(|file| {
151 file.ok().map(|entry| {
151 file.ok().map(|entry| {
152− let is_dir = entry
152+ let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
153− .file_type()
154− .map(|entry| entry.is_dir())
155− .unwrap_or(false);
156
153
157 let mut path = entry.path().strip_prefix(&dir).unwrap().to_path_buf();
154 let mut path = entry.path().strip_prefix(&dir).unwrap().to_path_buf();
158
155
helix-term/src/ui/prompt.rs+2−7
@@ -81,8 +81,7 @@ impl Prompt {
81 if self.completion.is_empty() {
81 if self.completion.is_empty() {
82 return;
82 return;
83 }
83 }
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();
86 self.completion_selection_index = Some(index);
85 self.completion_selection_index = Some(index);
87
86
88 let (range, item) = &self.completion[index];
87 let (range, item) = &self.completion[index];
@@ -183,11 +182,7 @@ impl Component for Prompt {
183 // char or shift char
182 // char or shift char
184 KeyEvent {
183 KeyEvent {
185 code: KeyCode::Char(c),
184 code: KeyCode::Char(c),
186− modifiers: KeyModifiers::NONE,
185+ modifiers: KeyModifiers::NONE | KeyModifiers::SHIFT,
187− }
188− | KeyEvent {
189− code: KeyCode::Char(c),
190− modifiers: KeyModifiers::SHIFT,
191 } => {
186 } => {
192 self.insert_char(c);
187 self.insert_char(c);
193 (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
188 (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
helix-view/src/document.rs+3−5
@@ -242,7 +242,7 @@ impl Document {
242 });
242 });
243 }
243 }
244
244
245− let success = self._apply(&transaction, view_id);
245+ let success = self._apply(transaction, view_id);
246
246
247 self.modified = true;
247 self.modified = true;
248 // TODO: be smarter about modified by keeping track of saved version instead. That way if
248 // TODO: be smarter about modified by keeping track of saved version instead. That way if
@@ -342,8 +342,7 @@ impl Document {
342 self.language
342 self.language
343 .as_ref()
343 .as_ref()
344 .and_then(|config| config.indent.as_ref())
344 .and_then(|config| config.indent.as_ref())
345− .map(|config| config.tab_width)
345+ .map_or(4, |config| config.tab_width) // fallback to 4 columns
346− .unwrap_or(4) // fallback to 4 columns
347 }
346 }
348
347
349 /// Returns a string containing a single level of indentation.
348 /// Returns a string containing a single level of indentation.
@@ -351,8 +350,7 @@ impl Document {
351 self.language
350 self.language
352 .as_ref()
351 .as_ref()
353 .and_then(|config| config.indent.as_ref())
352 .and_then(|config| config.indent.as_ref())
354− .map(|config| config.unit.as_str())
353+ .map_or(" ", |config| config.unit.as_str()) // fallback to 2 spaces
355− .unwrap_or(" ") // fallback to 2 spaces
356
354
357 // " ".repeat(TAB_WIDTH)
355 // " ".repeat(TAB_WIDTH)
358 }
356 }
helix-view/src/editor.rs+1
@@ -16,6 +16,7 @@ pub struct Editor {
16 pub executor: &'static smol::Executor<'static>,
16 pub executor: &'static smol::Executor<'static>,
17}
17}
18
18
19+#[derive(Copy, Clone)]
19pub enum Action {
20pub enum Action {
20 Replace,
21 Replace,
21 HorizontalSplit,
22 HorizontalSplit,
helix-view/src/tree.rs+8−11
@@ -29,14 +29,14 @@ pub enum Content {
29
29
30impl Node {
30impl Node {
31 pub fn container(layout: Layout) -> Self {
31 pub fn container(layout: Layout) -> Self {
32− Node {
32+ Self {
33 parent: ViewId::default(),
33 parent: ViewId::default(),
34 content: Content::Container(Box::new(Container::new(layout))),
34 content: Content::Container(Box::new(Container::new(layout))),
35 }
35 }
36 }
36 }
37
37
38 pub fn view(view: View) -> Self {
38 pub fn view(view: View) -> Self {
39− Node {
39+ Self {
40 parent: ViewId::default(),
40 parent: ViewId::default(),
41 content: Content::View(Box::new(view)),
41 content: Content::View(Box::new(view)),
42 }
42 }
@@ -414,15 +414,12 @@ impl Tree {
414 let mut iter = iter.skip_while(|&(key, _view)| key != self.focus);
414 let mut iter = iter.skip_while(|&(key, _view)| key != self.focus);
415 iter.next(); // take the focused value
415 iter.next(); // take the focused value
416
416
417− match iter.next() {
418− Some((key, _)) => {
417+ if let Some((key, _)) = iter.next() {
419− self.focus = key;
418+ self.focus = key;
420− }
419+ } else {
421− None => {
422− // extremely crude, take the first item again
420+ // extremely crude, take the first item again
423− let (key, _) = self.traverse().next().unwrap();
421+ let (key, _) = self.traverse().next().unwrap();
424− self.focus = key;
422+ self.focus = key;
425− }
426 }
423 }
427 }
424 }
428}
425}