Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): workspace watcher #5200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

11 changes: 9 additions & 2 deletions crates/biome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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 std::{env, fs};
use tokio::io;
Expand Down Expand Up @@ -80,8 +80,10 @@ pub(crate) fn run_server(
) -> Result<(), CliDiagnostic> {
setup_tracing_subscriber(log_path.as_deref(), log_file_name_prefix.as_deref());

let (mut watcher, instruction_channel) = WorkspaceWatcher::new()?;

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

let workspace = factory.workspace();
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 @@ -811,6 +811,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::Error {
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
2 changes: 1 addition & 1 deletion crates/biome_fs/src/fs/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl From<FileType> for FsErrorKind {
pub struct TemporaryFs {
/// The current working directory. It's the OS temporary folder joined with a file
/// name passed in the [TemporaryFs::new] function
working_directory: Utf8PathBuf,
pub working_directory: Utf8PathBuf,
files: Vec<(Utf8PathBuf, String)>,
}

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
Loading