clippy lint

imgbot
Blaž Hrastnik 3 years ago
parent 15c9a33ebc
commit ceea5eacd8

@ -384,11 +384,13 @@ impl Client {
let capabilities = self.capabilities.as_ref().unwrap(); let capabilities = self.capabilities.as_ref().unwrap();
let sync_capabilities = match capabilities.text_document_sync { let sync_capabilities = match capabilities.text_document_sync {
Some(lsp::TextDocumentSyncCapability::Kind(kind)) => kind, Some(
Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions { lsp::TextDocumentSyncCapability::Kind(kind)
| lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
change: Some(kind), change: Some(kind),
.. ..
})) => kind, }),
) => kind,
// None | SyncOptions { changes: None } // None | SyncOptions { changes: None }
_ => return Ok(()), _ => return Ok(()),
}; };
@ -537,9 +539,8 @@ impl Client {
let capabilities = self.capabilities.as_ref().unwrap(); let capabilities = self.capabilities.as_ref().unwrap();
// check if we're able to format // check if we're able to format
let _capabilities = match capabilities.document_formatting_provider { match capabilities.document_formatting_provider {
Some(lsp::OneOf::Left(true)) => (), Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) => (),
Some(lsp::OneOf::Right(_)) => (),
// None | Some(false) // None | Some(false)
_ => return Ok(Vec::new()), _ => return Ok(Vec::new()),
}; };
@ -567,9 +568,8 @@ impl Client {
let capabilities = self.capabilities.as_ref().unwrap(); let capabilities = self.capabilities.as_ref().unwrap();
// check if we're able to format // check if we're able to format
let _capabilities = match capabilities.document_range_formatting_provider { match capabilities.document_range_formatting_provider {
Some(lsp::OneOf::Left(true)) => (), Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) => (),
Some(lsp::OneOf::Right(_)) => (),
// None | Some(false) // None | Some(false)
_ => return Ok(Vec::new()), _ => return Ok(Vec::new()),
}; };

