Skip to content

Commit 811f47b

Browse files
authored
fix(lsp): internal project handling (#7377)
1 parent e8032dd commit 811f47b

File tree

7 files changed

+49
-40
lines changed

7 files changed

+49
-40
lines changed

.changeset/curly-tables-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
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.

.changeset/spicy-things-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
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.

crates/biome_lsp/src/documents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use biome_service::projects::ProjectKey;
44
/// Represents an open [`textDocument`]. Can be cheaply cloned.
55
///
66
/// [`textDocument`]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentItem
7-
#[derive(Clone)]
7+
#[derive(Debug, Clone)]
88
pub(crate) struct Document {
99
pub(crate) project_key: ProjectKey,
1010
pub(crate) version: i32,

crates/biome_lsp/src/handlers/text_document.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::sync::Arc;
33
use crate::diagnostics::LspError;
44
use crate::utils::apply_document_changes;
55
use crate::{documents::Document, session::Session};
6-
use biome_configuration::ConfigurationPathHint;
76
use biome_service::workspace::{
87
ChangeFileParams, CloseFileParams, DocumentFileSource, FeaturesBuilder, FileContent,
98
GetFileContentParams, IgnoreKind, OpenFileParams, PathIsIgnoredParams,
109
};
1110
use tower_lsp_server::lsp_types;
12-
use tracing::{debug, error, field, info};
11+
use tower_lsp_server::lsp_types::MessageType;
12+
use tracing::{debug, error, field};
1313

1414
/// Handler for `textDocument/didOpen` LSP notification
1515
#[tracing::instrument(
@@ -30,33 +30,23 @@ pub(crate) async fn did_open(
3030
let language_hint = DocumentFileSource::from_language_id(&params.text_document.language_id);
3131

3232
let path = session.file_path(&url)?;
33-
let project_key = match session.project_for_path(&path) {
34-
Some(project_key) => project_key,
35-
None => {
36-
info!("No open project for path: {path:?}. Opening new project.");
37-
let parent_path = path
38-
.parent()
39-
.map(|parent| parent.to_path_buf())
40-
.unwrap_or_default();
41-
let status = session
42-
.load_biome_configuration_file(ConfigurationPathHint::FromLsp(parent_path))
43-
.await;
44-
debug!("Configuration status: {status:?}");
45-
session.set_configuration_status(status);
46-
47-
if status.is_loaded() {
48-
match session.project_for_path(&path) {
49-
Some(project_key) => project_key,
50-
None => {
51-
error!("Could not find project for {path}");
52-
return Ok(());
53-
}
54-
}
55-
} else {
56-
error!("Configuration could not be loaded for {path}");
33+
34+
let status = session.configuration_status();
35+
36+
let project_key = if status.is_loaded() {
37+
match session.project_for_path(&path) {
38+
Some(project_key) => project_key,
39+
None => {
40+
error!("Could not find project for {path}");
5741
return Ok(());
5842
}
5943
}
44+
} else {
45+
if status.is_plugin_error() {
46+
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;
47+
}
48+
error!("Configuration could not be loaded for {path}");
49+
return Ok(());
6050
};
6151

6252
let is_ignored = session

crates/biome_lsp/src/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ impl LanguageServer for LSPServer {
354354
if let Some(base_path) = base_path {
355355
let possible_biome_json = file_path.strip_prefix(&base_path);
356356
if let Ok(watched_file) = possible_biome_json
357-
&& (ConfigName::file_names().contains(&&*watched_file.display().to_string())
357+
&& (ConfigName::file_names()
358+
.iter()
359+
.any(|file_name| watched_file.ends_with(file_name))
358360
|| watched_file.ends_with(".editorconfig"))
359361
{
360362
self.session.load_extension_settings().await;

crates/biome_lsp/src/session.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl Session {
465465
.collect()
466466
};
467467

468-
tracing::Span::current().record("diagnostic_count", diagnostics.len());
468+
info!("Diagnostics sent to the client {}", diagnostics.len());
469469

470470
self.client
471471
.publish_diagnostics(url, diagnostics, Some(doc.version))
@@ -780,16 +780,23 @@ impl Session {
780780
.or_else(|| fs.working_directory())
781781
.unwrap_or_default(),
782782
};
783-
let register_result = self.workspace.open_project(OpenProjectParams {
784-
path: path.as_path().into(),
785-
open_uninitialized: true,
786-
});
787-
let OpenProjectResult { project_key } = match register_result {
788-
Ok(result) => result,
789-
Err(error) => {
790-
error!("Failed to register the project folder: {error}");
791-
self.client.log_message(MessageType::ERROR, &error).await;
792-
return ConfigurationStatus::Error;
783+
784+
let project_key = match self.project_for_path(&path) {
785+
Some(project_key) => project_key,
786+
None => {
787+
let register_result = self.workspace.open_project(OpenProjectParams {
788+
path: path.as_path().into(),
789+
open_uninitialized: true,
790+
});
791+
let OpenProjectResult { project_key } = match register_result {
792+
Ok(result) => result,
793+
Err(error) => {
794+
error!("Failed to register the project folder: {error}");
795+
self.client.log_message(MessageType::ERROR, &error).await;
796+
return ConfigurationStatus::Error;
797+
}
798+
};
799+
project_key
793800
}
794801
};
795802

crates/biome_service/src/projects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl Projects {
273273
ProjectData {
274274
path: data.path.clone(),
275275
root_settings: data.root_settings.clone(),
276-
nested_settings: nested_settings.clone(),
276+
nested_settings,
277277
}
278278
});
279279
}

0 commit comments

Comments
 (0)