Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into no-dupe-keys
Browse files Browse the repository at this point in the history
* upstream/main:
  fix(npm/js-api): Import type from @rometools/backend-jsonrpc (rome#3647)
  doc(npm/js-api): Add experimental warning to README
  fix(npm/js-api): Lazy load backend implementations (rome#3652)
  feat(rome_lsp): stop the daemon after the last client disconnects (rome#3643)
  fix(npm/js_api): Ensure JS API build contains `dist` folder (rome#3648)
  fix(rome_cli): ensures the service only connects to compatible versions (rome#3642)
  feat(playground): add settings button and group IR (rome#3559)
  release: v10.0.1 (rome#3649)
  fix(rome_js_analyze): False positives for interactive elements in `useKeyWithClickEvents` (rome#3644)
  fix(rome_js_semantic): support for object and array bindings when exporting (rome#3620)
  doc(editors): Clarify Rome discovery (rome#3639)
  fix(rome_js_analyze): improve the detection of `ReactDOM.render` calls in `noRenderReturnValue` (rome#3626)
  chore(npm): add license (rome#3629)
  Add rustdocs index
  Add environment
  Change rust docs to use Netlify
  fix(rome_js_analyze): useValidAnchor considering all possible expressions (rome#3599)
  fix(rome_js_formatter): Trailing comma inside import rome#3600 (rome#3624)
  • Loading branch information
jeysal committed Nov 10, 2022
2 parents 1fc7282 + 84c53d4 commit 62c5af4
Show file tree
Hide file tree
Showing 59 changed files with 1,362 additions and 811 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_playground_on_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:

- name: Publish
run: |
netlify deploy --dir=website/playground/dist --prod --site playground-rometools --auth ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify deploy --dir=website/playground/dist --prod --site playground-rometools --auth ${{ secrets.NETLIFY_AUTH_TOKEN }}
13 changes: 9 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ jobs:

documentation:
name: Documentation
environment: netlify-rustdocs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install netlify-cli
run: npm i -g netlify-cli
- name: Install toolchain
run: rustup show
- name: Cache
Expand All @@ -105,11 +108,13 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: documentation
- name: Write index.html
run: echo '<meta http-equiv="refresh" content="0; url=/rome/index.html">' >target/doc/index.html
- name: Write _redirects
run: echo '/ /rome/index.html' >target/doc/_redirects
- name: Deploy documentation
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
run: |
netlify deploy --dir=./target/doc --prod --site rustdocs-rometools --auth ${{ secrets.NETLIFY_AUTH_TOKEN }}
coverage:
name: Test262 Coverage
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_js_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
working-directory: npm/js-api
run: |
pnpm i
pnpm build
pnpm build
- name: Upload JS API artifact
uses: actions/upload-artifact@v3
Expand All @@ -126,7 +126,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: js-api
path: npm
path: npm/js-api/dist

- name: Install Node.js
uses: actions/setup-node@v3
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Rome changelog

## 10.0.1

### CLI

- Respect the formatter / linter `enabled` flag from configuration ([#3591](https://github.com/rome/tools/issues/3591))
- Correctly account for diff diagnostics in the printed diagnostics count ([#3595](https://github.com/rome/tools/issues/3595))

### Formatter

- Do not insert a trailing comma in import expressions ([#3600](https://github.com/rome/tools/issues/3600))

### Linter

- Fixed false positives in `noUselessFragments`, `noArrayIndexKey`, `noChildrenProp`, `noUselessFragments`, `noVoidElementsWithChildren`, `noDangerouslySetInnerHtml`, `noDangerouslySetInnerHtmlWithChildren`, `useValidAnchor`, `noRenderReturnValue`, `noUnusedVariables` and `useKeyWithClickEvents`
([#3592](https://github.com/rome/tools/pull/3592), [#3619](https://github.com/rome/tools/pull/3619), [#3599](https://github.com/rome/tools/pull/3599), [#3626](https://github.com/rome/tools/pull/3626), [#3620](https://github.com/rome/tools/pull/3620) & [#3644](https://github.com/rome/tools/pull/3644))

### Editors

- Display the version of the language server in the status bar ([#3616](https://github.com/rome/tools/issues/3616))

## 10.0.0

### CLI
Expand Down
10 changes: 6 additions & 4 deletions crates/rome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{

pub(crate) fn start(mut session: CliSession) -> Result<(), Termination> {
let rt = Runtime::new()?;
let did_spawn = rt.block_on(ensure_daemon())?;
let did_spawn = rt.block_on(ensure_daemon(false))?;

if did_spawn {
session.app.console.log(markup! {
Expand Down Expand Up @@ -60,11 +60,13 @@ pub(crate) fn stop(mut session: CliSession) -> Result<(), Termination> {
Ok(())
}

pub(crate) fn run_server() -> Result<(), Termination> {
pub(crate) fn run_server(mut session: CliSession) -> Result<(), Termination> {
setup_tracing_subscriber();

let stop_on_disconnect = session.args.contains("--stop-on-disconnect");

let rt = Runtime::new()?;
let factory = ServerFactory::default();
let factory = ServerFactory::new(stop_on_disconnect);
let cancellation = factory.cancellation();
let span = debug_span!("Running Server", pid = std::process::id());

Expand Down Expand Up @@ -101,7 +103,7 @@ pub(crate) fn lsp_proxy() -> Result<(), Termination> {
/// Receives a process via `stdin` and then copy the content to the LSP socket.
/// Copy to the process on `stdout` when the LSP responds to a message
async fn start_lsp_proxy(rt: &Runtime) -> Result<(), Termination> {
ensure_daemon().await?;
ensure_daemon(true).await?;

match open_socket().await? {
Some((mut owned_read_half, mut owned_write_half)) => {
Expand Down
74 changes: 54 additions & 20 deletions crates/rome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{env, io, ops::Deref};
use tokio::runtime::Runtime;

use crate::commands::daemon::read_most_recent_log_file;
use crate::service::enumerate_pipes;
use crate::{service, CliSession, Termination, VERSION};

/// Handler for the `rage` command
Expand Down Expand Up @@ -85,38 +86,71 @@ struct RunningRomeServer;

impl Display for RunningRomeServer {
fn fmt(&self, f: &mut Formatter) -> io::Result<()> {
let runtime = Runtime::new()?;

match service::open_transport(runtime) {
Ok(None) => {
return markup!(
{Section("Server")}
{KeyValuePair("Status", markup!(<Dim>"stopped"</Dim>))}
)
.fmt(f);
let versions = match enumerate_pipes() {
Ok(iter) => iter,
Err(err) => {
(markup! {<Error>"\u{2716} Enumerating Rome instances failed:"</Error>}).fmt(f)?;
return writeln!(f, " {err}");
}
Ok(Some(transport)) => {
markup!("\n"<Emphasis>"Running Rome Server:"</Emphasis>" "{HorizontalLine::new(78)}"
};

for version in versions {
if version == rome_service::VERSION {
let runtime = Runtime::new()?;
match service::open_transport(runtime) {
Ok(None) => {
markup!(
{Section("Server")}
{KeyValuePair("Status", markup!(<Dim>"stopped"</Dim>))}
)
.fmt(f)?;
continue;
}
Ok(Some(transport)) => {
markup!("\n"<Emphasis>"Running Rome Server:"</Emphasis>" "{HorizontalLine::new(78)}"
"<Info>"\u{2139} The client isn't connected to any server but rage discovered this running Rome server."</Info>"
")
.fmt(f)?;

match client(transport) {
Ok(client) => WorkspaceRage(client.deref()).fmt(f)?,
match client(transport) {
Ok(client) => WorkspaceRage(client.deref()).fmt(f)?,
Err(err) => {
markup!(<Error>"\u{2716} Failed to connect: "</Error>).fmt(f)?;
writeln!(f, "{err}")?;
}
}
}
Err(err) => {
markup!(<Error>"\u{2716} Failed to connect: "</Error>).fmt(f)?;
markup!("\n"<Error>"\u{2716} Failed to connect: "</Error>).fmt(f)?;
writeln!(f, "{err}")?;
}
}

RomeServerLog.fmt(f)?;
} else {
markup!("\n"<Emphasis>"Incompatible Rome Server:"</Emphasis>" "{HorizontalLine::new(78)}"
"<Info>"\u{2139} Rage discovered this running server using an incompatible version of Rome."</Info>"
")
.fmt(f)?;

// Version 10.0.0 and below did not include a service version in the pipe name
let version = if version.is_empty() {
"<=10.0.0"
} else {
version.as_str()
};

markup!(
{Section("Server")}
{KeyValuePair("Version", markup!({version}))}
)
.fmt(f)?;
}
Err(err) => {
markup!("\n"<Error>"\u{2716} Failed to connect: "</Error>).fmt(f)?;
writeln!(f, "{err}")?;
}
};
}

RomeServerLog.fmt(f)
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'app> CliSession<'app> {
Some("lsp-proxy") => commands::daemon::lsp_proxy(),

// Internal commands
Some("__run_server") => commands::daemon::run_server(),
Some("__run_server") => commands::daemon::run_server(self),
Some("__print_socket") => commands::daemon::print_socket(),

// Print the help for known commands called without any arguments, and exit with an error
Expand Down
10 changes: 6 additions & 4 deletions crates/rome_cli/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ use tokio::{
#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub(crate) use self::windows::{ensure_daemon, open_socket, print_socket, run_daemon};
pub(crate) use self::windows::{
ensure_daemon, enumerate_pipes, open_socket, print_socket, run_daemon,
};

#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub(crate) use self::unix::open_socket;
#[cfg(unix)]
pub(crate) use self::unix::{ensure_daemon, print_socket, run_daemon};
pub(crate) use self::unix::{
ensure_daemon, enumerate_pipes, open_socket, print_socket, run_daemon,
};

/// Tries to open a connection to a running daemon instance, returning a
/// [WorkspaceTransport] instance if the socket is currently active
Expand Down
31 changes: 26 additions & 5 deletions crates/rome_cli/src/service/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ use tracing::Instrument;
/// Returns the filesystem path of the global socket used to communicate with
/// the server daemon
fn get_socket_name() -> PathBuf {
env::temp_dir().join("rome-socket")
env::temp_dir().join(format!("rome-socket-{}", rome_service::VERSION))
}

pub(crate) fn enumerate_pipes() -> io::Result<impl Iterator<Item = String>> {
fs::read_dir(env::temp_dir()).map(|iter| {
iter.filter_map(|entry| {
let entry = entry.ok()?.path();
let file_name = entry.file_name()?;
let file_name = file_name.to_str()?;

let rome_version = file_name.strip_prefix("rome-socket")?;
if rome_version.is_empty() {
Some(String::new())
} else {
Some(rome_version.strip_prefix('-')?.to_string())
}
})
})
}

/// Try to connect to the global socket and wait for the connection to become ready
Expand All @@ -34,12 +51,16 @@ async fn try_connect() -> io::Result<UnixStream> {
}

/// Spawn the daemon server process in the background
fn spawn_daemon() -> io::Result<Child> {
fn spawn_daemon(stop_on_disconnect: bool) -> io::Result<Child> {
let binary = env::current_exe()?;

let mut cmd = Command::new(binary);
cmd.arg("__run_server");

if stop_on_disconnect {
cmd.arg("--stop-on-disconnect");
}

// Create a new session for the process and make it the leader, this will
// ensures that the child process is fully detached from its parent and will
// continue running in the background even after the parent process exits
Expand Down Expand Up @@ -85,7 +106,7 @@ pub(crate) async fn open_socket() -> io::Result<Option<(OwnedReadHalf, OwnedWrit
///
/// Returns false if the daemon process was already running or true if it had
/// to be started
pub(crate) async fn ensure_daemon() -> io::Result<bool> {
pub(crate) async fn ensure_daemon(stop_on_disconnect: bool) -> io::Result<bool> {
let mut current_child: Option<Child> = None;
let mut last_error = None;

Expand Down Expand Up @@ -123,7 +144,7 @@ pub(crate) async fn ensure_daemon() -> io::Result<bool> {
} else {
// Spawn the daemon process and wait a few milliseconds for
// it to become ready then retry the connection
current_child = Some(spawn_daemon()?);
current_child = Some(spawn_daemon(stop_on_disconnect)?);
time::sleep(Duration::from_millis(50)).await;
}
}
Expand All @@ -145,7 +166,7 @@ pub(crate) async fn ensure_daemon() -> io::Result<bool> {
/// Ensure the server daemon is running and ready to receive connections and
/// print the global socket name in the standard output
pub(crate) async fn print_socket() -> io::Result<()> {
ensure_daemon().await?;
ensure_daemon(true).await?;
println!("{}", get_socket_name().display());
Ok(())
}
Expand Down
Loading

0 comments on commit 62c5af4

Please sign in to comment.