@ -19,7 +19,7 @@ use smol::{
Executor, Executor,
}; };
pub(crate) enum Payload { pub enum Payload {
Request { Request {
chan: Sender<Result<Value>>, chan: Sender<Result<Value>>,
value: jsonrpc::MethodCall, value: jsonrpc::MethodCall,
@ -40,7 +40,7 @@ enum Message {
Call(jsonrpc::Call), Call(jsonrpc::Call),
} }
pub(crate) struct Transport { pub struct Transport {
incoming: Sender<jsonrpc::Call>, incoming: Sender<jsonrpc::Call>,
outgoing: Receiver<Payload>, outgoing: Receiver<Payload>,
@ -68,8 +68,8 @@ impl Transport {
stderr, stderr,
incoming, incoming,
outgoing, outgoing,
pending_requests: Default::default(), pending_requests: HashMap::default(),
headers: Default::default(), headers: HashMap::default(),
}; };
ex.spawn(transport.duplex()).detach(); ex.spawn(transport.duplex()).detach();

@ -122,7 +122,7 @@ impl Application {
pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) { pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
let mut cx = crate::compositor::Context { let mut cx = crate::compositor::Context {
editor: &mut self.editor, editor: &mut self.editor,
executor: &self.executor, executor: self.executor,
callbacks: &mut self.callbacks, callbacks: &mut self.callbacks,
scroll: None, scroll: None,
}; };

@ -14,6 +14,7 @@ use crate::{
ui::{self, Completion, Picker, Popup, Prompt, PromptEvent}, ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
}; };
use std::borrow::Cow;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use helix_view::{ use helix_view::{
@ -333,7 +334,7 @@ where
let text = doc.text().slice(..); let text = doc.text().slice(..);
let selection = doc.selection(view_id).transform(|mut range| { let selection = doc.selection(view_id).transform(|mut range| {
if let Some(pos) = search::find_nth_next(text, ch, range.head, count, inclusive) { search::find_nth_next(text, ch, range.head, count, inclusive).map_or(range, |pos| {
if extend { if extend {
Range::new(range.anchor, pos) Range::new(range.anchor, pos)
} else { } else {
@ -341,9 +342,7 @@ where
Range::new(range.head, pos) Range::new(range.head, pos)
} }
// or (pos, pos) to move to found val // or (pos, pos) to move to found val
} else { })
range
}
}); });
doc.set_selection(view_id, selection); doc.set_selection(view_id, selection);
@ -642,7 +641,7 @@ fn _search(doc: &mut Document, view_id: ViewId, contents: &str, regex: &Regex) {
let start = doc.selection(view_id).cursor(); let start = doc.selection(view_id).cursor();
// TODO: use find_at to find the next match after the cursor, loop around the end // TODO: use find_at to find the next match after the cursor, loop around the end
if let Some(mat) = regex.find_at(&contents, start) { if let Some(mat) = regex.find_at(contents, start) {
let start = text.byte_to_char(mat.start()); let start = text.byte_to_char(mat.start());
let end = text.byte_to_char(mat.end()); let end = text.byte_to_char(mat.end());
let selection = Selection::single(start, end - 1); let selection = Selection::single(start, end - 1);
@ -859,15 +858,15 @@ pub fn command_mode(cx: &mut Context) {
let parts = input.split_ascii_whitespace().collect::<Vec<&str>>(); let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
match *parts.as_slice() { match *parts.as_slice() {
["q"] | ["quit"] => { ["q" | "quit"] => {
editor.close(editor.view().id); editor.close(editor.view().id);
// editor.should_close = true, // editor.should_close = true,
} }
["o", path] | ["open", path] => { ["o" | "open", path] => {
use helix_view::editor::Action; use helix_view::editor::Action;
editor.open(path.into(), Action::Replace); editor.open(path.into(), Action::Replace);
} }
["w"] | ["write"] => { ["w" | "write"] => {
// TODO: non-blocking via save() command // TODO: non-blocking via save() command
let id = editor.view().doc; let id = editor.view().doc;
let doc = &mut editor.documents[id]; let doc = &mut editor.documents[id];
@ -1487,7 +1486,7 @@ pub fn yank(cx: &mut Context) {
let values: Vec<String> = doc let values: Vec<String> = doc
.selection(view_id) .selection(view_id)
.fragments(doc.text().slice(..)) .fragments(doc.text().slice(..))
.map(|cow| cow.into_owned()) .map(Cow::into_owned)
.collect(); .collect();
// TODO: allow specifying reg // TODO: allow specifying reg

@ -77,7 +77,7 @@ fn main() {
use helix_core::syntax::{Loader, LOADER}; use helix_core::syntax::{Loader, LOADER};
let toml = include_str!("../../languages.toml"); let toml = include_str!("../../languages.toml");
LOADER.get_or_init(|| { LOADER.get_or_init(|| {
let config = toml::from_str(&toml).expect("Could not parse languages.toml"); let config = toml::from_str(toml).expect("Could not parse languages.toml");
Loader::new(config) Loader::new(config)
}); });

@ -58,13 +58,13 @@ impl EditorView {
viewport.width - OFFSET, viewport.width - OFFSET,
viewport.height.saturating_sub(1), viewport.height.saturating_sub(1),
); // - 1 for statusline ); // - 1 for statusline
self.render_buffer(&doc, view, area, surface, theme, is_focused); self.render_buffer(doc, view, area, surface, theme, is_focused);
// clear with background color // clear with background color
// TODO: this seems to prevent setting style later // TODO: this seems to prevent setting style later
// surface.set_style(viewport, theme.get("ui.background")); // surface.set_style(viewport, theme.get("ui.background"));
self.render_diagnostics(&doc, view, area, surface, theme, is_focused); self.render_diagnostics(doc, view, area, surface, theme, is_focused);
let area = Rect::new( let area = Rect::new(
viewport.x, viewport.x,
@ -72,7 +72,7 @@ impl EditorView {
viewport.width, viewport.width,
1, 1,
); );
self.render_statusline(&doc, area, surface, theme, is_focused); self.render_statusline(doc, area, surface, theme, is_focused);
// render status // render status
if let Some(status_msg) = &self.status_msg { if let Some(status_msg) = &self.status_msg {

@ -90,13 +90,13 @@ impl<T> Menu<T> {
pub fn move_up(&mut self) { pub fn move_up(&mut self) {
// TODO: wrap around to end // TODO: wrap around to end
let pos = self.cursor.map(|i| i.saturating_sub(1)).unwrap_or(0) % self.options.len(); let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.options.len();
self.cursor = Some(pos); self.cursor = Some(pos);
self.adjust_scroll(); self.adjust_scroll();
} }
pub fn move_down(&mut self) { pub fn move_down(&mut self) {
let pos = self.cursor.map(|i| i + 1).unwrap_or(0) % self.options.len(); let pos = self.cursor.map_or(0, |i| i + 1) % self.options.len();
self.cursor = Some(pos); self.cursor = Some(pos);
self.adjust_scroll(); self.adjust_scroll();
} }

@ -149,10 +149,7 @@ pub mod completers {
.build() .build()
.filter_map(|file| { .filter_map(|file| {
file.ok().map(|entry| { file.ok().map(|entry| {
let is_dir = entry let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
.file_type()
.map(|entry| entry.is_dir())
.unwrap_or(false);
let mut path = entry.path().strip_prefix(&dir).unwrap().to_path_buf(); let mut path = entry.path().strip_prefix(&dir).unwrap().to_path_buf();

@ -81,8 +81,7 @@ impl Prompt {
if self.completion.is_empty() { if self.completion.is_empty() {
return; return;
} }
let index = let index = self.completion_selection_index.map_or(0, |i| i + 1) % self.completion.len();
self.completion_selection_index.map(|i| i + 1).unwrap_or(0) % self.completion.len();
self.completion_selection_index = Some(index); self.completion_selection_index = Some(index);
let (range, item) = &self.completion[index]; let (range, item) = &self.completion[index];
@ -183,11 +182,7 @@ impl Component for Prompt {
// char or shift char // char or shift char
KeyEvent { KeyEvent {
code: KeyCode::Char(c), code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE, modifiers: KeyModifiers::NONE | KeyModifiers::SHIFT,
}
| KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::SHIFT,
} => { } => {
self.insert_char(c); self.insert_char(c);
(self.callback_fn)(cx.editor, &self.line, PromptEvent::Update); (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);

@ -242,7 +242,7 @@ impl Document {
}); });
} }
let success = self._apply(&transaction, view_id); let success = self._apply(transaction, view_id);
self.modified = true; self.modified = true;
// TODO: be smarter about modified by keeping track of saved version instead. That way if // TODO: be smarter about modified by keeping track of saved version instead. That way if
@ -342,8 +342,7 @@ impl Document {
self.language self.language
.as_ref() .as_ref()
.and_then(|config| config.indent.as_ref()) .and_then(|config| config.indent.as_ref())
.map(|config| config.tab_width) .map_or(4, |config| config.tab_width) // fallback to 4 columns
.unwrap_or(4) // fallback to 4 columns
} }
/// Returns a string containing a single level of indentation. /// Returns a string containing a single level of indentation.
@ -351,8 +350,7 @@ impl Document {
self.language self.language
.as_ref() .as_ref()
.and_then(|config| config.indent.as_ref()) .and_then(|config| config.indent.as_ref())
.map(|config| config.unit.as_str()) .map_or(" ", |config| config.unit.as_str()) // fallback to 2 spaces
.unwrap_or(" ") // fallback to 2 spaces
// " ".repeat(TAB_WIDTH) // " ".repeat(TAB_WIDTH)
} }

@ -16,6 +16,7 @@ pub struct Editor {
pub executor: &'static smol::Executor<'static>, pub executor: &'static smol::Executor<'static>,
} }
#[derive(Copy, Clone)]
pub enum Action { pub enum Action {
Replace, Replace,
HorizontalSplit, HorizontalSplit,

@ -29,14 +29,14 @@ pub enum Content {
impl Node { impl Node {
pub fn container(layout: Layout) -> Self { pub fn container(layout: Layout) -> Self {
Node { Self {
parent: ViewId::default(), parent: ViewId::default(),
content: Content::Container(Box::new(Container::new(layout))), content: Content::Container(Box::new(Container::new(layout))),
} }
} }
pub fn view(view: View) -> Self { pub fn view(view: View) -> Self {
Node { Self {
parent: ViewId::default(), parent: ViewId::default(),
content: Content::View(Box::new(view)), content: Content::View(Box::new(view)),
} }
@ -414,18 +414,15 @@ impl Tree {
let mut iter = iter.skip_while(|&(key, _view)| key != self.focus); let mut iter = iter.skip_while(|&(key, _view)| key != self.focus);
iter.next(); // take the focused value iter.next(); // take the focused value
match iter.next() { if let Some((key, _)) = iter.next() {
Some((key, _)) => {
self.focus = key; self.focus = key;
} } else {
None => {
// extremely crude, take the first item again // extremely crude, take the first item again
let (key, _) = self.traverse().next().unwrap(); let (key, _) = self.traverse().next().unwrap();
self.focus = key; self.focus = key;
} }
} }
} }
}
pub struct Traverse<'a> { pub struct Traverse<'a> {
tree: &'a Tree, tree: &'a Tree,

Loading…
Cancel
Save