gluon_language_server/
lib.rs1#[macro_use]
2extern crate serde_derive;
3
4#[macro_use]
5extern crate log;
6
7extern crate gluon_completion as completion;
8
9#[macro_use]
10mod server;
11#[macro_use]
12pub mod rpc;
13
14mod check_importer;
15mod command;
16mod diagnostics;
17mod name;
18mod text_edit;
19
20use gluon::either;
21
22use futures::prelude::*;
23
24pub use crate::{command::completion::CompletionData, server::Server};
25
26pub type BoxFuture<I, E> = std::pin::Pin<Box<dyn Future<Output = Result<I, E>> + Send + 'static>>;
27
28pub async fn run() -> Result<(), anyhow::Error> {
29 ::env_logger::init();
30
31 let _matches = clap::App::new("debugger")
32 .version(env!("CARGO_PKG_VERSION"))
33 .get_matches();
34
35 let thread = gluon::new_vm_async().await;
36 Server::start(thread, tokio::io::stdin(), tokio::io::stdout()).await?;
37 Ok(())
38}
39
40async fn cancelable<T, F, G>(f: F, g: G) -> T
41where
42 F: Future<Output = T>,
43 G: Future<Output = T>,
44{
45 futures::pin_mut!(f);
46 futures::pin_mut!(g);
47 futures::future::select(f, g).await.factor_first().0
48}
49
50use gluon::base::{
51 pos::{ByteIndex, ByteOffset, Span},
52 source::FileMap,
53};
54
55fn position_to_byte_index(
56 files: &FileMap,
57 position: &lsp_types::Position,
58) -> Result<ByteIndex, codespan_reporting::files::Error> {
59 let index = codespan_lsp::position_to_byte_index(files, (), position)?;
60
61 Ok(files.span().start() + ByteOffset::from(index as i64))
62}
63
64fn byte_span_to_range(
65 files: &FileMap,
66 span: Span<ByteIndex>,
67) -> Result<lsp_types::Range, codespan_reporting::files::Error> {
68 let start = files.span().start().to_usize();
69 let range = span.start().to_usize() - start..span.end().to_usize() - start;
70 codespan_lsp::byte_span_to_range(files, (), range)
71}