Skip to content

Commit

Permalink
refactor: initial project layout
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Jan 6, 2025
1 parent 37296a2 commit 68da217
Show file tree
Hide file tree
Showing 50 changed files with 441 additions and 435 deletions.
48 changes: 24 additions & 24 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ biome_yaml_parser = { version = "0.0.1", path = "./crates/biome_yaml_
biome_yaml_syntax = { version = "0.0.1", path = "./crates/biome_yaml_syntax" }

biome_markup = { version = "0.5.7", path = "./crates/biome_markup" }
biome_package = { version = "0.5.7", path = "./crates/biome_package" }
biome_parser = { version = "0.5.7", path = "./crates/biome_parser" }
biome_project = { version = "0.5.7", path = "./crates/biome_project" }
biome_rowan = { version = "0.5.7", path = "./crates/biome_rowan" }
biome_string_case = { version = "0.5.7", path = "./crates/biome_string_case" }
biome_suppression = { version = "0.5.7", path = "./crates/biome_suppression" }
Expand Down
20 changes: 0 additions & 20 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,20 +635,6 @@ pub(crate) fn validate_configuration_diagnostics(
Ok(())
}

fn resolve_manifest(fs: &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 {
return Ok(Some((BiomePath::new(result.file_path), result.content)));
}

Ok(None)
}

fn get_files_to_process_with_cli_options(
since: Option<&str>,
changed: bool,
Expand Down Expand Up @@ -774,7 +760,6 @@ pub(crate) trait CommandRunner: Sized {
/// - Configure the VCS integration
/// - Computes the paths to traverse/handle. This changes based on the VCS arguments that were passed.
/// - Register a project folder using the working directory.
/// - Resolves the closets manifest AKA `package.json` and registers it.
/// - Updates the settings that belong to the project registered
fn configure_workspace(
&mut self,
Expand Down Expand Up @@ -807,11 +792,6 @@ pub(crate) trait CommandRunner: Sized {
open_uninitialized: true,
})?;

let manifest_data = resolve_manifest(fs)?;

if let Some((path, content)) = manifest_data {
workspace.set_manifest_for_project((project_key, path, content).into())?;
}
workspace.update_settings(UpdateSettingsParams {
project_key,
workspace_directory: configuration_path.map(BiomePath::from),
Expand Down
8 changes: 7 additions & 1 deletion crates/biome_fs/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use crossbeam::channel::{unbounded, Receiver, Sender};
use papaya::HashSet;
use rustc_hash::FxBuildHasher;

pub type PathInternerSet = HashSet<Utf8PathBuf, FxBuildHasher>;

/// File paths interner cache
///
/// The path interner stores an instance of [PathBuf]
pub struct PathInterner {
storage: HashSet<Utf8PathBuf, FxBuildHasher>,
storage: PathInternerSet,
handler: Sender<Utf8PathBuf>,
}

Expand All @@ -32,4 +34,8 @@ impl PathInterner {
}
result
}

pub fn into_paths(self) -> PathInternerSet {
self.storage
}
}
2 changes: 1 addition & 1 deletion crates/biome_fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ pub use fs::{
FileSystemExt, FsErrorKind, MemoryFileSystem, OpenOptions, OsFileSystem, TraversalContext,
TraversalScope,
};
pub use interner::PathInterner;
pub use interner::{PathInterner, PathInternerSet};
pub use path::BiomePath;
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ biome_glob = { workspace = true, features = ["biome_deserialize",
biome_js_factory = { workspace = true }
biome_js_semantic = { workspace = true }
biome_js_syntax = { workspace = true }
biome_project = { workspace = true }
biome_package = { workspace = true }
biome_rowan = { workspace = true }
biome_string_case = { workspace = true }
biome_suppression = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use biome_analyze::{
use biome_aria::AriaRoles;
use biome_diagnostics::Error as DiagnosticError;
use biome_js_syntax::{JsFileSource, JsLanguage};
use biome_project::PackageJson;
use biome_package::PackageJson;
use biome_rowan::TextRange;
use biome_suppression::{parse_suppression_comment, SuppressionDiagnostic};
use std::ops::Deref;
Expand Down Expand Up @@ -164,7 +164,7 @@ mod tests {
use biome_diagnostics::{print_diagnostic_to_string, Diagnostic, DiagnosticExt, Severity};
use biome_js_parser::{parse, JsParserOptions};
use biome_js_syntax::{JsFileSource, TextRange, TextSize};
use biome_project::{Dependencies, PackageJson};
use biome_package::{Dependencies, PackageJson};
use std::slice;

use crate::{analyze, AnalysisFilter, ControlFlow};
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/services/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use biome_analyze::{
RuleKey, ServiceBag, SyntaxVisitor,
};
use biome_js_syntax::{AnyJsRoot, JsLanguage, JsSyntaxNode};
use biome_project::PackageJson;
use biome_package::PackageJson;
use biome_rowan::AstNode;
use std::sync::Arc;

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/tests/spec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use biome_fs::OsFileSystem;
use biome_js_parser::{parse, JsParserOptions};
use biome_js_syntax::{JsFileSource, JsLanguage, ModuleKind};
use biome_plugin_loader::AnalyzerGritPlugin;
use biome_project::PackageType;
use biome_package::PackageType;
use biome_rowan::AstNode;
use biome_test_utils::{
assert_errors_are_absent, code_fix_to_string, create_analyzer_options, diagnostic_to_string,
Expand Down
18 changes: 11 additions & 7 deletions crates/biome_lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ impl LanguageServer for LSPServer {
futures::join!(
self.session.load_extension_settings(),
self.session.load_workspace_settings(),
self.session.load_manifest()
);

let msg = format!("Server initialized with PID: {}", std::process::id());
Expand Down Expand Up @@ -323,14 +322,13 @@ impl LanguageServer for LSPServer {
Ok(file_path) => {
let base_path = self.session.base_path();
if let Some(base_path) = base_path {
let possible_rome_json = file_path.strip_prefix(&base_path);
if let Ok(watched_file) = possible_rome_json {
let possible_biome_json = file_path.strip_prefix(&base_path);
if let Ok(watched_file) = possible_biome_json {
if ConfigName::file_names()
.contains(&&*watched_file.display().to_string())
|| watched_file.ends_with(".editorconfig")
{
self.session.load_workspace_settings().await;
self.session.load_manifest().await;
self.setup_capabilities().await;
self.session.update_all_diagnostics().await;
// for now we are only interested to the configuration file,
Expand Down Expand Up @@ -403,10 +401,17 @@ impl LanguageServer for LSPServer {

match result {
Ok(project_key) => {
self.session.insert_project(project_path, project_key);
self.session
.insert_project(project_path.clone(), project_key);

self.session
.scan_project_folder(project_key, project_path)
.await;

self.session.update_all_diagnostics().await;
}
Err(err) => {
error!("Failed to add project to the workspace: {}", err);
error!("Failed to add project to the workspace: {err}");
self.session
.client
.log_message(MessageType::ERROR, err)
Expand Down Expand Up @@ -622,7 +627,6 @@ impl ServerFactory {
workspace_method!(builder, scan_project_folder);
workspace_method!(builder, close_project);
workspace_method!(builder, open_file);
workspace_method!(builder, set_manifest_for_project);
workspace_method!(builder, get_syntax_tree);
workspace_method!(builder, get_control_flow_graph);
workspace_method!(builder, get_formatter_ir);
Expand Down
Loading

0 comments on commit 68da217

Please sign in to comment.