forked from rome/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rome_bin): merge the CLI and Language Server (rome#3044)
* refactor(rome_bin): merge the CLI and Language Server * address PR review * rename `run_cli` to `CliSession::run` * fix CI * address PR review * improve the printing of transport errors
- Loading branch information
1 parent
cbe0477
commit c882f06
Showing
51 changed files
with
1,589 additions
and
821 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "rome_bin" | ||
version = "0.0.0" | ||
edition = "2021" | ||
authors = ["Rome Tools Developers and Contributors"] | ||
license = "MIT" | ||
repository = "https://github.com/rome/tools" | ||
description = "Rome's main binary distribution" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[[bin]] | ||
name = "rome" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
rome_cli = { path = "../rome_cli" } | ||
rome_lsp = { path = "../rome_lsp" } | ||
rome_service = { path = "../rome_service" } | ||
|
||
tokio = { version = "1.15.0", features = ["io-std", "io-util", "net", "time", "rt", "rt-multi-thread"] } | ||
tower-lsp = { version = "0.17.0" } | ||
anyhow = "1.0.52" | ||
|
||
tracing = { version = "0.1.31", default-features = false, features = ["std"] } | ||
tracing-tree = "0.2.0" | ||
tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } | ||
tracing-appender = "0.2" | ||
|
||
[target.'cfg(unix)'.dependencies] | ||
libc = "0.2.127" | ||
tokio = { version = "1.15.0", features = ["io-std", "io-util", "net", "time", "process", "rt", "rt-multi-thread", "macros"] } | ||
|
||
[target.'cfg(windows)'.dependencies] | ||
mimalloc = "0.1.29" |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `rome_bin` | ||
|
||
Rome's main binary distribution, exposes the command line interface defined in | ||
`rome_cli`, and the language server interface defined in `rome_lsp` and used by | ||
the `rome` VSCode extension | ||
|
||
# Logs | ||
|
||
When the server is run in daemon mode, it will output logs to a file created in | ||
a `rome-logs` directory inside the system temporary directory. The log file | ||
will be rotated on a hourly basis. |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use rome_cli::{setup_panic_handler, Arguments, CliSession, Termination}; | ||
use rome_service::workspace; | ||
use tokio::runtime::Runtime; | ||
|
||
use crate::service::open_transport; | ||
|
||
pub fn run_cli_session(args: Arguments) -> Result<(), Termination> { | ||
setup_panic_handler(); | ||
|
||
// Try to open a connection to an existing Rome server socket, or create an | ||
// in-process Workspace server instance if no daemon process is found | ||
let runtime = Runtime::new()?; | ||
let workspace = match open_transport(runtime)? { | ||
Some(transport) => workspace::client(transport)?, | ||
None => workspace::server(), | ||
}; | ||
|
||
CliSession::new(&*workspace, args).run() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![doc = include_str!("../README.md")] | ||
|
||
mod cli; | ||
mod server; | ||
mod service; | ||
|
||
pub use cli::run_cli_session; | ||
pub use server::{print_server_socket, run_server_session}; | ||
pub use service::SocketTransport; |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! This is the main binary of Rome. | ||
//! | ||
//! If you're curios about how to use it, check Rome's [website] | ||
//! | ||
//! [website]: https://rome.tools | ||
use cli::run_cli_session; | ||
use rome_cli::{Arguments, Termination}; | ||
use server::{print_server_socket, run_server_session}; | ||
|
||
mod cli; | ||
mod server; | ||
mod service; | ||
|
||
#[cfg(target_os = "windows")] | ||
#[global_allocator] | ||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; | ||
|
||
fn main() -> Result<(), Termination> { | ||
let mut args = Arguments::from_env(); | ||
|
||
if args.contains("__print_socket") { | ||
print_server_socket() | ||
} else if args.contains("__run_server") { | ||
run_server_session() | ||
} else { | ||
run_cli_session(args) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::env; | ||
|
||
use rome_cli::Termination; | ||
use rome_lsp::ServerFactory; | ||
use tokio::runtime::Runtime; | ||
use tracing::{debug_span, Instrument}; | ||
use tracing_subscriber::{prelude::*, registry, EnvFilter, Layer}; | ||
use tracing_tree::HierarchicalLayer; | ||
|
||
use crate::service::{print_socket, run_daemon}; | ||
|
||
pub fn run_server_session() -> Result<(), Termination> { | ||
setup_tracing_subscriber(); | ||
|
||
let rt = Runtime::new()?; | ||
let factory = ServerFactory::default(); | ||
let span = debug_span!("Running Server", pid = std::process::id()); | ||
rt.block_on(run_daemon(factory).instrument(span))?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn print_server_socket() -> Result<(), Termination> { | ||
let rt = Runtime::new()?; | ||
rt.block_on(print_socket())?; | ||
Ok(()) | ||
} | ||
|
||
/// Setup the [tracing]-based logging system for the server | ||
/// The events received by the subscriber are filtered at the `info` level, | ||
/// then printed using the [HierarchicalLayer] layer, and the resulting text | ||
/// is written to log files rotated on a hourly basis (in | ||
/// `rome-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary | ||
/// directory) | ||
fn setup_tracing_subscriber() { | ||
/// This filter enables: | ||
/// - All spans and events at level info or higher | ||
/// - All spans and events in the `rome_lsp` and `rome_js_parser` crates | ||
const LOGGING_FILTER: &str = "info,rome_lsp=trace,rome_js_parser=trace"; | ||
|
||
let logs_dir = env::temp_dir().join("rome-logs"); | ||
let file_appender = tracing_appender::rolling::hourly(logs_dir, "server.log"); | ||
|
||
registry() | ||
.with( | ||
HierarchicalLayer::default() | ||
.with_indent_lines(true) | ||
.with_indent_amount(2) | ||
.with_bracketed_fields(true) | ||
.with_targets(true) | ||
.with_ansi(false) | ||
.with_writer(file_appender) | ||
.with_filter(EnvFilter::new(LOGGING_FILTER)), | ||
) | ||
.init(); | ||
} |
Oops, something went wrong.