on master help sign in
Address clippy lints.
commit777a80917db01e658139da11a20ff08256667cfe authorBlaž Hrastnik <blaz@mxxn.io> dateFri 8 Jan 2021, 16:31 (6 years ago) parent7d41550
12 files changed+48−49
helix-core/src/indent.rs+4−8 helix-core/src/transaction.rs+5−5 helix-lsp/src/client.rs+10−14 helix-lsp/src/lib.rs+6 helix-lsp/src/select_all.rs+1−1 helix-lsp/src/transport.rs+5−1 helix-term/src/commands.rs+4−4 helix-term/src/main.rs+1−3 helix-term/src/ui/editor.rs+4−2 helix-term/src/ui/picker.rs+3−6 helix-term/src/ui/prompt.rs+1−1 helix-view/src/document.rs+4−4
helix-core/src/indent.rs+4−8
@@ -44,7 +44,7 @@ fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option<Nod
4444 Some(node)
4545}
4646
47−fn walk(node: Option<Node>, newline: bool) -> usize {
47+fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
4848 let mut increment = 0;
4949
5050 // Hardcoded for rust for now
@@ -183,13 +183,9 @@ pub fn suggested_indent_for_pos(
183183 let byte_start = state.doc.char_to_byte(pos);
184184 let node = get_highest_syntax_node_at_bytepos(syntax, byte_start);
185185
186− let indentation = walk(node, new_line);
187− // special case for comments
188−
189− // println!("------------");
190− // if preserve_leading_whitespace
191−
192− indentation
186+ // TODO: special case for comments
187+ // TODO: if preserve_leading_whitespace
188+ calculate_indentation(node, new_line)
193189 } else {
194190 // TODO: heuristics for non-tree sitter grammars
195191 0
helix-core/src/transaction.rs+5−5
@@ -66,7 +66,7 @@ impl ChangeSet {
6666 /// Combine two changesets together.
6767 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
6868 /// returned value will represent the change `docA` → `docC`.
69− pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
69+ pub fn compose(self, other: ChangeSet) -> Self {
7070 debug_assert!(self.len_after() == other.len);
7171
7272 let len = self.changes.len();
@@ -99,7 +99,7 @@ impl ChangeSet {
9999 head_a = a;
100100 head_b = changes_b.next();
101101 }
102− (None, _) | (_, None) => return Err(()),
102+ (None, _) | (_, None) => return unreachable!(),
103103 (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
104104 Ordering::Less => {
105105 changes.push(Retain(i));
@@ -180,10 +180,10 @@ impl ChangeSet {
180180 };
181181 }
182182
183− Ok(Self {
183+ Self {
184184 len: self.len,
185185 changes,
186− })
186+ }
187187 }
188188
189189 /// Given another change set starting in the same document, maps this
@@ -496,7 +496,7 @@ mod test {
496496 let mut text = Rope::from("hello xz");
497497
498498 // should probably return cloned text
499− let composed = a.compose(b).unwrap();
499+ let composed = a.compose(b);
500500 assert_eq!(composed.len, 8);
501501 assert!(composed.apply(&mut text));
502502 assert_eq!(text, "world! abc");
helix-lsp/src/client.rs+10−14
@@ -5,7 +5,7 @@ use crate::{
55
66type Result<T> = core::result::Result<T, Error>;
77
8−use helix_core::{ChangeSet, Rope, RopeSlice, Transaction};
8+use helix_core::{ChangeSet, Rope};
99
1010// use std::collections::HashMap;
1111use std::sync::atomic::{AtomicU64, Ordering};
@@ -18,13 +18,12 @@ use smol::{
1818 channel::{Receiver, Sender},
1919 io::{BufReader, BufWriter},
2020 // prelude::*,
21− process::{Child, ChildStderr, Command, Stdio},
21+ process::{Child, Command, Stdio},
2222 Executor,
2323};
2424
2525pub struct Client {
2626 _process: Child,
27− stderr: BufReader<ChildStderr>,
2827
2928 outgoing: Sender<Payload>,
3029 // pub incoming: Receiver<Call>,
@@ -51,11 +50,10 @@ impl Client {
5150 let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
5251 let stderr = BufReader::new(process.stderr.take().expect("Failed to open stderr"));
5352
54− let (incoming, outgoing) = Transport::start(ex, reader, writer);
53+ let (incoming, outgoing) = Transport::start(ex, reader, writer, stderr);
5554
5655 let client = Client {
5756 _process: process,
58− stderr,
5957
6058 outgoing,
6159 // incoming,
@@ -76,17 +74,15 @@ impl Client {
7674 jsonrpc::Id::Num(id)
7775 }
7876
79− fn to_params(value: Value) -> Result<jsonrpc::Params> {
77+ fn value_into_params(value: Value) -> jsonrpc::Params {
8078 use jsonrpc::Params;
8179
82− let params = match value {
80+ match value {
8381 Value::Null => Params::None,
8482 Value::Bool(_) | Value::Number(_) | Value::String(_) => Params::Array(vec![value]),
8583 Value::Array(vec) => Params::Array(vec),
8684 Value::Object(map) => Params::Map(map),
87− };
88−
89− Ok(params)
85+ }
9086 }
9187
9288 /// Execute a RPC request on the language server.
@@ -101,7 +97,7 @@ impl Client {
10197 jsonrpc: Some(jsonrpc::Version::V2),
10298 id: self.next_request_id(),
10399 method: R::METHOD.to_string(),
104− params: Self::to_params(params)?,
100+ params: Self::value_into_params(params),
105101 };
106102
107103 let (tx, rx) = smol::channel::bounded::<Result<Value>>(1);
@@ -143,7 +139,7 @@ impl Client {
143139 let notification = jsonrpc::Notification {
144140 jsonrpc: Some(jsonrpc::Version::V2),
145141 method: R::METHOD.to_string(),
146− params: Self::to_params(params)?,
142+ params: Self::value_into_params(params),
147143 };
148144
149145 self.outgoing
@@ -251,7 +247,7 @@ impl Client {
251247 .await
252248 }
253249
254− fn to_changes(
250+ fn changeset_to_changes(
255251 old_text: &Rope,
256252 changeset: &ChangeSet,
257253 ) -> Vec<lsp::TextDocumentContentChangeEvent> {
@@ -346,7 +342,7 @@ impl Client {
346342 text: "".to_string(),
347343 }] // TODO: probably need old_state here too?
348344 }
349− lsp::TextDocumentSyncKind::Incremental => Self::to_changes(old_text, changes),
345+ lsp::TextDocumentSyncKind::Incremental => Self::changeset_to_changes(old_text, changes),
350346 lsp::TextDocumentSyncKind::None => return Ok(()),
351347 };
352348
helix-lsp/src/lib.rs+6
@@ -104,6 +104,12 @@ pub struct Registry {
104104 pub incoming: SelectAll<Receiver<Call>>,
105105}
106106
107+impl Default for Registry {
108+ fn default() -> Self {
109+ Self::new()
110+ }
111+}
112+
107113impl Registry {
108114 pub fn new() -> Self {
109115 let mut inner = HashMap::new();
helix-lsp/src/select_all.rs+1−1
@@ -119,7 +119,7 @@ where
119119 I: IntoIterator,
120120 I::Item: Stream + Unpin,
121121{
122− let mut set = SelectAll::new();
122+ let set = SelectAll::new();
123123
124124 for stream in streams {
125125 set.push(stream);
helix-lsp/src/transport.rs+5−1
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22
33use log::{debug, error};
44
5−use crate::{Error, Notification};
5+use crate::Error;
66
77type Result<T> = core::result::Result<T, Error>;
88
@@ -48,6 +48,8 @@ pub(crate) struct Transport {
4848
4949 writer: BufWriter<ChildStdin>,
5050 reader: BufReader<ChildStdout>,
51+ #[allow(dead_code)] // TODO: handle stderr logs
52+ stderr: BufReader<ChildStderr>,
5153}
5254
5355impl Transport {
@@ -55,6 +57,7 @@ impl Transport {
5557 ex: &Executor,
5658 reader: BufReader<ChildStdout>,
5759 writer: BufWriter<ChildStdin>,
60+ stderr: BufReader<ChildStderr>,
5861 ) -> (Receiver<jsonrpc::Call>, Sender<Payload>) {
5962 let (incoming, rx) = smol::channel::unbounded();
6063 let (tx, outgoing) = smol::channel::unbounded();
@@ -62,6 +65,7 @@ impl Transport {
6265 let transport = Self {
6366 reader,
6467 writer,
68+ stderr,
6569 incoming,
6670 outgoing,
6771 pending_requests: Default::default(),
helix-term/src/commands.rs+4−4
@@ -291,7 +291,7 @@ pub fn split_selection(cx: &mut Context) {
291291 selection::split_on_matches(text, view.doc.selection(), &regex);
292292 view.doc.set_selection(selection);
293293 }
294− Err(_) => (), // TODO: mark command line as error
294+ Err(_err) => (), // TODO: mark command line as error
295295 }
296296 }
297297 }
@@ -453,9 +453,9 @@ pub fn command_mode(cx: &mut Context) {
453453
454454 let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
455455
456− match parts.as_slice() {
457− &["q"] => editor.should_close = true,
458− &["o", path] => {
456+ match *parts.as_slice() {
457+ ["q"] => editor.should_close = true,
458+ ["o", path] => {
459459 // TODO: make view()/view_mut() always contain a view.
460460 let size = editor.view().unwrap().size;
461461 editor.open(path.into(), size);
helix-term/src/main.rs+1−3
@@ -49,7 +49,7 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
4949 Ok(())
5050}
5151
52−fn main() -> Result<(), Error> {
52+fn main() {
5353 let args = clap::app_from_crate!()
5454 .arg(
5555 Arg::new("files")
@@ -79,6 +79,4 @@ fn main() -> Result<(), Error> {
7979
8080 // we use the thread local executor to spawn the application task separately from the work pool
8181 smol::block_on(app.run());
82−
83− Ok(())
8482}
helix-term/src/ui/editor.rs+4−2
@@ -170,9 +170,11 @@ impl EditorView {
170170
171171 // ugh, improve with a traverse method
172172 // or interleave highlight spans with selection and diagnostic spans
173− let style = if view.doc.diagnostics.iter().any(|diagnostic| {
173+ let is_diagnostic = view.doc.diagnostics.iter().any(|diagnostic| {
174174 diagnostic.range.0 <= char_index && diagnostic.range.1 > char_index
175− }) {
175+ });
176+
177+ let style = if is_diagnostic {
176178 style.clone().add_modifier(Modifier::UNDERLINED)
177179 } else {
178180 style
helix-term/src/ui/picker.rs+3−6
@@ -170,12 +170,9 @@ impl<T> Component for Picker<T> {
170170 return close_fn;
171171 }
172172 _ => {
173− match self.prompt.handle_event(event, cx) {
174− EventResult::Consumed(_) => {
175− // TODO: recalculate only if pattern changed
176− self.score();
177− }
178− _ => (),
173+ if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
174+ // TODO: recalculate only if pattern changed
175+ self.score();
179176 }
180177 }
181178 }
helix-term/src/ui/prompt.rs+1−1
@@ -126,7 +126,7 @@ impl Prompt {
126126 let color = if self.completion_selection_index.is_some()
127127 && i == self.completion_selection_index.unwrap()
128128 {
129− Style::default().bg(Color::Rgb(104, 060, 232))
129+ Style::default().bg(Color::Rgb(104, 60, 232))
130130 } else {
131131 text_color
132132 };
helix-view/src/document.rs+4−4
@@ -4,8 +4,7 @@ use std::path::{Path, PathBuf};
44use std::sync::Arc;
55
66use helix_core::{
7− syntax::LOADER, ChangeSet, Diagnostic, History, Position, Range, Rope, RopeSlice, Selection,
8− State, Syntax, Transaction,
7+ syntax::LOADER, ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction,
98};
109
1110#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@@ -55,7 +54,6 @@ where
5554 }
5655}
5756
58−use futures_util::TryFutureExt;
5957use helix_lsp::lsp;
6058use url::Url;
6159
@@ -176,7 +174,7 @@ impl Document {
176174 if !transaction.changes().is_empty() {
177175 // Compose this transaction with the previous one
178176 take_with(&mut self.changes, |changes| {
179− changes.compose(transaction.changes().clone()).unwrap()
177+ changes.compose(transaction.changes().clone())
180178 });
181179
182180 // TODO: when composing, replace transaction.selection too
@@ -219,6 +217,8 @@ impl Document {
219217 .unwrap();
220218 }
221219
220+ // TODO: undo / redo need to emit changes to lsp
221+
222222 // reset changeset to fix len
223223 self.changes = ChangeSet::new(self.text());
224224