on master help sign in
Address clippy lints.
777a809Blaž Hrastnik
helix-core/src/indent.rs+4−8
@@ -44,7 +44,7 @@ fn get_highest_syntax_node_at_bytepos(syntax: &Syntax, pos: usize) -> Option<Nod
44 Some(node)
44 Some(node)
45}
45}
46
46
47−fn walk(node: Option<Node>, newline: bool) -> usize {
47+fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
48 let mut increment = 0;
48 let mut increment = 0;
49
49
50 // Hardcoded for rust for now
50 // Hardcoded for rust for now
@@ -183,13 +183,9 @@ pub fn suggested_indent_for_pos(
183 let byte_start = state.doc.char_to_byte(pos);
183 let byte_start = state.doc.char_to_byte(pos);
184 let node = get_highest_syntax_node_at_bytepos(syntax, byte_start);
184 let node = get_highest_syntax_node_at_bytepos(syntax, byte_start);
185
185
186− let indentation = walk(node, new_line);
187− // special case for comments
186+ // TODO: special case for comments
188−
189− // println!("------------");
190− // if preserve_leading_whitespace
187+ // TODO: if preserve_leading_whitespace
191−
188+ calculate_indentation(node, new_line)
192− indentation
193 } else {
189 } else {
194 // TODO: heuristics for non-tree sitter grammars
190 // TODO: heuristics for non-tree sitter grammars
195 0
191 0
helix-core/src/transaction.rs+5−5
@@ -66,7 +66,7 @@ impl ChangeSet {
66 /// Combine two changesets together.
66 /// Combine two changesets together.
67 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
67 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
68 /// returned value will represent the change `docA` → `docC`.
68 /// 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 {
70 debug_assert!(self.len_after() == other.len);
70 debug_assert!(self.len_after() == other.len);
71
71
72 let len = self.changes.len();
72 let len = self.changes.len();
@@ -99,7 +99,7 @@ impl ChangeSet {
99 head_a = a;
99 head_a = a;
100 head_b = changes_b.next();
100 head_b = changes_b.next();
101 }
101 }
102− (None, _) | (_, None) => return Err(()),
102+ (None, _) | (_, None) => return unreachable!(),
103 (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
103 (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
104 Ordering::Less => {
104 Ordering::Less => {
105 changes.push(Retain(i));
105 changes.push(Retain(i));
@@ -180,10 +180,10 @@ impl ChangeSet {
180 };
180 };
181 }
181 }
182
182
183− Ok(Self {
183+ Self {
184 len: self.len,
184 len: self.len,
185 changes,
185 changes,
186− })
186+ }
187 }
187 }
188
188
189 /// Given another change set starting in the same document, maps this
189 /// Given another change set starting in the same document, maps this
@@ -496,7 +496,7 @@ mod test {
496 let mut text = Rope::from("hello xz");
496 let mut text = Rope::from("hello xz");
497
497
498 // should probably return cloned text
498 // should probably return cloned text
499− let composed = a.compose(b).unwrap();
499+ let composed = a.compose(b);
500 assert_eq!(composed.len, 8);
500 assert_eq!(composed.len, 8);
501 assert!(composed.apply(&mut text));
501 assert!(composed.apply(&mut text));
502 assert_eq!(text, "world! abc");
502 assert_eq!(text, "world! abc");
helix-lsp/src/client.rs+10−14
@@ -5,7 +5,7 @@ use crate::{
5
5
6type Result<T> = core::result::Result<T, Error>;
6type Result<T> = core::result::Result<T, Error>;
7
7
8−use helix_core::{ChangeSet, Rope, RopeSlice, Transaction};
8+use helix_core::{ChangeSet, Rope};
9
9
10// use std::collections::HashMap;
10// use std::collections::HashMap;
11use std::sync::atomic::{AtomicU64, Ordering};
11use std::sync::atomic::{AtomicU64, Ordering};
@@ -18,13 +18,12 @@ use smol::{
18 channel::{Receiver, Sender},
18 channel::{Receiver, Sender},
19 io::{BufReader, BufWriter},
19 io::{BufReader, BufWriter},
20 // prelude::*,
20 // prelude::*,
21− process::{Child, ChildStderr, Command, Stdio},
21+ process::{Child, Command, Stdio},
22 Executor,
22 Executor,
23};
23};
24
24
25pub struct Client {
25pub struct Client {
26 _process: Child,
26 _process: Child,
27− stderr: BufReader<ChildStderr>,
28
27
29 outgoing: Sender<Payload>,
28 outgoing: Sender<Payload>,
30 // pub incoming: Receiver<Call>,
29 // pub incoming: Receiver<Call>,
@@ -51,11 +50,10 @@ impl Client {
51 let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
50 let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout"));
52 let stderr = BufReader::new(process.stderr.take().expect("Failed to open stderr"));
51 let stderr = BufReader::new(process.stderr.take().expect("Failed to open stderr"));
53
52
54− let (incoming, outgoing) = Transport::start(ex, reader, writer);
53+ let (incoming, outgoing) = Transport::start(ex, reader, writer, stderr);
55
54
56 let client = Client {
55 let client = Client {
57 _process: process,
56 _process: process,
58− stderr,
59
57
60 outgoing,
58 outgoing,
61 // incoming,
59 // incoming,
@@ -76,17 +74,15 @@ impl Client {
76 jsonrpc::Id::Num(id)
74 jsonrpc::Id::Num(id)
77 }
75 }
78
76
79− fn to_params(value: Value) -> Result<jsonrpc::Params> {
77+ fn value_into_params(value: Value) -> jsonrpc::Params {
80 use jsonrpc::Params;
78 use jsonrpc::Params;
81
79
82− let params = match value {
80+ match value {
83 Value::Null => Params::None,
81 Value::Null => Params::None,
84 Value::Bool(_) | Value::Number(_) | Value::String(_) => Params::Array(vec![value]),
82 Value::Bool(_) | Value::Number(_) | Value::String(_) => Params::Array(vec![value]),
85 Value::Array(vec) => Params::Array(vec),
83 Value::Array(vec) => Params::Array(vec),
86 Value::Object(map) => Params::Map(map),
84 Value::Object(map) => Params::Map(map),
87− };
85+ }
88−
89− Ok(params)
90 }
86 }
91
87
92 /// Execute a RPC request on the language server.
88 /// Execute a RPC request on the language server.
@@ -101,7 +97,7 @@ impl Client {
101 jsonrpc: Some(jsonrpc::Version::V2),
97 jsonrpc: Some(jsonrpc::Version::V2),
102 id: self.next_request_id(),
98 id: self.next_request_id(),
103 method: R::METHOD.to_string(),
99 method: R::METHOD.to_string(),
104− params: Self::to_params(params)?,
100+ params: Self::value_into_params(params),
105 };
101 };
106
102
107 let (tx, rx) = smol::channel::bounded::<Result<Value>>(1);
103 let (tx, rx) = smol::channel::bounded::<Result<Value>>(1);
@@ -143,7 +139,7 @@ impl Client {
143 let notification = jsonrpc::Notification {
139 let notification = jsonrpc::Notification {
144 jsonrpc: Some(jsonrpc::Version::V2),
140 jsonrpc: Some(jsonrpc::Version::V2),
145 method: R::METHOD.to_string(),
141 method: R::METHOD.to_string(),
146− params: Self::to_params(params)?,
142+ params: Self::value_into_params(params),
147 };
143 };
148
144
149 self.outgoing
145 self.outgoing
@@ -251,7 +247,7 @@ impl Client {
251 .await
247 .await
252 }
248 }
253
249
254− fn to_changes(
250+ fn changeset_to_changes(
255 old_text: &Rope,
251 old_text: &Rope,
256 changeset: &ChangeSet,
252 changeset: &ChangeSet,
257 ) -> Vec<lsp::TextDocumentContentChangeEvent> {
253 ) -> Vec<lsp::TextDocumentContentChangeEvent> {
@@ -346,7 +342,7 @@ impl Client {
346 text: "".to_string(),
342 text: "".to_string(),
347 }] // TODO: probably need old_state here too?
343 }] // TODO: probably need old_state here too?
348 }
344 }
349− lsp::TextDocumentSyncKind::Incremental => Self::to_changes(old_text, changes),
345+ lsp::TextDocumentSyncKind::Incremental => Self::changeset_to_changes(old_text, changes),
350 lsp::TextDocumentSyncKind::None => return Ok(()),
346 lsp::TextDocumentSyncKind::None => return Ok(()),
351 };
347 };
352
348
helix-lsp/src/lib.rs+6
@@ -104,6 +104,12 @@ pub struct Registry {
104 pub incoming: SelectAll<Receiver<Call>>,
104 pub incoming: SelectAll<Receiver<Call>>,
105}
105}
106
106
107+impl Default for Registry {
108+ fn default() -> Self {
109+ Self::new()
110+ }
111+}
112+
107impl Registry {
113impl Registry {
108 pub fn new() -> Self {
114 pub fn new() -> Self {
109 let mut inner = HashMap::new();
115 let mut inner = HashMap::new();
helix-lsp/src/select_all.rs+1−1
@@ -119,7 +119,7 @@ where
119 I: IntoIterator,
119 I: IntoIterator,
120 I::Item: Stream + Unpin,
120 I::Item: Stream + Unpin,
121{
121{
122− let mut set = SelectAll::new();
122+ let set = SelectAll::new();
123
123
124 for stream in streams {
124 for stream in streams {
125 set.push(stream);
125 set.push(stream);
helix-lsp/src/transport.rs+5−1
@@ -2,7 +2,7 @@ use std::collections::HashMap;
2
2
3use log::{debug, error};
3use log::{debug, error};
4
4
5−use crate::{Error, Notification};
5+use crate::Error;
6
6
7type Result<T> = core::result::Result<T, Error>;
7type Result<T> = core::result::Result<T, Error>;
8
8
@@ -48,6 +48,8 @@ pub(crate) struct Transport {
48
48
49 writer: BufWriter<ChildStdin>,
49 writer: BufWriter<ChildStdin>,
50 reader: BufReader<ChildStdout>,
50 reader: BufReader<ChildStdout>,
51+ #[allow(dead_code)] // TODO: handle stderr logs
52+ stderr: BufReader<ChildStderr>,
51}
53}
52
54
53impl Transport {
55impl Transport {
@@ -55,6 +57,7 @@ impl Transport {
55 ex: &Executor,
57 ex: &Executor,
56 reader: BufReader<ChildStdout>,
58 reader: BufReader<ChildStdout>,
57 writer: BufWriter<ChildStdin>,
59 writer: BufWriter<ChildStdin>,
60+ stderr: BufReader<ChildStderr>,
58 ) -> (Receiver<jsonrpc::Call>, Sender<Payload>) {
61 ) -> (Receiver<jsonrpc::Call>, Sender<Payload>) {
59 let (incoming, rx) = smol::channel::unbounded();
62 let (incoming, rx) = smol::channel::unbounded();
60 let (tx, outgoing) = smol::channel::unbounded();
63 let (tx, outgoing) = smol::channel::unbounded();
@@ -62,6 +65,7 @@ impl Transport {
62 let transport = Self {
65 let transport = Self {
63 reader,
66 reader,
64 writer,
67 writer,
68+ stderr,
65 incoming,
69 incoming,
66 outgoing,
70 outgoing,
67 pending_requests: Default::default(),
71 pending_requests: Default::default(),
helix-term/src/commands.rs+4−4
@@ -291,7 +291,7 @@ pub fn split_selection(cx: &mut Context) {
291 selection::split_on_matches(text, view.doc.selection(), &regex);
291 selection::split_on_matches(text, view.doc.selection(), &regex);
292 view.doc.set_selection(selection);
292 view.doc.set_selection(selection);
293 }
293 }
294− Err(_) => (), // TODO: mark command line as error
294+ Err(_err) => (), // TODO: mark command line as error
295 }
295 }
296 }
296 }
297 }
297 }
@@ -453,9 +453,9 @@ pub fn command_mode(cx: &mut Context) {
453
453
454 let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
454 let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
455
455
456− match parts.as_slice() {
456+ match *parts.as_slice() {
457− &["q"] => editor.should_close = true,
457+ ["q"] => editor.should_close = true,
458− &["o", path] => {
458+ ["o", path] => {
459 // TODO: make view()/view_mut() always contain a view.
459 // TODO: make view()/view_mut() always contain a view.
460 let size = editor.view().unwrap().size;
460 let size = editor.view().unwrap().size;
461 editor.open(path.into(), size);
461 editor.open(path.into(), size);
helix-term/src/main.rs+1−3
@@ -49,7 +49,7 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
49 Ok(())
49 Ok(())
50}
50}
51
51
52−fn main() -> Result<(), Error> {
52+fn main() {
53 let args = clap::app_from_crate!()
53 let args = clap::app_from_crate!()
54 .arg(
54 .arg(
55 Arg::new("files")
55 Arg::new("files")
@@ -79,6 +79,4 @@ fn main() -> Result<(), Error> {
79
79
80 // we use the thread local executor to spawn the application task separately from the work pool
80 // we use the thread local executor to spawn the application task separately from the work pool
81 smol::block_on(app.run());
81 smol::block_on(app.run());
82−
83− Ok(())
84}
82}
helix-term/src/ui/editor.rs+4−2
@@ -170,9 +170,11 @@ impl EditorView {
170
170
171 // ugh, improve with a traverse method
171 // ugh, improve with a traverse method
172 // or interleave highlight spans with selection and diagnostic spans
172 // 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| {
174 diagnostic.range.0 <= char_index && diagnostic.range.1 > char_index
174 diagnostic.range.0 <= char_index && diagnostic.range.1 > char_index
175− }) {
175+ });
176+
177+ let style = if is_diagnostic {
176 style.clone().add_modifier(Modifier::UNDERLINED)
178 style.clone().add_modifier(Modifier::UNDERLINED)
177 } else {
179 } else {
178 style
180 style
helix-term/src/ui/picker.rs+3−6
@@ -170,12 +170,9 @@ impl<T> Component for Picker<T> {
170 return close_fn;
170 return close_fn;
171 }
171 }
172 _ => {
172 _ => {
173− match self.prompt.handle_event(event, cx) {
173+ if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
174− EventResult::Consumed(_) => {
175− // TODO: recalculate only if pattern changed
174+ // TODO: recalculate only if pattern changed
176− self.score();
175+ self.score();
177− }
178− _ => (),
179 }
176 }
180 }
177 }
181 }
178 }
helix-term/src/ui/prompt.rs+1−1
@@ -126,7 +126,7 @@ impl Prompt {
126 let color = if self.completion_selection_index.is_some()
126 let color = if self.completion_selection_index.is_some()
127 && i == self.completion_selection_index.unwrap()
127 && i == self.completion_selection_index.unwrap()
128 {
128 {
129− Style::default().bg(Color::Rgb(104, 060, 232))
129+ Style::default().bg(Color::Rgb(104, 60, 232))
130 } else {
130 } else {
131 text_color
131 text_color
132 };
132 };
helix-view/src/document.rs+4−4
@@ -4,8 +4,7 @@ use std::path::{Path, PathBuf};
4use std::sync::Arc;
4use std::sync::Arc;
5
5
6use helix_core::{
6use helix_core::{
7− syntax::LOADER, ChangeSet, Diagnostic, History, Position, Range, Rope, RopeSlice, Selection,
7+ syntax::LOADER, ChangeSet, Diagnostic, History, Rope, Selection, State, Syntax, Transaction,
8− State, Syntax, Transaction,
9};
8};
10
9
11#[derive(Copy, Clone, PartialEq, Eq, Hash)]
10#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@@ -55,7 +54,6 @@ where
55 }
54 }
56}
55}
57
56
58−use futures_util::TryFutureExt;
59use helix_lsp::lsp;
57use helix_lsp::lsp;
60use url::Url;
58use url::Url;
61
59
@@ -176,7 +174,7 @@ impl Document {
176 if !transaction.changes().is_empty() {
174 if !transaction.changes().is_empty() {
177 // Compose this transaction with the previous one
175 // Compose this transaction with the previous one
178 take_with(&mut self.changes, |changes| {
176 take_with(&mut self.changes, |changes| {
179− changes.compose(transaction.changes().clone()).unwrap()
177+ changes.compose(transaction.changes().clone())
180 });
178 });
181
179
182 // TODO: when composing, replace transaction.selection too
180 // TODO: when composing, replace transaction.selection too
@@ -219,6 +217,8 @@ impl Document {
219 .unwrap();
217 .unwrap();
220 }
218 }
221
219
220+ // TODO: undo / redo need to emit changes to lsp
221+
222 // reset changeset to fix len
222 // reset changeset to fix len
223 self.changes = ChangeSet::new(self.text());
223 self.changes = ChangeSet::new(self.text());
224
224