Skip to content

Commit c440d2d

Browse files
ematipicoarendjr
andauthored
perf(lsp): scan project based on ScanKind (#6099)
Co-authored-by: arendjr <[email protected]>
1 parent 367ee9d commit c440d2d

File tree

36 files changed

+599
-509
lines changed

36 files changed

+599
-509
lines changed

crates/biome_cli/examples/text_reporter.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
use biome_cli::{
22
DiagnosticsPayload, Execution, Reporter, ReporterVisitor, TraversalSummary, VcsTargeted,
33
};
4-
use biome_service::projects::ProjectKey;
54

65
/// This will be the visitor, which where we **write** the data
76
struct BufferVisitor(String);
87

98
/// This is the reporter, which will be a type that will hold the information needed to the reporter
109
struct TextReport {
11-
project_key: ProjectKey,
1210
summary: TraversalSummary,
1311
}
1412

1513
impl Reporter for TextReport {
1614
fn write(self, visitor: &mut dyn ReporterVisitor) -> std::io::Result<()> {
17-
let execution = Execution::new_format(
18-
self.project_key,
19-
VcsTargeted {
20-
staged: false,
21-
changed: false,
22-
},
23-
);
15+
let execution = Execution::new_format(VcsTargeted {
16+
staged: false,
17+
changed: false,
18+
});
2419
visitor.report_summary(&execution, self.summary, false)?;
2520
Ok(())
2621
}
@@ -50,19 +45,13 @@ impl ReporterVisitor for BufferVisitor {
5045

5146
pub fn main() {
5247
// In a real scenario, the project key is obtained from the
53-
// `Workspace::open_project()` call.
54-
let project_key = ProjectKey::new();
55-
5648
let summary = TraversalSummary {
5749
changed: 32,
5850
unchanged: 28,
5951
..TraversalSummary::default()
6052
};
6153
let mut visitor = BufferVisitor(String::new());
62-
let reporter = TextReport {
63-
project_key,
64-
summary,
65-
};
54+
let reporter = TextReport { summary };
6655
reporter.write(&mut visitor).unwrap();
6756

6857
assert_eq!(visitor.0.as_str(), "Total is 64")

crates/biome_cli/src/commands/check.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use biome_configuration::{Configuration, FormatterConfiguration, LinterConfigura
99
use biome_console::Console;
1010
use biome_deserialize::Merge;
1111
use biome_fs::FileSystem;
12-
use biome_service::projects::ProjectKey;
1312
use biome_service::{Workspace, WorkspaceError, configuration::LoadedConfiguration};
1413
use std::ffi::OsString;
1514

@@ -123,7 +122,6 @@ impl CommandRunner for CheckCommandPayload {
123122
cli_options: &CliOptions,
124123
console: &mut dyn Console,
125124
_workspace: &dyn Workspace,
126-
project_key: ProjectKey,
127125
) -> Result<Execution, CliDiagnostic> {
128126
let fix_file_mode = determine_fix_file_mode(FixFileModeOptions {
129127
write: self.write,
@@ -134,7 +132,6 @@ impl CommandRunner for CheckCommandPayload {
134132
})?;
135133

136134
Ok(Execution::new(TraversalMode::Check {
137-
project_key,
138135
fix_file_mode,
139136
stdin: self.get_stdin(console)?,
140137
vcs_targeted: (self.staged, self.changed).into(),

crates/biome_cli/src/commands/ci.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use biome_console::Console;
1010
use biome_deserialize::Merge;
1111
use biome_fs::FileSystem;
1212
use biome_service::configuration::LoadedConfiguration;
13-
use biome_service::projects::ProjectKey;
1413
use biome_service::{Workspace, WorkspaceError};
1514
use std::ffi::OsString;
1615

@@ -114,10 +113,8 @@ impl CommandRunner for CiCommandPayload {
114113
cli_options: &CliOptions,
115114
_console: &mut dyn Console,
116115
_workspace: &dyn Workspace,
117-
project_key: ProjectKey,
118116
) -> Result<Execution, CliDiagnostic> {
119117
Ok(Execution::new_ci(
120-
project_key,
121118
(false, self.changed).into(),
122119
self.enforce_assist,
123120
cli_options.skip_parse_errors,

crates/biome_cli/src/commands/format.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use biome_console::Console;
1212
use biome_deserialize::Merge;
1313
use biome_fs::FileSystem;
1414
use biome_service::configuration::LoadedConfiguration;
15-
use biome_service::projects::ProjectKey;
1615
use biome_service::{Workspace, WorkspaceError};
1716
use std::ffi::OsString;
1817

@@ -138,10 +137,8 @@ impl CommandRunner for FormatCommandPayload {
138137
cli_options: &CliOptions,
139138
console: &mut dyn Console,
140139
_workspace: &dyn Workspace,
141-
project_key: ProjectKey,
142140
) -> Result<Execution, CliDiagnostic> {
143141
Ok(Execution::new(TraversalMode::Format {
144-
project_key,
145142
skip_parse_errors: cli_options.skip_parse_errors,
146143
write: self.should_write(),
147144
stdin: self.get_stdin(console)?,

crates/biome_cli/src/commands/lint.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use biome_console::Console;
1313
use biome_deserialize::Merge;
1414
use biome_fs::FileSystem;
1515
use biome_service::configuration::LoadedConfiguration;
16-
use biome_service::projects::ProjectKey;
1716
use biome_service::{Workspace, WorkspaceError};
1817
use std::ffi::OsString;
1918

@@ -127,7 +126,6 @@ impl CommandRunner for LintCommandPayload {
127126
cli_options: &CliOptions,
128127
console: &mut dyn Console,
129128
_workspace: &dyn Workspace,
130-
project_key: ProjectKey,
131129
) -> Result<Execution, CliDiagnostic> {
132130
let fix_file_mode = determine_fix_file_mode(FixFileModeOptions {
133131
write: self.write,
@@ -137,7 +135,6 @@ impl CommandRunner for LintCommandPayload {
137135
suppression_reason: self.suppression_reason.clone(),
138136
})?;
139137
Ok(Execution::new(TraversalMode::Lint {
140-
project_key,
141138
fix_file_mode,
142139
stdin: self.get_stdin(console)?,
143140
only: self.only.clone(),

crates/biome_cli/src/commands/migrate.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use biome_configuration::Configuration;
99
use biome_console::{Console, ConsoleExt, markup};
1010
use biome_fs::FileSystem;
1111
use biome_service::configuration::LoadedConfiguration;
12-
use biome_service::projects::ProjectKey;
1312
use biome_service::{Workspace, WorkspaceError};
1413
use camino::Utf8PathBuf;
1514
use std::ffi::OsString;
@@ -57,11 +56,9 @@ impl CommandRunner for MigrateCommandPayload {
5756
_cli_options: &CliOptions,
5857
console: &mut dyn Console,
5958
_workspace: &dyn Workspace,
60-
project_key: ProjectKey,
6159
) -> Result<Execution, CliDiagnostic> {
6260
if let Some(path) = self.configuration_file_path.clone() {
6361
Ok(Execution::new(TraversalMode::Migrate {
64-
project_key,
6562
write: self.should_write(),
6663
configuration_file_path: path,
6764
sub_command: self.sub_command.clone(),

crates/biome_cli/src/commands/mod.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::commands::scan_kind::compute_scan_kind;
44
use crate::execute::Stdin;
55
use crate::logging::LoggingKind;
66
use crate::{
7-
CliDiagnostic, CliSession, Execution, LoggingLevel, VERSION, execute_mode, setup_cli_subscriber,
7+
CliDiagnostic, CliSession, Execution, LoggingLevel, TraversalMode, VERSION, execute_mode,
8+
setup_cli_subscriber,
89
};
910
use biome_configuration::analyzer::assist::AssistEnabled;
1011
use biome_configuration::analyzer::{LinterEnabled, RuleSelector};
@@ -34,7 +35,7 @@ use biome_service::configuration::{LoadedConfiguration, load_configuration, load
3435
use biome_service::documentation::Doc;
3536
use biome_service::projects::ProjectKey;
3637
use biome_service::workspace::{
37-
FixFileMode, OpenProjectParams, ScanProjectFolderParams, UpdateSettingsParams,
38+
FixFileMode, OpenProjectParams, ScanKind, ScanProjectFolderParams, UpdateSettingsParams,
3839
};
3940
use biome_service::{Workspace, WorkspaceError};
4041
use bpaf::Bpaf;
@@ -791,6 +792,7 @@ pub(crate) trait CommandRunner: Sized {
791792
paths,
792793
duration,
793794
configuration_files,
795+
project_key,
794796
} = self.configure_workspace(fs, console, workspace, cli_options)?;
795797
execute_mode(
796798
execution,
@@ -799,6 +801,7 @@ pub(crate) trait CommandRunner: Sized {
799801
paths,
800802
duration,
801803
configuration_files,
804+
project_key,
802805
)
803806
}
804807

@@ -837,16 +840,37 @@ pub(crate) trait CommandRunner: Sized {
837840
.working_directory()
838841
.map(BiomePath::from)
839842
.unwrap_or_default();
840-
let project_key = workspace.open_project(OpenProjectParams {
841-
path: project_path.clone(),
842-
open_uninitialized: true,
843-
})?;
844843

845-
let execution = self.get_execution(cli_options, console, workspace, project_key)?;
846-
let scan_kind = compute_scan_kind(&execution, &configuration);
844+
let execution = self.get_execution(cli_options, console, workspace)?;
845+
846+
let params = if let TraversalMode::Lint { only, skip, .. } = execution.traversal_mode() {
847+
OpenProjectParams {
848+
path: project_path.clone(),
849+
open_uninitialized: true,
850+
only_rules: Some(only.clone()),
851+
skip_rules: Some(skip.clone()),
852+
}
853+
} else {
854+
OpenProjectParams {
855+
path: project_path.clone(),
856+
open_uninitialized: true,
857+
only_rules: None,
858+
skip_rules: None,
859+
}
860+
};
861+
862+
let open_project_result = workspace.open_project(params)?;
863+
864+
let scan_kind = compute_scan_kind(&execution, &configuration).unwrap_or({
865+
if open_project_result.scan_kind == ScanKind::None && configuration.use_ignore_file() {
866+
ScanKind::KnownFiles
867+
} else {
868+
open_project_result.scan_kind
869+
}
870+
});
847871

848872
let result = workspace.update_settings(UpdateSettingsParams {
849-
project_key,
873+
project_key: open_project_result.project_key,
850874
// When the user provides the path to the configuration, we can't use its directory because
851875
// it might be outside the project, so we need to use the current project directory.
852876
workspace_directory: if is_configuration_from_user {
@@ -865,7 +889,7 @@ pub(crate) trait CommandRunner: Sized {
865889
}
866890

867891
let result = workspace.scan_project_folder(ScanProjectFolderParams {
868-
project_key,
892+
project_key: open_project_result.project_key,
869893
path: Some(project_path.clone()),
870894
watch: cli_options.use_server,
871895
force: false, // TODO: Maybe we'll want a CLI flag for this.
@@ -886,6 +910,7 @@ pub(crate) trait CommandRunner: Sized {
886910
paths,
887911
duration: Some(result.duration),
888912
configuration_files: result.configuration_files,
913+
project_key: open_project_result.project_key,
889914
})
890915
}
891916

@@ -941,7 +966,6 @@ pub(crate) trait CommandRunner: Sized {
941966
cli_options: &CliOptions,
942967
console: &mut dyn Console,
943968
workspace: &dyn Workspace,
944-
project_key: ProjectKey,
945969
) -> Result<Execution, CliDiagnostic>;
946970

947971
// Below, methods that consumers can implement
@@ -968,6 +992,8 @@ pub(crate) struct ConfiguredWorkspace {
968992
pub duration: Option<Duration>,
969993
/// Configuration files found inside the project
970994
pub configuration_files: Vec<BiomePath>,
995+
/// The unique identifier of the project
996+
pub project_key: ProjectKey,
971997
}
972998

973999
pub trait LoadEditorConfig: CommandRunner {

0 commit comments

Comments
 (0)