Skip to content

Commit

Permalink
Implement workspace watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Feb 25, 2025
1 parent 7b7ef04 commit 864cb7e
Show file tree
Hide file tree
Showing 28 changed files with 655 additions and 122 deletions.
102 changes: 101 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions crates/biome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use crate::{
use biome_console::{markup, ConsoleExt};
use biome_fs::OsFileSystem;
use biome_lsp::ServerFactory;
use biome_service::{workspace::WorkspaceClient, TransportError, WorkspaceError};
use biome_service::{workspace::WorkspaceClient, TransportError, WorkspaceError, WorkspaceWatcher};
use camino::{Utf8Path, Utf8PathBuf};
use crossbeam::channel::unbounded;
use std::{env, fs};
use tokio::io;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -80,8 +81,10 @@ pub(crate) fn run_server(
) -> Result<(), CliDiagnostic> {
setup_tracing_subscriber(log_path.as_deref(), log_file_name_prefix.as_deref());

let (instruction_tx, instruction_rx) = unbounded();

let rt = Runtime::new()?;
let factory = ServerFactory::new(stop_on_disconnect);
let factory = ServerFactory::new(stop_on_disconnect, instruction_tx);
let cancellation = factory.cancellation();
let span = debug_span!("Running Server",
pid = std::process::id(),
Expand All @@ -90,6 +93,12 @@ pub(crate) fn run_server(
log_file_name_prefix = &log_file_name_prefix.as_deref(),
);

let workspace = factory.workspace();
let mut watcher = WorkspaceWatcher::new(instruction_rx)?;
rt.spawn_blocking(move || {
watcher.run(workspace.as_ref());
});

rt.block_on(async move {
tokio::select! {
res = run_daemon(factory, config_path).instrument(span) => {
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ pub(crate) trait CommandRunner: Sized {
let result = workspace.scan_project_folder(ScanProjectFolderParams {
project_key,
path: Some(project_path),
watch: cli_options.use_server,
})?;
for diagnostic in result.diagnostics {
if diagnostic.severity() == Severity::Fatal {
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic>
project_key,
path: biome_path.clone(),
content: FileContent::FromClient(biome_config_content.to_string()),
version: 0,
version: Some(0),
document_file_source: Some(JsonFileSource::json().into()),
persist_node_cache: false,
})?;
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ pub fn execute_mode(
project_key,
content: FileContent::FromClient(content),
path: report_file.clone(),
version: 0,
version: None,
document_file_source: None,
persist_node_cache: false,
})?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'ctx, 'app> WorkspaceFile<'ctx, 'app> {
project_key: ctx.project_key,
document_file_source: None,
path: path.clone(),
version: 0,
version: None,
content: FileContent::FromClient(input.clone()),
persist_node_cache: false,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/src/execute/std_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(crate) fn run<'a>(
workspace.open_file(OpenFileParams {
project_key,
path: biome_path.clone(),
version: 0,
version: None,
content: FileContent::FromClient(content.into()),
document_file_source: None,
persist_node_cache: false,
Expand Down Expand Up @@ -85,7 +85,7 @@ pub(crate) fn run<'a>(
workspace.open_file(OpenFileParams {
project_key,
path: biome_path.clone(),
version: 0,
version: None,
content: FileContent::FromClient(content.into()),
document_file_source: None,
persist_node_cache: false,
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use snap_test::assert_cli_snapshot;

use biome_cli::{biome_command, CliDiagnostic, CliSession};
use biome_console::{markup, BufferConsole, Console, ConsoleExt};
use biome_fs::{FileSystem, MemoryFileSystem};
use biome_fs::{FileSystem, MemoryFileSystem, OsFileSystem};
use biome_service::App;
use bpaf::ParseFailure;

Expand Down Expand Up @@ -359,7 +359,7 @@ pub(crate) fn run_cli_with_dyn_fs(
runtime::Runtime,
};

let factory = ServerFactory::default();
let factory = ServerFactory::new_with_fs(Box::new(OsFileSystem::default()));
let connection = factory.create(None);

let runtime = Runtime::new().expect("failed to create runtime");
Expand Down
12 changes: 12 additions & 0 deletions crates/biome_fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
use std::collections::BTreeSet;
use std::fmt::{Debug, Display, Formatter};
use std::panic::RefUnwindSafe;
use std::path::Path;
use std::sync::Arc;
use std::{fmt, io};
use tracing::{error, info};
Expand Down Expand Up @@ -450,6 +451,17 @@ impl Display for FileSystemDiagnostic {
}
}

impl FileSystemDiagnostic {
pub fn non_utf8_path(path: &Path) -> Self {
Self {
severity: Severity::Error,
path: path.display().to_string(),
error_kind: FsErrorKind::NonUtf8Path,
source: None,
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum FsErrorKind {
/// File not found
Expand Down
1 change: 1 addition & 0 deletions crates/biome_lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ biome_rowan = { workspace = true }
biome_service = { workspace = true }
biome_text_edit = { workspace = true }
camino = { workspace = true }
crossbeam = { workspace = true }
futures = "0.3.31"
papaya = { workspace = true }
rustc-hash = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_lsp/src/handlers/text_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub(crate) async fn did_open(
session.workspace.open_file(OpenFileParams {
project_key,
path,
version,
content: FileContent::FromClient(content),
version: Some(version),
document_file_source: Some(language_hint),
persist_node_cache: true,
})?;
Expand Down
Loading

0 comments on commit 864cb7e

Please sign in to comment.