-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- refactor(rime): global rime instance with once_cell - feat: support serving remote LSP client via TCP
- Loading branch information
Showing
6 changed files
with
80 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,48 @@ | ||
use std::{net::SocketAddr, str::FromStr}; | ||
|
||
use rime_ls::lsp::Backend; | ||
use tokio::net::{TcpListener, TcpStream}; | ||
use tower_lsp::{LspService, Server}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let (service, socket) = LspService::build(Backend::new).finish(); | ||
async fn run_stdio() { | ||
let stdin = tokio::io::stdin(); | ||
let stdout = tokio::io::stdout(); | ||
|
||
let (service, socket) = LspService::build(Backend::new).finish(); | ||
Server::new(stdin, stdout, socket).serve(service).await; | ||
} | ||
|
||
async fn run_tcp(stream: TcpStream) { | ||
let (read, write) = tokio::io::split(stream); | ||
|
||
let (service, socket) = LspService::build(Backend::new).finish(); | ||
Server::new(read, write, socket).serve(service).await; | ||
} | ||
|
||
async fn run_tcp_forever(bind_addr: SocketAddr) -> tokio::io::Result<()> { | ||
println!("Listening on: {}", &bind_addr); | ||
let listener = TcpListener::bind(bind_addr).await?; | ||
loop { | ||
let (stream, _) = listener.accept().await?; | ||
tokio::spawn(run_tcp(stream)); | ||
} | ||
} | ||
|
||
fn usage() { | ||
println!("rime_ls v{}", env!("CARGO_PKG_VERSION")); | ||
println!("Usage: rime_ls [--listen <bind_addr>]") | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut args = std::env::args(); | ||
match args.nth(1).as_deref() { | ||
None => run_stdio().await, | ||
Some("--listen") => { | ||
let addr = args.next().unwrap_or("127.0.0.1:9257".to_owned()); | ||
let addr = SocketAddr::from_str(&addr).unwrap(); | ||
run_tcp_forever(addr).await.unwrap(); | ||
} | ||
_ => usage(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters