Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): ordered paths, project manifest, tsconfig #3699

Merged
merged 20 commits into from
Aug 27, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ pub(crate) fn check(
cli_options.verbose,
)?;

resolve_manifest(&session)?;

let editorconfig_search_path = loaded_configuration.directory_path.clone();
let LoadedConfiguration {
configuration: biome_configuration,
Expand Down Expand Up @@ -187,6 +185,14 @@ pub(crate) fn check(
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;
let manifest_data = resolve_manifest(&session.app.fs)?;

if let Some(manifest_data) = manifest_data {
session
.app
.workspace
.set_manifest_for_project(manifest_data.into())?;
}

session
.app
Expand Down
9 changes: 8 additions & 1 deletion crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub(crate) fn ci(session: CliSession, payload: CiCommandPayload) -> Result<(), C
session.app.console,
cli_options.verbose,
)?;
resolve_manifest(&session)?;

let LoadedConfiguration {
configuration: mut fs_configuration,
Expand Down Expand Up @@ -127,6 +126,14 @@ pub(crate) fn ci(session: CliSession, payload: CiCommandPayload) -> Result<(), C
set_as_current_workspace: true,
})?;

let manifest_data = resolve_manifest(&session.app.fs)?;

if let Some(manifest_data) = manifest_data {
session
.app
.workspace
.set_manifest_for_project(manifest_data.into())?;
}
session
.app
.workspace
Expand Down
10 changes: 8 additions & 2 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ pub(crate) fn format(
cli_options.verbose,
)?;

resolve_manifest(&session)?;

let editorconfig_search_path = loaded_configuration.directory_path.clone();
let LoadedConfiguration {
configuration: biome_configuration,
Expand Down Expand Up @@ -236,6 +234,14 @@ pub(crate) fn format(
set_as_current_workspace: true,
})?;

let manifest_data = resolve_manifest(&session.app.fs)?;

if let Some(manifest_data) = manifest_data {
session
.app
.workspace
.set_manifest_for_project(manifest_data.into())?;
}
session
.app
.workspace
Expand Down
9 changes: 8 additions & 1 deletion crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
session.app.console,
cli_options.verbose,
)?;
resolve_manifest(&session)?;

