Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/curly-tables-stare.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions .changeset/spicy-things-bathe.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion crates/biome_lsp/src/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 16 additions & 26 deletions crates/biome_lsp/src/handlers/text_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -30,33 +30,23 @@ pub(crate) async fn did_open(
let language_hint = DocumentFileSource::from_language_id(&params.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
Expand Down
4 changes: 3 additions & 1 deletion crates/biome_lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 18 additions & 11 deletions crates/biome_lsp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
};

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_service/src/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl Projects {
ProjectData {
path: data.path.clone(),
root_settings: data.root_settings.clone(),
nested_settings: nested_settings.clone(),
nested_settings,
}
});
}
Expand Down
Loading