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) Some(node)
} }
fn walk(node: Option<Node>, newline: bool) -> usize { fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
let mut increment = 0; let mut increment = 0;
// Hardcoded for rust for now // 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 byte_start = state.doc.char_to_byte(pos);
let node = get_highest_syntax_node_at_bytepos(syntax, byte_start); let node = get_highest_syntax_node_at_bytepos(syntax, byte_start);
let indentation = walk(node, new_line); // TODO: special case for comments
// special case for comments // TODO: if preserve_leading_whitespace
calculate_indentation(node, new_line)
// println!("------------");
// if preserve_leading_whitespace
indentation
} else { } else {
// TODO: heuristics for non-tree sitter grammars // TODO: heuristics for non-tree sitter grammars
0 0

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

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

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

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

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

@ -291,7 +291,7 @@ pub fn split_selection(cx: &mut Context) {
selection::split_on_matches(text, view.doc.selection(), &regex); selection::split_on_matches(text, view.doc.selection(), &regex);
view.doc.set_selection(selection); 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>>(); let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
match parts.as_slice() { match *parts.as_slice() {
&["q"] => editor.should_close = true, ["q"] => editor.should_close = true,
&["o", path] => { ["o", path] => {
// TODO: make view()/view_mut() always contain a view. // TODO: make view()/view_mut() always contain a view.
let size = editor.view().unwrap().size; let size = editor.view().unwrap().size;
editor.open(path.into(), size); editor.open(path.into(), size);

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

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

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

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

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

Loading…
Cancel
Save