diff --git a/.changeset/curly-tables-stare.md b/.changeset/curly-tables-stare.md new file mode 100644 index 000000000000..0d40d6eff89a --- /dev/null +++ b/.changeset/curly-tables-stare.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": patch +--- + +Fixed a bug where the Biome Language Server didn't correctly compute the diagnostics of a monorepo setting, caused by an incorrect handling of the project status. diff --git a/.changeset/spicy-things-bathe.md b/.changeset/spicy-things-bathe.md new file mode 100644 index 000000000000..f6ce01a69baa --- /dev/null +++ b/.changeset/spicy-things-bathe.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": patch +--- + +Fixed [#7371](https://github.com/biomejs/biome/issues/7371) where the Biome Language Server didn't correctly recompute the diagnostics when updating a nested configuration file. diff --git a/crates/biome_lsp/src/documents.rs b/crates/biome_lsp/src/documents.rs index af81cb9ec179..b96540fccab3 100644 --- a/crates/biome_lsp/src/documents.rs +++ b/crates/biome_lsp/src/documents.rs @@ -4,7 +4,7 @@ use biome_service::projects::ProjectKey; /// Represents an open [`textDocument`]. Can be cheaply cloned. /// /// [`textDocument`]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentItem -#[derive(Clone)] +#[derive(Debug, Clone)] pub(crate) struct Document { pub(crate) project_key: ProjectKey, pub(crate) version: i32, diff --git a/crates/biome_lsp/src/handlers/text_document.rs b/crates/biome_lsp/src/handlers/text_document.rs index f6e24820f714..06e6ba1fbd3f 100644 --- a/crates/biome_lsp/src/handlers/text_document.rs +++ b/crates/biome_lsp/src/handlers/text_document.rs @@ -3,13 +3,13 @@ use std::sync::Arc; use crate::diagnostics::LspError; use crate::utils::apply_document_changes; use crate::{documents::Document, session::Session}; -use biome_configuration::ConfigurationPathHint; use biome_service::workspace::{ ChangeFileParams, CloseFileParams, DocumentFileSource, FeaturesBuilder, FileContent, GetFileContentParams, IgnoreKind, OpenFileParams, PathIsIgnoredParams, }; use tower_lsp_server::lsp_types; -use tracing::{debug, error, field, info}; +use tower_lsp_server::lsp_types::MessageType; +use tracing::{debug, error, field}; /// Handler for `textDocument/didOpen` LSP notification #[tracing::instrument( @@ -30,33 +30,23 @@ pub(crate) async fn did_open( let language_hint = DocumentFileSource::from_language_id(¶ms.text_document.language_id); let path = session.file_path(&url)?; - let project_key = match session.project_for_path(&path) { - Some(project_key) => project_key, - None => { - info!("No open project for path: {path:?}. Opening new project."); - let parent_path = path - .parent() - .map(|parent| parent.to_path_buf()) - .unwrap_or_default(); - let status = session - .load_biome_configuration_file(ConfigurationPathHint::FromLsp(parent_path)) - .await; - debug!("Configuration status: {status:?}"); - session.set_configuration_status(status); - - if status.is_loaded() { - match session.project_for_path(&path) { - Some(project_key) => project_key, - None => { - error!("Could not find project for {path}"); - return Ok(()); - } - } - } else { - error!("Configuration could not be loaded for {path}"); + + let status = session.configuration_status(); + + let project_key = if status.is_loaded() { + match session.project_for_path(&path) { + Some(project_key) => project_key, + None => { + error!("Could not find project for {path}"); return Ok(()); } } + } else { + if status.is_plugin_error() { + session.client.show_message(MessageType::WARNING, "The plugin loading has failed. Biome will report only parsing errors until the file is fixed or its usage is disabled.").await; + } + error!("Configuration could not be loaded for {path}"); + return Ok(()); }; let is_ignored = session diff --git a/crates/biome_lsp/src/server.rs b/crates/biome_lsp/src/server.rs index 3739d6e985b3..1b71a078dcf4 100644 --- a/crates/biome_lsp/src/server.rs +++ b/crates/biome_lsp/src/server.rs @@ -354,7 +354,9 @@ impl LanguageServer for LSPServer { if let Some(base_path) = base_path { let possible_biome_json = file_path.strip_prefix(&base_path); if let Ok(watched_file) = possible_biome_json - && (ConfigName::file_names().contains(&&*watched_file.display().to_string()) + && (ConfigName::file_names() + .iter() + .any(|file_name| watched_file.ends_with(file_name)) || watched_file.ends_with(".editorconfig")) { self.session.load_extension_settings().await; diff --git a/crates/biome_lsp/src/session.rs b/crates/biome_lsp/src/session.rs index 686ad75cd634..ad9f3e7d6cc6 100644 --- a/crates/biome_lsp/src/session.rs +++ b/crates/biome_lsp/src/session.rs @@ -465,7 +465,7 @@ impl Session { .collect() }; - tracing::Span::current().record("diagnostic_count", diagnostics.len()); + info!("Diagnostics sent to the client {}", diagnostics.len()); self.client .publish_diagnostics(url, diagnostics, Some(doc.version)) @@ -780,16 +780,23 @@ impl Session { .or_else(|| fs.working_directory()) .unwrap_or_default(), }; - let register_result = self.workspace.open_project(OpenProjectParams { - path: path.as_path().into(), - open_uninitialized: true, - }); - let OpenProjectResult { project_key } = match register_result { - Ok(result) => result, - Err(error) => { - error!("Failed to register the project folder: {error}"); - self.client.log_message(MessageType::ERROR, &error).await; - return ConfigurationStatus::Error; + + let project_key = match self.project_for_path(&path) { + Some(project_key) => project_key, + None => { + let register_result = self.workspace.open_project(OpenProjectParams { + path: path.as_path().into(), + open_uninitialized: true, + }); + let OpenProjectResult { project_key } = match register_result { + Ok(result) => result, + Err(error) => { + error!("Failed to register the project folder: {error}"); + self.client.log_message(MessageType::ERROR, &error).await; + return ConfigurationStatus::Error; + } + }; + project_key } }; diff --git a/crates/biome_service/src/projects.rs b/crates/biome_service/src/projects.rs index d5c0cd65e41f..7cae209602ce 100644 --- a/crates/biome_service/src/projects.rs +++ b/crates/biome_service/src/projects.rs @@ -273,7 +273,7 @@ impl Projects { ProjectData { path: data.path.clone(), root_settings: data.root_settings.clone(), - nested_settings: nested_settings.clone(), + nested_settings, } }); }