|
|
@ -2,6 +2,8 @@ mod transport;
|
|
|
|
|
|
|
|
|
|
|
|
use transport::{Payload, Transport};
|
|
|
|
use transport::{Payload, Transport};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use helix_core::{State, Transaction};
|
|
|
|
|
|
|
|
|
|
|
|
// use std::collections::HashMap;
|
|
|
|
// use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
|
|
use jsonrpc_core as jsonrpc;
|
|
|
|
use jsonrpc_core as jsonrpc;
|
|
|
@ -13,14 +15,24 @@ use serde::{Deserialize, Serialize};
|
|
|
|
pub use lsp::Position;
|
|
|
|
pub use lsp::Position;
|
|
|
|
pub use lsp::Url;
|
|
|
|
pub use lsp::Url;
|
|
|
|
|
|
|
|
|
|
|
|
use smol::prelude::*;
|
|
|
|
|
|
|
|
use smol::{
|
|
|
|
use smol::{
|
|
|
|
channel::{Receiver, Sender},
|
|
|
|
channel::{Receiver, Sender},
|
|
|
|
io::{BufReader, BufWriter},
|
|
|
|
io::{BufReader, BufWriter},
|
|
|
|
|
|
|
|
// prelude::*,
|
|
|
|
process::{Child, ChildStderr, Command, Stdio},
|
|
|
|
process::{Child, ChildStderr, Command, Stdio},
|
|
|
|
Executor,
|
|
|
|
Executor,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub mod util {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn lsp_pos_to_pos(doc: &helix_core::RopeSlice, pos: lsp::Position) -> usize {
|
|
|
|
|
|
|
|
let line = doc.line_to_char(pos.line as usize);
|
|
|
|
|
|
|
|
let line_start = doc.char_to_utf16_cu(line);
|
|
|
|
|
|
|
|
doc.utf16_cu_to_char(pos.character as usize + line_start)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A type representing all possible values sent from the server to the client.
|
|
|
|
/// A type representing all possible values sent from the server to the client.
|
|
|
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
|
|
|
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
@ -58,7 +70,7 @@ impl Notification {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Client {
|
|
|
|
pub struct Client {
|
|
|
|
process: Child,
|
|
|
|
_process: Child,
|
|
|
|
stderr: BufReader<ChildStderr>,
|
|
|
|
stderr: BufReader<ChildStderr>,
|
|
|
|
|
|
|
|
|
|
|
|
outgoing: Sender<Payload>,
|
|
|
|
outgoing: Sender<Payload>,
|
|
|
@ -90,7 +102,7 @@ impl Client {
|
|
|
|
let (incoming, outgoing) = Transport::start(ex, reader, writer);
|
|
|
|
let (incoming, outgoing) = Transport::start(ex, reader, writer);
|
|
|
|
|
|
|
|
|
|
|
|
Client {
|
|
|
|
Client {
|
|
|
|
process,
|
|
|
|
_process: process,
|
|
|
|
stderr,
|
|
|
|
stderr,
|
|
|
|
|
|
|
|
|
|
|
|
outgoing,
|
|
|
|
outgoing,
|
|
|
@ -224,15 +236,12 @@ impl Client {
|
|
|
|
// Text document
|
|
|
|
// Text document
|
|
|
|
// -------------------------------------------------------------------------------------------
|
|
|
|
// -------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn text_document_did_open(
|
|
|
|
pub async fn text_document_did_open(&mut self, state: &State) -> anyhow::Result<()> {
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
state: &helix_core::State,
|
|
|
|
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
|
|
|
|
self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
|
|
|
|
self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
|
|
|
|
text_document: lsp::TextDocumentItem {
|
|
|
|
text_document: lsp::TextDocumentItem {
|
|
|
|
uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
|
|
|
|
uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
|
|
|
|
language_id: "rust".to_string(), // TODO: hardcoded for now
|
|
|
|
language_id: "rust".to_string(), // TODO: hardcoded for now
|
|
|
|
version: 0,
|
|
|
|
version: state.version,
|
|
|
|
text: String::from(&state.doc),
|
|
|
|
text: String::from(&state.doc),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -242,14 +251,15 @@ impl Client {
|
|
|
|
// TODO: trigger any time history.commit_revision happens
|
|
|
|
// TODO: trigger any time history.commit_revision happens
|
|
|
|
pub async fn text_document_did_change(
|
|
|
|
pub async fn text_document_did_change(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
state: &helix_core::State,
|
|
|
|
state: &State,
|
|
|
|
|
|
|
|
transaction: &Transaction,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
|
|
|
|
self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
|
|
|
|
text_document: lsp::VersionedTextDocumentIdentifier::new(
|
|
|
|
text_document: lsp::VersionedTextDocumentIdentifier::new(
|
|
|
|
lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
|
|
|
|
lsp::Url::from_file_path(state.path().unwrap()).unwrap(),
|
|
|
|
0, // TODO: version
|
|
|
|
state.version,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
content_changes: vec![], // TODO:
|
|
|
|
content_changes: vec![], // TODO: probably need old_state here too?
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|