Skip to content

Commit 6cc84cb

Browse files
authored
fix(core): consider extended configs for scan kind (#7099)
1 parent 655049e commit 6cc84cb

File tree

19 files changed

+252
-287
lines changed

19 files changed

+252
-287
lines changed
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 [#7062](https://github.com/biomejs/biome/issues/7062): Biome now correctly considers extended configs when determining the mode for the scanner.

crates/biome_cli/src/commands/mod.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ use biome_diagnostics::{Diagnostic, PrintDiagnostic, Severity};
3131
use biome_fs::{BiomePath, FileSystem};
3232
use biome_grit_patterns::GritTargetLanguage;
3333
use biome_resolver::FsWithResolverProxy;
34-
use biome_service::configuration::{LoadedConfiguration, load_configuration, load_editorconfig};
34+
use biome_service::configuration::{
35+
LoadedConfiguration, ProjectScanComputer, load_configuration, load_editorconfig,
36+
};
3537
use biome_service::documentation::Doc;
3638
use biome_service::projects::ProjectKey;
3739
use biome_service::workspace::{
@@ -921,27 +923,20 @@ pub(crate) trait CommandRunner: Sized {
921923
let paths = self.get_files_to_process(fs, &configuration)?;
922924
let paths = validated_paths_for_execution(paths, &execution, &working_dir)?;
923925

924-
let params = if let TraversalMode::Lint { only, skip, .. } = execution.traversal_mode() {
925-
OpenProjectParams {
926-
path: BiomePath::new(project_dir),
927-
open_uninitialized: true,
928-
only_rules: Some(only.clone()),
929-
skip_rules: Some(skip.clone()),
930-
}
931-
} else {
932-
OpenProjectParams {
933-
path: BiomePath::new(project_dir),
934-
open_uninitialized: true,
935-
only_rules: None,
936-
skip_rules: None,
937-
}
938-
};
939-
940926
// Open the project
941-
let open_project_result = workspace.open_project(params)?;
927+
let open_project_result = workspace.open_project(OpenProjectParams {
928+
path: BiomePath::new(project_dir),
929+
open_uninitialized: true,
930+
})?;
942931

932+
let scan_kind_computer =
933+
if let TraversalMode::Lint { only, skip, .. } = execution.traversal_mode() {
934+
ProjectScanComputer::new(&configuration).with_rule_selectors(skip, only)
935+
} else {
936+
ProjectScanComputer::new(&configuration)
937+
};
943938
let scan_kind = derive_best_scan_kind(
944-
open_project_result.scan_kind,
939+
scan_kind_computer.compute(),
945940
&execution,
946941
&root_configuration_dir,
947942
&working_dir,

crates/biome_cli/tests/commands/lint.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,6 +4079,64 @@ bar();"#
40794079
));
40804080
}
40814081

4082+
#[test]
4083+
fn linter_enables_project_domain_based_on_extended_config() {
4084+
let mut console = BufferConsole::default();
4085+
let fs = MemoryFileSystem::default();
4086+
4087+
fs.insert(
4088+
Utf8Path::new("biome.json").into(),
4089+
r#"{ "extends": ["biome.base.json"] }"#.as_bytes(),
4090+
);
4091+
4092+
fs.insert(
4093+
Utf8Path::new("biome.base.json").into(),
4094+
r#"{
4095+
"linter": {
4096+
"rules": {
4097+
"nursery": {
4098+
"noFloatingPromises": "on"
4099+
}
4100+
}
4101+
}
4102+
}"#
4103+
.as_bytes(),
4104+
);
4105+
4106+
let file = Utf8Path::new("src/foo.ts");
4107+
fs.insert(
4108+
file.into(),
4109+
r#"export function foo(): Foo {}
4110+
4111+
export async function bar() {}"#
4112+
.as_bytes(),
4113+
);
4114+
4115+
let file = Utf8Path::new("src/index.ts");
4116+
fs.insert(
4117+
file.into(),
4118+
r#"import { foo, bar } from "./foo.ts";
4119+
4120+
fn(foo());
4121+
4122+
bar();"#
4123+
.as_bytes(),
4124+
);
4125+
4126+
let (fs, result) = run_cli_with_server_workspace(
4127+
fs,
4128+
&mut console,
4129+
Args::from(["lint", file.as_str()].as_slice()),
4130+
);
4131+
assert_cli_snapshot(SnapshotPayload::new(
4132+
module_path!(),
4133+
"linter_enables_project_domain_based_on_extended_config",
4134+
fs,
4135+
console,
4136+
result,
4137+
));
4138+
}
4139+
40824140
#[test]
40834141
fn should_apply_root_settings_with_stdin_file_path() {
40844142
let mut fs = TemporaryFs::new("should_apply_root_settings_with_stdin_file_path");
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `biome.json`
6+
7+
```json
8+
{ "extends": ["biome.base.json"] }
9+
```
10+
11+
## `biome.base.json`
12+
13+
```json
14+
{
15+
"linter": {
16+
"rules": {
17+
"nursery": {
18+
"noFloatingPromises": "on"
19+
}
20+
}
21+
}
22+
}
23+
```
24+
25+
## `src/foo.ts`
26+
27+
```ts
28+
export function foo(): Foo {}
29+
30+
export async function bar() {}
31+
```
32+
33+
## `src/index.ts`
34+
35+
```ts
36+
import { foo, bar } from "./foo.ts";
37+
38+
fn(foo());
39+
40+
bar();
41+
```
42+
43+
# Emitted Messages
44+
45+
```block
46+
src/index.ts:5:1 lint/nursery/noFloatingPromises ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
47+
48+
i A "floating" Promise was found, meaning it is not properly handled and could lead to ignored errors or unexpected behavior.
49+
50+
3 │ fn(foo());
51+
4 │
52+
> 5 │ bar();
53+
│ ^^^^^^
54+
55+
i This happens when a Promise is not awaited, lacks a `.catch` or `.then` rejection handler, or is not explicitly ignored using the `void` operator.
56+
57+
58+
```
59+
60+
```block
61+
Checked 1 file in <TIME>. No fixes applied.
62+
```

crates/biome_formatter_test/src/spec.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ impl<'a> SpecTestFile<'a> {
5050
"The input '{spec_input_file}' must exist and be a file.",
5151
);
5252

53-
let OpenProjectResult { project_key, .. } = app
53+
let OpenProjectResult { project_key } = app
5454
.workspace
5555
.open_project(OpenProjectParams {
5656
path: BiomePath::new(""),
5757
open_uninitialized: true,
58-
only_rules: None,
59-
skip_rules: None,
6058
})
6159
.unwrap();
6260

crates/biome_lsp/src/handlers/text_document.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ 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_fs::BiomePath;
6+
use biome_configuration::ConfigurationPathHint;
77
use biome_service::workspace::{
88
ChangeFileParams, CloseFileParams, DocumentFileSource, FeaturesBuilder, FileContent,
9-
GetFileContentParams, IgnoreKind, IsPathIgnoredParams, OpenFileParams, OpenProjectParams,
10-
ScanKind,
9+
GetFileContentParams, IgnoreKind, IsPathIgnoredParams, OpenFileParams,
1110
};
1211
use tower_lsp_server::lsp_types;
1312
use tracing::{debug, error, field, info};
@@ -35,26 +34,28 @@ pub(crate) async fn did_open(
3534
Some(project_key) => project_key,
3635
None => {
3736
info!("No open project for path: {path:?}. Opening new project.");
38-
let parent_path = BiomePath::new(
39-
path.parent()
40-
.map(|parent| parent.to_path_buf())
41-
.unwrap_or_default(),
42-
);
43-
let result = session.workspace.open_project(OpenProjectParams {
44-
path: parent_path.clone(),
45-
open_uninitialized: true,
46-
skip_rules: None,
47-
only_rules: None,
48-
})?;
49-
let scan_kind = if result.scan_kind.is_none() {
50-
ScanKind::KnownFiles
51-
} else {
52-
result.scan_kind
53-
};
54-
session
55-
.insert_and_scan_project(result.project_key, parent_path, scan_kind)
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))
5643
.await;
57-
result.project_key
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}");
57+
return Ok(());
58+
}
5859
}
5960
};
6061

