Address clippy lints.

pull/8/head
Blaž Hrastnik 4 years ago
parent 7d41550a23
commit 777a80917d

@ -44,7 +44,7 @@ fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option<Nod
Some(node)
}
fn walk(node: Option<Node>, newline: bool) -> usize {
fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
let mut increment = 0;
// Hardcoded for rust for now
@ -183,13 +183,9 @@ pub fn suggested_indent_for_pos(
let byte_start = state.doc.char_to_byte(pos);
let node = get_highest_syntax_node_at_bytepos(syntax, byte_start);
let indentation = walk(node, new_line);
// special case for comments
// println!("------------");
// if preserve_leading_whitespace
indentation
// TODO: special case for comments
// TODO: if preserve_leading_whitespace
calculate_indentation(node, new_line)
} else {
// TODO: heuristics for non-tree sitter grammars
0

@ -66,7 +66,7 @@ impl ChangeSet {
/// Combine two changesets together.
/// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
/// returned value will represent the change `docA` → `docC`.
pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
pub fn compose(self, other: ChangeSet) -> Self {
debug_assert!(self.len_after() == other.len);
let len = self.changes.len();
@ -99,7 +99,7 @@ impl ChangeSet {
head_a = a;
head_b = changes_b.next();
}
(None, _) | (_, None) => return Err(()),
(None, _) | (_, None) => return unreachable!(),
(Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
Ordering::Less => {
changes.push(Retain(i));
@ -180,10 +180,10 @@ impl ChangeSet {
};
}
Ok(Self {
Self {
len: self.len,
changes,
})
}
}
/// Given another change set starting in the same document, maps this
@ -496,7 +496,7 @@ mod test {
let mut text = Rope::from("hello xz");
// should probably return cloned text
let composed = a.compose(b).unwrap();
let composed = a.compose(b);
assert_eq!(composed.len, 8);
assert!(composed.apply(&mut text));
assert_eq!(text, "world! abc");

@ -5,7 +5,7 @@ use crate::{
type Result<T> = core::result::Result<T, Error>;
use helix_core::{ChangeSet, Rope, RopeSlice, Transaction};
use helix_core::{ChangeSet, Rope};
// use std::collections::HashMap;
use std::sync::atomic::{AtomicU64, Ordering};
@ -18,13 +18,12 @@ use smol::{
channel::{Receiver, Sender},
io::{BufReader, BufWriter},
// prelude::*,
process::{Child, ChildStderr, Command, Stdio},
process::{Child, Command, Stdio},
Executor,
};
pub struct Client {
_process: Child,
stderr: BufReader<ChildStderr>,
outgoing: Sender<Payload>,
// pub incoming: Receiver<Call>,
@ -51,11 +50,10 @@ impl Client {
let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
let stderr = BufReader::new(process.stderr.take().expect("Failed to open stderr"));
let (incoming, outgoing) = Transport::start(ex, reader, writer);
let (incoming, outgoing) = Transport::start(ex, reader, writer, stderr);
let client = Client {
_process: process,
stderr,
outgoing,
// incoming,
@ -76,17 +74,15 @@ impl Client {
jsonrpc::Id::Num(id)
}
fn to_params(value: Value) -> Result<jsonrpc::Params> {
fn value_into_params(value: Value) -> jsonrpc::Params {
use jsonrpc::Params;
let params = match value {
match value {
Value::Null => Params::None,
Value::Bool(_) | Value::Number(_) | Value::String(_) => Params::Array(vec![value]),
Value::Array(vec) => Params::Array(vec),
Value::Object(map) => Params::Map(map),
};
Ok(params)
}
}
/// Execute a RPC request on the language server.
@ -101,7 +97,7 @@ impl Client {
jsonrpc: Some(jsonrpc::Version::V2),
id: self.next_request_id(),
method: R::METHOD.to_string(),
params: Self::to_params(params)?,
params: Self::value_into_params(params),
};
let (tx, rx) = smol::channel::bounded::<Result<Value>>(1);
@ -143,7 +139,7 @@ impl Client {
let notification = jsonrpc::Notification {
jsonrpc: Some(jsonrpc::Version::V2),
method: R::METHOD.to_string(),
params: Self::to_params(params)?,
params: Self::value_into_params(params),
};
self.outgoing
@ -251,7 +247,7 @@ impl Client {
.await
}
fn to_changes(
fn changeset_to_changes(
old_text: &Rope,
changeset: &ChangeSet,
) -> Vec<lsp::TextDocumentContentChangeEvent> {
@ -346,7 +342,7 @@ impl Client {
text: "".to_string(),
}] // TODO: probably need old_state here too?
}
lsp::TextDocumentSyncKind::Incremental => Self::to_changes(old_text, changes),
lsp::TextDocumentSyncKind::Incremental => Self::changeset_to_changes(old_text, changes),
lsp::TextDocumentSyncKind::None => return Ok(()),
};

@ -104,6 +104,12 @@ pub struct Registry {
pub incoming: SelectAll<Receiver<Call>>,
}
impl Default for Registry {
fn default() -> Self {
Self::new()
}
}
impl Registry {
pub fn new() -> Self {
let mut inner = HashMap::new();

@ -119,7 +119,7 @@ where
I: IntoIterator,
I::Item: Stream + Unpin,
{
let mut set = SelectAll::new();
let set = SelectAll::new();
for stream in streams {
set.push(stream);

@ -2,7 +2,7 @@ use std::collections::HashMap;
use log::{debug, error};
use crate::{Error, Notification};
use crate::Error;
type Result<T> = core::result::Result<T, Error>;
@ -48,6 +48,8 @@ pub(crate) struct Transport {
writer: BufWriter<ChildStdin>,
reader: BufReader<ChildStdout>,
#[allow(dead_code)] // TODO: handle stderr logs
stderr: BufReader<ChildStderr>,
}
impl Transport {
@ -55,6 +57,7 @@ impl Transport {
ex: &Executor,
reader: BufReader<ChildStdout>,
writer: BufWriter<ChildStdin>,
stderr: BufReader<ChildStderr>,
) -> (Receiver<jsonrpc::Call>, Sender<Payload>) {
let (incoming, rx) = smol::channel::unbounded();
let (tx, outgoing) = smol::channel::unbounded();
@ -62,6 +65,7 @@ impl Transport {
let transport = Self {
reader,
writer,
stderr,
incoming,
outgoing,
pending_requests: Default::default(),

@ -291,7 +291,7 @@ pub fn split_selection(cx: &mut Context) {
selection::split_on_matches(text, view.doc.selection(), &regex);
view.doc.set_selection(selection);
}
Err(_) => (), // TODO: mark command line as error
Err(_err) => (), // TODO: mark command line as error
}
}
}
@ -453,9 +453,9 @@ pub fn command_mode(cx: &mut Context) {
let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
match parts.as_slice() {
&["q"] => editor.should_close = true,
&["o", path] => {
match *parts.as_slice() {
["q"] => editor.should_close = true,
["o", path] => {
// TODO: make view()/view_mut() always contain a view.
let size = editor.view().unwrap().size;
editor.open(path.into(), size);

@ -49,7 +49,7 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
Ok(())
}
fn main() -> Result<(), Error> {
fn main() {
let args = clap::app_from_crate!()
.arg(
Arg::new("files")
@ -79,6 +79,4 @@ fn main() -> Result<(), Error> {
// we use the thread local executor to spawn the application task separately from the work pool
smol::block_on(app.run());
Ok(())
}

@ -170,9 +170,11 @@ impl EditorView {
// ugh, improve with a traverse method
// or interleave highlight spans with selection and diagnostic spans
let style = if view.doc.diagnostics.iter().any(|diagnostic| {
let is_diagnostic = view.doc.diagnostics.iter().any(|diagnostic| {
diagnostic.range.0 <= char_index && diagnostic.range.1 > char_index
}) {
});
let style = if is_diagnostic {
style.clone().add_modifier(Modifier::UNDERLINED)
} else {
style

@ -170,13 +170,10 @@ impl<T> Component for Picker<T> {
return close_fn;
}
_ => {
match self.prompt.handle_event(event, cx) {
EventResult::Consumed(_) => {
if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
// TODO: recalculate only if pattern changed
self.score();
}
_ => (),
}
}
}

@ -126,7 +126,7 @@ impl Prompt {
let color = if self.completion_selection_index.is_some()
&& i == self.completion_selection_index.unwrap()
{
Style::default().bg(Color::Rgb(104, 060, 232))
Style::default().bg(Color::Rgb(104, 60, 232))
} else {
text_color
};

@ -4,8 +4,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use helix_core::{
syntax::LOADER, ChangeSet, Diagnostic, History, Position, Range, Rope, RopeSlice, Selection,
State, Syntax, Transaction,
syntax::LOADER, ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction,
};
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@ -55,7 +54,6 @@ where
}
}
use futures_util::TryFutureExt;
use helix_lsp::lsp;
use url::Url;
@ -176,7 +174,7 @@ impl Document {
if !transaction.changes().is_empty() {
// Compose this transaction with the previous one
take_with(&mut self.changes, |changes| {
changes.compose(transaction.changes().clone()).unwrap()
changes.compose(transaction.changes().clone())
});
// TODO: when composing, replace transaction.selection too
@ -219,6 +217,8 @@ impl Document {
.unwrap();
}
// TODO: undo / redo need to emit changes to lsp
// reset changeset to fix len
self.changes = ChangeSet::new(self.text());

Loading…
Cancel
Save