1
0
Fork 0
mirror of https://github.com/helix-editor/helix synced 2024-06-01 07:46:05 +02:00

Address clippy lints.

This commit is contained in:
Blaž Hrastnik 2021-01-08 16:31:19 +09:00
parent 7d41550a23
commit 777a80917d
12 changed files with 48 additions and 49 deletions

View File

@ -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

View File

@ -66,7 +66,7 @@ fn len_after(&self) -> usize {
/// 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 @@ pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
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 @@ pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
};
}
Ok(Self {
Self {
len: self.len,
changes,
})
}
}
/// Given another change set starting in the same document, maps this
@ -496,7 +496,7 @@ fn composition() {
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");

View File

@ -5,7 +5,7 @@
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 @@
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 @@ pub fn start(ex: &Executor, cmd: &str, args: &[String]) -> (Self, Receiver<Call>
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 @@ fn next_request_id(&self) -> jsonrpc::Id {
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 @@ pub async fn request<R: lsp::request::Request>(&self, params: R::Params) -> Resu
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 @@ pub async fn notify<R: lsp::notification::Notification>(&self, params: R::Params
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 @@ pub async fn text_document_did_open(
.await
}
fn to_changes(
fn changeset_to_changes(
old_text: &Rope,
changeset: &ChangeSet,
) -> Vec<lsp::TextDocumentContentChangeEvent> {
@ -346,7 +342,7 @@ pub async fn text_document_did_change(
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(()),
};

View File

@ -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();

View File

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

View File

@ -2,7 +2,7 @@
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 @@ pub fn start(
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 @@ pub fn start(
let transport = Self {
reader,
writer,
stderr,
incoming,
outgoing,
pending_requests: Default::default(),

View File

@ -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);

View File

@ -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(())
}

View File

@ -170,9 +170,11 @@ pub fn render_buffer(
// 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

View File

@ -170,12 +170,9 @@ fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
return close_fn;
}
_ => {
match self.prompt.handle_event(event, cx) {
EventResult::Consumed(_) => {
// TODO: recalculate only if pattern changed
self.score();
}
_ => (),
if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
// TODO: recalculate only if pattern changed
self.score();
}
}
}

View File

@ -126,7 +126,7 @@ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
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
};

View File

@ -4,8 +4,7 @@
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 @@ fn take_with<T, F>(mut_ref: &mut T, closure: F)
}
}
use futures_util::TryFutureExt;
use helix_lsp::lsp;
use url::Url;
@ -176,7 +174,7 @@ pub fn apply(&mut self, transaction: &Transaction) -> bool {
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 @@ pub fn undo(&mut self) -> bool {
.unwrap();
}
// TODO: undo / redo need to emit changes to lsp
// reset changeset to fix len
self.changes = ChangeSet::new(self.text());