clippy lint

pull/11/head
Blaž Hrastnik 4 years ago
parent 15c9a33ebc
commit ceea5eacd8

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

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

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

@ -14,6 +14,7 @@ use crate::{
ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
};
use std::borrow::Cow;
use std::path::{Path, PathBuf};
use helix_view::{
@ -333,7 +334,7 @@ where
let text = doc.text().slice(..);
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 {
Range::new(range.anchor, pos)
} else {
@ -341,9 +342,7 @@ where
Range::new(range.head, pos)
}
// or (pos, pos) to move to found val
} else {
range
}
})
});
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();
// 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 end = text.byte_to_char(mat.end());
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>>();
match *parts.as_slice() {
["q"] | ["quit"] => {
["q" | "quit"] => {
editor.close(editor.view().id);
// editor.should_close = true,
}
["o", path] | ["open", path] => {
["o" | "open", path] => {
use helix_view::editor::Action;
editor.open(path.into(), Action::Replace);
}
["w"] | ["write"] => {
["w" | "write"] => {
// TODO: non-blocking via save() command
let id = editor.view().doc;
let doc = &mut editor.documents[id];
@ -1487,7 +1486,7 @@ pub fn yank(cx: &mut Context) {
let values: Vec<String> = doc
.selection(view_id)
.fragments(doc.text().slice(..))
.map(|cow| cow.into_owned())
.map(Cow::into_owned)
.collect();
// TODO: allow specifying reg

@ -77,7 +77,7 @@ fn main() {
use helix_core::syntax::{Loader, LOADER};
let toml = include_str!("../../languages.toml");
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)
});

@ -58,13 +58,13 @@ impl EditorView {
viewport.width - OFFSET,
viewport.height.saturating_sub(1),
); // - 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
// TODO: this seems to prevent setting style later
// 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(
viewport.x,
@ -72,7 +72,7 @@ impl EditorView {
viewport.width,
1,
);
self.render_statusline(&doc, area, surface, theme, is_focused);
self.render_statusline(doc, area, surface, theme, is_focused);
// render status
if let Some(status_msg) = &self.status_msg {

@ -90,13 +90,13 @@ impl<T> Menu<T> {
pub fn move_up(&mut self) {
// 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.adjust_scroll();
}
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.adjust_scroll();
}

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

@ -81,8 +81,7 @@ impl Prompt {
if self.completion.is_empty() {
return;
}
let index =
self.completion_selection_index.map(|i| i + 1).unwrap_or(0) % self.completion.len();
let index = self.completion_selection_index.map_or(0, |i| i + 1) % self.completion.len();
self.completion_selection_index = Some(index);
let (range, item) = &self.completion[index];
@ -183,11 +182,7 @@ impl Component for Prompt {
// char or shift char
KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE,
}
| KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::SHIFT,
modifiers: KeyModifiers::NONE | KeyModifiers::SHIFT,
} => {
self.insert_char(c);
(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;
// TODO: be smarter about modified by keeping track of saved version instead. That way if
@ -342,8 +342,7 @@ impl Document {
self.language
.as_ref()
.and_then(|config| config.indent.as_ref())
.map(|config| config.tab_width)
.unwrap_or(4) // fallback to 4 columns
.map_or(4, |config| config.tab_width) // fallback to 4 columns
}
/// Returns a string containing a single level of indentation.
@ -351,8 +350,7 @@ impl Document {
self.language
.as_ref()
.and_then(|config| config.indent.as_ref())
.map(|config| config.unit.as_str())
.unwrap_or(" ") // fallback to 2 spaces
.map_or(" ", |config| config.unit.as_str()) // fallback to 2 spaces
// " ".repeat(TAB_WIDTH)
}

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

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

Loading…
Cancel
Save