Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/rust-analyzer/src/bin/mod.rs (renamed from crates/rust-analyzer/src/bin/main.rs)47
-rw-r--r--crates/rust-analyzer/src/lib.rs2
-rw-r--r--lib/lsp-server/src/stdio.rs10
3 files changed, 24 insertions, 35 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/mod.rs
index 44c442ffd8..607b856828 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/mod.rs
@@ -12,14 +12,14 @@ mod rustc_wrapper;
use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc};
-use anyhow::Context;
-use lsp_server::Connection;
-use paths::Utf8PathBuf;
-use rust_analyzer::{
+use crate::{
cli::flags,
config::{Config, ConfigChange, ConfigErrors},
from_json,
};
+use anyhow::Context;
+use lsp_server::Connection;
+use paths::Utf8PathBuf;
use tracing_subscriber::fmt::writer::BoxMakeWriter;
use vfs::AbsPathBuf;
@@ -60,7 +60,7 @@ fn actual_main() -> anyhow::Result<ExitCode> {
break 'lsp_server;
}
if cmd.version {
- println!("rust-analyzer {}", rust_analyzer::version());
+ println!("rust-analyzer {}", crate::version());
break 'lsp_server;
}
@@ -68,11 +68,11 @@ fn actual_main() -> anyhow::Result<ExitCode> {
// a secondary latency-sensitive thread with an increased stack size.
// We use this thread intent because any delay in the main loop
// will make actions like hitting enter in the editor slow.
- with_extra_thread(
- "LspServer",
- stdx::thread::ThreadIntent::LatencySensitive,
- run_server,
- )?;
+ // with_extra_thread(
+ // "LspServer",
+ // stdx::thread::ThreadIntent::LatencySensitive,
+ // run_server,
+ // )?;
}
flags::RustAnalyzerCmd::Parse(cmd) => cmd.run()?,
flags::RustAnalyzerCmd::Symbols(cmd) => cmd.run()?,
@@ -158,7 +158,7 @@ fn setup_logging(log_file_flag: Option<PathBuf>) -> anyhow::Result<()> {
None => BoxMakeWriter::new(std::io::stderr),
};
- rust_analyzer::tracing::Config {
+ crate::tracing::Config {
writer,
// Deliberately enable all `warn` logs if the user has not set RA_LOG, as there is usually
// useful information in there for debugging.
@@ -190,17 +190,13 @@ fn with_extra_thread(
Ok(())
}
-fn run_server() -> anyhow::Result<()> {
- tracing::info!("server version {} will start", rust_analyzer::version());
-
- let (connection, io_threads) = Connection::stdio();
+pub fn run_server(connection: Connection) -> anyhow::Result<()> {
+ tracing::info!("server version {} will start", crate::version());
let (initialize_id, initialize_params) = match connection.initialize_start() {
Ok(it) => it,
Err(e) => {
- if e.channel_is_disconnected() {
- io_threads.join()?;
- }
+ if e.channel_is_disconnected() {}
return Err(e.into());
}
};
@@ -280,13 +276,13 @@ fn run_server() -> anyhow::Result<()> {
}
}
- let server_capabilities = rust_analyzer::server_capabilities(&config);
+ let server_capabilities = crate::server_capabilities(&config);
let initialize_result = lsp_types::InitializeResult {
capabilities: server_capabilities,
server_info: Some(lsp_types::ServerInfo {
name: String::from("rust-analyzer"),
- version: Some(rust_analyzer::version().to_string()),
+ version: Some(crate::version().to_string()),
}),
offset_encoding: None,
};
@@ -294,9 +290,7 @@ fn run_server() -> anyhow::Result<()> {
let initialize_result = serde_json::to_value(initialize_result).unwrap();
if let Err(e) = connection.initialize_finish(initialize_id, initialize_result) {
- if e.channel_is_disconnected() {
- io_threads.join()?;
- }
+ if e.channel_is_disconnected() {}
return Err(e.into());
}
@@ -314,12 +308,7 @@ fn run_server() -> anyhow::Result<()> {
// If the io_threads have an error, there's usually an error on the main
// loop too because the channels are closed. Ensure we report both errors.
- match (rust_analyzer::main_loop(config, connection), io_threads.join()) {
- (Err(loop_e), Err(join_e)) => anyhow::bail!("{loop_e}\n{join_e}"),
- (Ok(_), Err(join_e)) => anyhow::bail!("{join_e}"),
- (Err(loop_e), Ok(_)) => anyhow::bail!("{loop_e}"),
- (Ok(_), Ok(_)) => {}
- }
+ crate::main_loop(config, connection)?;
tracing::info!("server did shut down");
Ok(())
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index 4a37bb34ab..5152d3c754 100644
--- a/crates/rust-analyzer/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -28,8 +28,8 @@ pub const MINIMUM_SUPPORTED_TOOLCHAIN_VERSION: semver::Version = semver::Version
build: semver::BuildMetadata::EMPTY,
};
+pub mod bin;
pub mod cli;
-
mod command;
mod diagnostics;
mod discover;
diff --git a/lib/lsp-server/src/stdio.rs b/lib/lsp-server/src/stdio.rs
index 55b2f7b223..d14d8ee55d 100644
--- a/lib/lsp-server/src/stdio.rs
+++ b/lib/lsp-server/src/stdio.rs
@@ -3,7 +3,7 @@ use std::{
thread,
};
-use log::debug;
+use log::{debug, trace};
use crossbeam_channel::{Receiver, Sender, bounded, unbounded};
@@ -15,11 +15,11 @@ pub fn stdio_transport(
) -> (Sender<Message>, Receiver<Message>, IoThreads) {
let (writer_sender, writer_receiver) = unbounded::<Message>();
let writer = thread::Builder::new()
- .name("LspServerWriter".to_owned())
+ .name("send to lsp".to_owned())
.spawn(move || {
loop {
let it = writer_receiver.recv().unwrap();
- debug!("sent message {it:#?}");
+ trace!("sent message {it:#?}");
let result = it.write(&mut write_to).unwrap();
result
}
@@ -27,11 +27,11 @@ pub fn stdio_transport(
.unwrap();
let (reader_sender, reader_receiver) = bounded::<Message>(0);
let reader: thread::JoinHandle<Result<(), io::Error>> = thread::Builder::new()
- .name("LspServerReader".to_owned())
+ .name("read from lsp".to_owned())
.spawn(move || {
while let Some(msg) = Message::read(&mut read_from)? {
let is_exit = matches!(&msg, Message::Notification(n) if n.is_exit());
- debug!("received message {msg:#?}");
+ trace!("received message {msg:#?}");
if let Err(e) = reader_sender.send(msg) {
return Err(io::Error::other(e));
}