crates/biome_lsp/src/server.rs

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use crate::session::{
66
};
77
use crate::utils::{into_lsp_error, panic_to_lsp_error};
88
use crate::{handlers, requests};
9+
use biome_configuration::ConfigurationPathHint;
910
use biome_console::markup;
1011
use biome_diagnostics::panic::PanicError;
1112
use biome_fs::{ConfigName, MemoryFileSystem, OsFileSystem};
1213
use biome_resolver::FsWithResolverProxy;
1314
use biome_service::workspace::{
14-
CloseProjectParams, OpenProjectParams, RageEntry, RageParams, RageResult, ScanKind,
15-
ServiceDataNotification,
15+
CloseProjectParams, RageEntry, RageParams, RageResult, ServiceDataNotification,
1616
};
1717
use biome_service::{WatcherInstruction, WorkspaceServer};
1818
use crossbeam::channel::{Sender, bounded};
@@ -412,39 +412,14 @@ impl LanguageServer for LSPServer {
412412

413413
for added in &params.event.added {
414414
if let Ok(project_path) = self.session.file_path(&added.uri) {
415-
let result = self
415+
let status = self
416416
.session
417-
.workspace
418-
.open_project(OpenProjectParams {
419-
path: project_path.clone(),
420-
open_uninitialized: true,
421-
only_rules: None,
422-
skip_rules: None,
423-
})
424-
.map_err(LspError::from);
425-
426-
match result {
427-
Ok(result) => {
428-
let scan_kind = if result.scan_kind.is_none() {
429-
ScanKind::KnownFiles
430-
} else {
431-
result.scan_kind
432-
};
433-
self.session
434-
.insert_and_scan_project(
435-
result.project_key,
436-
project_path.clone(),
437-
scan_kind,
438-
)
439-
.await;
440-
441-
self.session.update_all_diagnostics().await;
442-
}
443-
Err(err) => {
444-
error!("Failed to add project to the workspace: {err}");
445-
self.notify_error(err).await;
446-
}
447-
}
417+
.load_biome_configuration_file(ConfigurationPathHint::FromWorkspace(
418+
project_path.to_path_buf(),
419+
))
420+
.await;
421+
debug!("Configuration status: {status:?}");
422+
self.session.set_configuration_status(status);
448423
}
449424
}
450425
}

0 commit comments

Comments
 (0)