let LoadedConfiguration {
configuration: mut fs_configuration,
Expand Down Expand Up @@ -156,6 +155,14 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;
let manifest_data = resolve_manifest(&session.app.fs)?;

if let Some(manifest_data) = manifest_data {
session
.app
.workspace
.set_manifest_for_project(manifest_data.into())?;
}

session
.app
Expand Down
21 changes: 7 additions & 14 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::cli_options::{cli_options, CliOptions, CliReporter, ColorsArg};
use crate::diagnostics::{DeprecatedArgument, DeprecatedConfigurationFile};
use crate::execute::Stdin;
use crate::logging::LoggingKind;
use crate::{CliDiagnostic, CliSession, LoggingLevel, VERSION};
use crate::{CliDiagnostic, LoggingLevel, VERSION};
use biome_configuration::analyzer::RuleSelector;
use biome_configuration::css::PartialCssLinter;
use biome_configuration::javascript::PartialJavascriptLinter;
Expand All @@ -24,7 +24,7 @@ use biome_diagnostics::{Diagnostic, PrintDiagnostic};
use biome_fs::{BiomePath, FileSystem};
use biome_service::configuration::LoadedConfiguration;
use biome_service::documentation::Doc;
use biome_service::workspace::{FixFileMode, OpenProjectParams, UpdateProjectParams};
use biome_service::workspace::FixFileMode;
use biome_service::{DynRef, WorkspaceError};
use bpaf::Bpaf;
use std::ffi::OsString;
Expand Down Expand Up @@ -640,27 +640,20 @@ pub(crate) fn validate_configuration_diagnostics(
Ok(())
}

fn resolve_manifest(cli_session: &CliSession) -> Result<(), WorkspaceError> {
let fs = &*cli_session.app.fs;
let workspace = &*cli_session.app.workspace;

fn resolve_manifest(
fs: &DynRef<'_, dyn FileSystem>,
) -> Result<Option<(BiomePath, String)>, WorkspaceError> {
let result = fs.auto_search(
&fs.working_directory().unwrap_or_default(),
&["package.json"],
false,
)?;

if let Some(result) = result {
let biome_path = BiomePath::new(result.file_path);
workspace.open_project(OpenProjectParams {
path: biome_path.clone(),
content: result.content,
version: 0,
})?;
workspace.update_current_manifest(UpdateProjectParams { path: biome_path })?;
return Ok(Some((BiomePath::new(result.file_path), result.content)));
}

Ok(())
Ok(None)
}

/// Computes [Stdin] if the CLI has the necessary information.
Expand Down
30 changes: 21 additions & 9 deletions crates/biome_cli/src/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub(crate) fn search(
session.app.console,
cli_options.verbose,
)?;
resolve_manifest(&session)?;

let LoadedConfiguration {
mut configuration,
Expand All @@ -60,25 +59,38 @@ pub(crate) fn search(
let (vcs_base_path, gitignore_matches) =
configuration.retrieve_gitignore_matches(&session.app.fs, vcs_base_path.as_deref())?;

let workspace = &session.app.workspace;
session
.app
.workspace
.register_project_folder(RegisterProjectFolderParams {
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;
workspace.update_settings(UpdateSettingsParams {
workspace_directory: session.app.fs.working_directory(),
configuration,
vcs_base_path,
gitignore_matches,
})?;
let manifest_data = resolve_manifest(&session.app.fs)?;

if let Some(manifest_data) = manifest_data {
session
.app
.workspace
.set_manifest_for_project(manifest_data.into())?;
}

session
.app
.workspace
.update_settings(UpdateSettingsParams {
workspace_directory: session.app.fs.working_directory(),
configuration,
vcs_base_path,
gitignore_matches,
})?;

let console = &mut *session.app.console;
let stdin = get_stdin(stdin_file_path, console, "search")?;

let pattern = workspace
let pattern = session
.app
.workspace
.parse_pattern(ParsePatternParams { pattern })?
.pattern_id;

Expand Down
25 changes: 12 additions & 13 deletions crates/biome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use lint::lint;
use search::search;
use std::marker::PhantomData;
use std::ops::Deref;
use std::path::Path;

#[derive(Debug)]
pub(crate) enum FileStatus {
/// File changed and it was a success
Expand Down Expand Up @@ -125,17 +125,16 @@ impl<'ctx, 'app> Deref for SharedTraversalOptions<'ctx, 'app> {
/// diagnostics were emitted, or compare the formatted code with the original
/// content of the file and emit a diff or write the new content to the disk if
/// write mode is enabled
pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult {
tracing::trace_span!("process_file", path = ?path).in_scope(move || {
let biome_path = BiomePath::new(path);
pub(crate) fn process_file(ctx: &TraversalOptions, biome_path: &BiomePath) -> FileResult {
tracing::trace_span!("process_file", path = ?biome_path).in_scope(move || {
let file_features = ctx
.workspace
.file_features(SupportsFeatureParams {
path: biome_path,
path: biome_path.clone(),
features: ctx.execution.to_feature(),
})
.with_file_path_and_code_and_tags(
path.display().to_string(),
biome_path.display().to_string(),
category!("files/missingHandler"),
DiagnosticTags::VERBOSE,
)?;
Expand All @@ -145,7 +144,7 @@ pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult {
return Ok(FileStatus::Ignored);
} else if file_features.is_not_supported() {
return Err(Message::from(
UnhandledDiagnostic.with_file_path(path.display().to_string()),
UnhandledDiagnostic.with_file_path(biome_path.display().to_string()),
));
}

Expand Down Expand Up @@ -192,14 +191,14 @@ pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult {
match reason {
SupportKind::FileNotSupported => {
return Err(Message::from(
UnhandledDiagnostic.with_file_path(path.display().to_string()),
UnhandledDiagnostic.with_file_path(biome_path.display().to_string()),
));
}
SupportKind::FeatureNotEnabled | SupportKind::Ignored => {
return Ok(FileStatus::Ignored);
}
SupportKind::Protected => {
return Ok(FileStatus::Protected(path.display().to_string()));
return Ok(FileStatus::Protected(biome_path.display().to_string()));
}
SupportKind::Supported => {}
};
Expand All @@ -210,21 +209,21 @@ pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult {
match ctx.execution.traversal_mode {
TraversalMode::Lint { .. } => {
// the unsupported case should be handled already at this point
lint(shared_context, path)
lint(shared_context, biome_path)
}
TraversalMode::Format { .. } => {
// the unsupported case should be handled already at this point
format(shared_context, path)
format(shared_context, biome_path)
}
TraversalMode::Check { .. } | TraversalMode::CI { .. } => {
check_file(shared_context, path, &file_features)
check_file(shared_context, biome_path, &file_features)
}
TraversalMode::Migrate { .. } => {
unreachable!("The migration should not be called for this file")
}
TraversalMode::Search { ref pattern, .. } => {
// the unsupported case should be handled already at this point
search(shared_context, path, pattern)
search(shared_context, biome_path, pattern)
}
}
})
Expand Down
Loading
Loading