Skip to content
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
9 changes: 9 additions & 0 deletions .changeset/six-corners-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@biomejs/biome": minor
---

Added new functions to the `@biomejs/wasm-*` packages:
- `fileExists`: returns whether the input file exists in the workspace.
- `isPathIgnored`: returns whether the input path is ignored.
- `updateModuleGraph`: updates the internal module graph of the input path.
- `getModuleGraph`: it returns a serialized version of the internal module graph.
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use biome_fs::{BiomePath, FileSystem, PathInterner};
use biome_fs::{TraversalContext, TraversalScope};
use biome_service::projects::ProjectKey;
use biome_service::workspace::{
DocumentFileSource, DropPatternParams, FileFeaturesResult, IgnoreKind, IsPathIgnoredParams,
DocumentFileSource, DropPatternParams, FileFeaturesResult, IgnoreKind, PathIsIgnoredParams,
};
use biome_service::{Workspace, WorkspaceError, extension_error, workspace::SupportsFeatureParams};
use camino::{Utf8Path, Utf8PathBuf};
Expand Down Expand Up @@ -537,7 +537,7 @@ impl TraversalContext for TraversalOptions<'_, '_> {
// Note that `symlink/subdir` is not an existing file.
let can_handle = !self
.workspace
.is_path_ignored(IsPathIgnoredParams {
.is_path_ignored(PathIsIgnoredParams {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to rename this type because the initial I was in conflict with the WASM types, which all start with I

project_key: self.project_key,
path: biome_path.clone(),
features: self.execution.to_feature(),
Expand Down
8 changes: 4 additions & 4 deletions crates/biome_lsp/src/handlers/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use biome_service::WorkspaceError;
use biome_service::file_handlers::{AstroFileHandler, SvelteFileHandler, VueFileHandler};
use biome_service::workspace::{
CheckFileSizeParams, FeaturesBuilder, FileFeaturesResult, FixFileMode, FixFileParams,
GetFileContentParams, IgnoreKind, IsPathIgnoredParams, PullActionsParams,
GetFileContentParams, IgnoreKind, PathIsIgnoredParams, PullActionsParams,
SupportsFeatureParams,
};
use std::borrow::Cow;
Expand Down Expand Up @@ -62,7 +62,7 @@ pub(crate) fn code_actions(
return Ok(None);
}

if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand Down Expand Up @@ -309,7 +309,7 @@ fn fix_all(
return Ok(None);
}

if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features: analyzer_features,
Expand All @@ -331,7 +331,7 @@ fn fix_all(
})?;
let should_format = file_features.supports_format();

if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features: analyzer_features,
Expand Down
14 changes: 7 additions & 7 deletions crates/biome_lsp/src/handlers/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use biome_rowan::{TextLen, TextRange, TextSize};
use biome_service::file_handlers::{AstroFileHandler, SvelteFileHandler, VueFileHandler};
use biome_service::workspace::{
CheckFileSizeParams, FeaturesBuilder, FeaturesSupported, FileFeaturesResult, FormatFileParams,
FormatOnTypeParams, FormatRangeParams, GetFileContentParams, IgnoreKind, IsPathIgnoredParams,
FormatOnTypeParams, FormatRangeParams, GetFileContentParams, IgnoreKind, PathIsIgnoredParams,
SupportsFeatureParams,
};
use biome_service::{WorkspaceError, extension_error};
Expand All @@ -30,7 +30,7 @@ pub(crate) fn format(
}
let features = FeaturesBuilder::new().with_formatter().build();

if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand All @@ -48,7 +48,7 @@ pub(crate) fn format(
})?;

if file_features.supports_format()
&& !session.workspace.is_path_ignored(IsPathIgnoredParams {
&& !session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand Down Expand Up @@ -114,7 +114,7 @@ pub(crate) fn format_range(
}
let features = FeaturesBuilder::new().with_formatter().build();

if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand All @@ -133,7 +133,7 @@ pub(crate) fn format_range(
})?;

if file_features.supports_format()
&& !session.workspace.is_path_ignored(IsPathIgnoredParams {
&& !session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand Down Expand Up @@ -230,7 +230,7 @@ pub(crate) fn format_on_type(
features,
})?;

if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand All @@ -240,7 +240,7 @@ pub(crate) fn format_on_type(
}

if file_features.supports_format()
&& !session.workspace.is_path_ignored(IsPathIgnoredParams {
&& !session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_lsp/src/handlers/text_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{documents::Document, session::Session};
use biome_fs::BiomePath;
use biome_service::workspace::{
ChangeFileParams, CloseFileParams, DocumentFileSource, FeaturesBuilder, FileContent,
GetFileContentParams, IgnoreKind, IsPathIgnoredParams, OpenFileParams, OpenProjectParams,
GetFileContentParams, IgnoreKind, OpenFileParams, OpenProjectParams, PathIsIgnoredParams,
ScanKind,
};
use tower_lsp_server::lsp_types;
Expand Down Expand Up @@ -60,7 +60,7 @@ pub(crate) async fn did_open(

let is_ignored = session
.workspace
.is_path_ignored(IsPathIgnoredParams {
.is_path_ignored(PathIsIgnoredParams {
project_key,
path: path.clone(),
features: FeaturesBuilder::new().build(),
Expand Down Expand Up @@ -108,7 +108,7 @@ pub(crate) async fn did_change(
return Ok(());
}
let features = FeaturesBuilder::new().build();
if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_lsp/src/requests/syntax_tree.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{diagnostics::LspError, session::Session};
use biome_service::workspace::{
FeaturesBuilder, GetSyntaxTreeParams, IgnoreKind, IsPathIgnoredParams,
FeaturesBuilder, GetSyntaxTreeParams, IgnoreKind, PathIsIgnoredParams,
};
use serde::{Deserialize, Serialize};
use tower_lsp_server::lsp_types::{TextDocumentIdentifier, Uri};
Expand All @@ -22,7 +22,7 @@ pub(crate) fn syntax_tree(session: &Session, url: &Uri) -> Result<Option<String>
};
let features = FeaturesBuilder::new().build();

if session.workspace.is_path_ignored(IsPathIgnoredParams {
if session.workspace.is_path_ignored(PathIsIgnoredParams {
path: path.clone(),
project_key: doc.project_key,
features,
Expand Down
8 changes: 7 additions & 1 deletion crates/biome_module_graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ biome_rowan = { workspace = true }
camino = { workspace = true }
cfg-if = { workspace = true }
indexmap = { workspace = true }
once_cell = "1.21.3" # Use `std::sync::OnceLock::get_or_try_init` when it is stable.
once_cell = "1.21.3" # Use `std::sync::OnceLock::get_or_try_init` when it is stable.
papaya = { workspace = true }
rust-lapper = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true }
static_assertions = { workspace = true }

Expand All @@ -51,6 +53,10 @@ mimalloc = { workspace = true }
[target.'cfg(all(target_family="unix", not(all(target_arch = "aarch64", target_env = "musl"))))'.dev-dependencies]
tikv-jemallocator = { workspace = true }

[features]
schema = ["dep:schemars"]
serde = ["dep:serde"]

[[bench]]
harness = false
name = "module_graph"
42 changes: 39 additions & 3 deletions crates/biome_module_graph/src/js_module_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ mod collector;
mod module_resolver;
mod scope;
mod visitor;

use std::{ops::Deref, sync::Arc};

use biome_js_syntax::AnyJsImportLike;
use biome_js_type_info::{BindingId, ImportSymbol, ResolvedTypeId, ScopeId, TypeData};
use biome_jsdoc_comment::JsdocComment;
Expand All @@ -14,6 +11,8 @@ use biome_rowan::{Text, TextRange};
use indexmap::IndexMap;
use rust_lapper::Lapper;
use rustc_hash::FxHashMap;
use std::collections::BTreeSet;
use std::{collections::BTreeMap, ops::Deref, sync::Arc};

use crate::ModuleGraph;

Expand Down Expand Up @@ -82,6 +81,31 @@ impl JsModuleInfo {
id: scope_id_for_range(&self.0.scope_by_range, range),
}
}

/// Returns a serializable version of this module
pub fn dump(&self) -> SerializedJsModuleInfo {
SerializedJsModuleInfo {
static_imports: self
.static_imports
.iter()
.map(|(text, static_import)| {
(text.to_string(), static_import.specifier.to_string())
})
.collect::<BTreeMap<_, _>>(),

exports: self
.exports
.iter()
.map(|(text, _)| text.to_string())
.collect::<BTreeSet<_>>(),

dynamic_imports: self
.dynamic_import_paths
.iter()
.map(|(text, _)| text.to_string())
.collect::<BTreeSet<_>>(),
}
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -345,3 +369,15 @@ fn scope_id_for_range(scope_by_range: &Lapper<u32, ScopeId>, range: TextRange) -
ScopeId::new(interval.val.index())
})
}

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SerializedJsModuleInfo {
/// Static imports
static_imports: BTreeMap<String, String>,
/// Dynamic imports
dynamic_imports: BTreeSet<String>,
/// Exported symbols
exports: BTreeSet<String>,
}
1 change: 1 addition & 0 deletions crates/biome_module_graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ pub use biome_resolver::ResolvedPath;

pub use js_module_info::{
JsExport, JsImport, JsModuleInfo, JsOwnExport, JsReexport, ModuleResolver,
SerializedJsModuleInfo,
};
pub use module_graph::{ModuleGraph, SUPPORTED_EXTENSIONS};
3 changes: 2 additions & 1 deletion crates/biome_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ biome_json_analyze = { workspace = true }
biome_json_formatter = { workspace = true, features = ["serde"] }
biome_json_parser = { workspace = true }
biome_json_syntax = { workspace = true }
biome_module_graph = { workspace = true }
biome_module_graph = { workspace = true, features = ["serde"] }
biome_package = { workspace = true }
biome_parser = { workspace = true }
biome_plugin_loader = { workspace = true }
Expand Down Expand Up @@ -95,6 +95,7 @@ schema = [
"biome_html_syntax/schema",
"biome_html_formatter/schema",
"biome_fs/schema",
"biome_module_graph/schema",
]

[lints]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/biome_service/src/workspace.tests.rs
expression: result
---
GetModuleGraphResult {
data: {
"/project/utils.js": SerializedJsModuleInfo {
static_imports: {},
dynamic_imports: {},
exports: {
"debounce",
"filter",
},
},
"/project/dynamic.js": SerializedJsModuleInfo {
static_imports: {},
dynamic_imports: {},
exports: {
"squash",
},
},
"/project/file.js": SerializedJsModuleInfo {
static_imports: {
"debounce": "./utils.js",
"filter": "./utils.js",
},
dynamic_imports: {
"./dynamic.js",
},
exports: {},
},
},
}
Loading