on master help sign in
state.version tracking
ef5e5f9Blaž Hrastnik
helix-core/src/state.rs+2
@@ -29,6 +29,7 @@ pub struct State {
29 pub changes: ChangeSet,
29 pub changes: ChangeSet,
30 pub old_state: Option<(Rope, Selection)>,
30 pub old_state: Option<(Rope, Selection)>,
31
31
32+ pub version: i64,
32 pub diagnostics: Vec<Diagnostic>,
33 pub diagnostics: Vec<Diagnostic>,
33}
34}
34
35
@@ -61,6 +62,7 @@ impl State {
61 changes,
62 changes,
62 old_state,
63 old_state,
63 diagnostics: Vec::new(),
64 diagnostics: Vec::new(),
65+ version: 0,
64 }
66 }
65 }
67 }
66
68
helix-lsp/src/lib.rs+21−11
@@ -2,6 +2,8 @@ mod transport;
2
2
3use transport::{Payload, Transport};
3use transport::{Payload, Transport};
4
4
5+use helix_core::{State, Transaction};
6+
5// use std::collections::HashMap;
7// use std::collections::HashMap;
6
8
7use jsonrpc_core as jsonrpc;
9use jsonrpc_core as jsonrpc;
@@ -13,14 +15,24 @@ use serde::{Deserialize, Serialize};
13pub use lsp::Position;
15pub use lsp::Position;
14pub use lsp::Url;
16pub use lsp::Url;
15
17
16−use smol::prelude::*;
17use smol::{
18use smol::{
18 channel::{Receiver, Sender},
19 channel::{Receiver, Sender},
19 io::{BufReader, BufWriter},
20 io::{BufReader, BufWriter},
21+ // prelude::*,
20 process::{Child, ChildStderr, Command, Stdio},
22 process::{Child, ChildStderr, Command, Stdio},
21 Executor,
23 Executor,
22};
24};
23
25
26+pub mod util {
27+ use super::*;
28+
29+ pub fn lsp_pos_to_pos(doc: &helix_core::RopeSlice, pos: lsp::Position) -> usize {
30+ let line = doc.line_to_char(pos.line as usize);
31+ let line_start = doc.char_to_utf16_cu(line);
32+ doc.utf16_cu_to_char(pos.character as usize + line_start)
33+ }
34+}
35+
24/// A type representing all possible values sent from the server to the client.
36/// A type representing all possible values sent from the server to the client.
25#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
37#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
26#[serde(deny_unknown_fields)]
38#[serde(deny_unknown_fields)]
@@ -58,7 +70,7 @@ impl Notification {
58}
70}
59
71
60pub struct Client {
72pub struct Client {
61− process: Child,
73+ _process: Child,
62 stderr: BufReader<ChildStderr>,
74 stderr: BufReader<ChildStderr>,
63
75
64 outgoing: Sender<Payload>,
76 outgoing: Sender<Payload>,
@@ -90,7 +102,7 @@ impl Client {
90 let (incoming, outgoing) = Transport::start(ex, reader, writer);
102 let (incoming, outgoing) = Transport::start(ex, reader, writer);
91
103
92 Client {
104 Client {
93− process,
105+ _process: process,
94 stderr,
106 stderr,
95
107
96 outgoing,
108 outgoing,
@@ -224,15 +236,12 @@ impl Client {
224 // Text document
236 // Text document
225 // -------------------------------------------------------------------------------------------
237 // -------------------------------------------------------------------------------------------
226
238
227− pub async fn text_document_did_open(
239+ pub async fn text_document_did_open(&mut self, state: &State) -> anyhow::Result<()> {
228− &mut self,
229− state: &helix_core::State,
230− ) -> anyhow::Result<()> {
231 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
240 self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
232 text_document: lsp::TextDocumentItem {
241 text_document: lsp::TextDocumentItem {
233 uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
242 uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
234 language_id: "rust".to_string(), // TODO: hardcoded for now
243 language_id: "rust".to_string(), // TODO: hardcoded for now
235− version: 0,
244+ version: state.version,
236 text: String::from(&state.doc),
245 text: String::from(&state.doc),
237 },
246 },
238 })
247 })
@@ -242,14 +251,15 @@ impl Client {
242 // TODO: trigger any time history.commit_revision happens
251 // TODO: trigger any time history.commit_revision happens
243 pub async fn text_document_did_change(
252 pub async fn text_document_did_change(
244 &mut self,
253 &mut self,
245− state: &helix_core::State,
254+ state: &State,
255+ transaction: &Transaction,
246 ) -> anyhow::Result<()> {
256 ) -> anyhow::Result<()> {
247 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
257 self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
248 text_document: lsp::VersionedTextDocumentIdentifier::new(
258 text_document: lsp::VersionedTextDocumentIdentifier::new(
249 lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
259 lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
250− 0, // TODO: version
260+ state.version,
251 ),
261 ),
252− content_changes: vec![], // TODO:
262+ content_changes: vec![], // TODO: probably need old_state here too?
253 })
263 })
254 .await
264 .await
255 }
265 }
helix-term/src/application.rs+7−26
@@ -568,23 +568,12 @@ impl<'a> Application<'a> {
568 use helix_lsp::Notification;
568 use helix_lsp::Notification;
569 match notification {
569 match notification {
570 Some(Notification::PublishDiagnostics(params)) => {
570 Some(Notification::PublishDiagnostics(params)) => {
571− let view = self.editor.views.iter_mut().find(|view| {
571+ let path = Some(params.uri.to_file_path().unwrap());
572− let path = view
572+ let view = self
573− .state
573+ .editor
574− .path
574+ .views
575− .as_ref()
575+ .iter_mut()
576− .map(|path| helix_lsp::Url::from_file_path(path).unwrap());
576+ .find(|view| view.state.path == path);
577−
578− eprintln!("{:?} {} {}", path, params.uri, params.diagnostics.len());
579− // HAXX
580− path == Some(params.uri.clone())
581− });
582−
583− fn lsp_pos_to_pos(doc: &helix_core::RopeSlice, pos: helix_lsp::Position) -> usize {
584− let line = doc.line_to_char(pos.line as usize);
585− let line_start = doc.char_to_utf16_cu(line);
586− doc.utf16_cu_to_char(pos.character as usize + line_start)
587− }
588
577
589 if let Some(view) = view {
578 if let Some(view) = view {
590 let doc = view.state.doc().slice(..);
579 let doc = view.state.doc().slice(..);
@@ -592,18 +581,10 @@ impl<'a> Application<'a> {
592 .diagnostics
581 .diagnostics
593 .into_iter()
582 .into_iter()
594 .map(|diagnostic| {
583 .map(|diagnostic| {
584+ use helix_lsp::util::lsp_pos_to_pos;
595 let start = lsp_pos_to_pos(&doc, diagnostic.range.start);
585 let start = lsp_pos_to_pos(&doc, diagnostic.range.start);
596 let end = lsp_pos_to_pos(&doc, diagnostic.range.end);
586 let end = lsp_pos_to_pos(&doc, diagnostic.range.end);
597
587
598− // eprintln!(
599− // "{:?}-{:?} {}-{} {}",
600− // diagnostic.range.start,
601− // diagnostic.range.end,
602− // start,
603− // end,
604− // diagnostic.message
605− // );
606−
607 helix_core::Diagnostic {
588 helix_core::Diagnostic {
608 range: (start, end),
589 range: (start, end),
609 line: diagnostic.range.start.line as usize,
590 line: diagnostic.range.start.line as usize,
helix-view/src/commands.rs+6−1
@@ -391,6 +391,12 @@ fn append_changes_to_history(view: &mut View) {
391 // annotations either add a new layer or compose into the previous one.
391 // annotations either add a new layer or compose into the previous one.
392 let transaction = Transaction::from(changes).with_selection(view.state.selection().clone());
392 let transaction = Transaction::from(changes).with_selection(view.state.selection().clone());
393
393
394+ // increment document version
395+ // TODO: needs to happen on undo/redo too
396+ view.state.version += 1;
397+
398+ // TODO: trigger lsp/documentDidChange with changes
399+
394 // HAXX: we need to reconstruct the state as it was before the changes..
400 // HAXX: we need to reconstruct the state as it was before the changes..
395 let (doc, selection) = view.state.old_state.take().unwrap();
401 let (doc, selection) = view.state.old_state.take().unwrap();
396 let mut old_state = State::new(doc);
402 let mut old_state = State::new(doc);
@@ -399,7 +405,6 @@ fn append_changes_to_history(view: &mut View) {
399 // TODO: take transaction by value?
405 // TODO: take transaction by value?
400 view.history.commit_revision(&transaction, &old_state);
406 view.history.commit_revision(&transaction, &old_state);
401
407
402− // TODO: need to start the state with these vals
403 // HAXX
408 // HAXX
404 view.state.old_state = Some((view.state.doc().clone(), view.state.selection.clone()));
409 view.state.old_state = Some((view.state.doc().clone(), view.state.selection.clone()));
405}
410}