Skip to content

Commit 02ee2bb

Browse files
committed
don't use bitflag for biome path
1 parent 05db693 commit 02ee2bb

File tree

6 files changed

+22
-215
lines changed

6 files changed

+22
-215
lines changed

crates/biome_cli/src/execute/traverse.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use biome_diagnostics::DiagnosticTags;
1010
use biome_diagnostics::{DiagnosticExt, Error, Resource, Severity, category};
1111
use biome_fs::{BiomePath, FileSystem, PathInterner};
1212
use biome_fs::{TraversalContext, TraversalScope};
13-
use biome_service::dome::Dome;
1413
use biome_service::projects::ProjectKey;
1514
use biome_service::workspace::{DocumentFileSource, DropPatternParams, IsPathIgnoredParams};
1615
use biome_service::{Workspace, WorkspaceError, extension_error, workspace::SupportsFeatureParams};

crates/biome_fs/src/path.rs

Lines changed: 22 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,24 @@
55
//! - shortcuts to open/write to the file
66
use crate::ConfigName;
77
use camino::{Utf8Path, Utf8PathBuf};
8-
use enumflags2::{BitFlags, bitflags};
9-
use smallvec::SmallVec;
108
use std::borrow::Cow;
119
use std::cmp::Ordering;
1210
use std::fmt::{Debug, Formatter};
1311
use std::fs::read_to_string;
1412
use std::hash::Hash;
15-
use std::ops::DerefMut;
1613
use std::path::{Path, PathBuf};
1714
use std::{fs::File, io, io::Write, ops::Deref};
1815

1916
/// The priority of the file
17+
// NOTE: The order of the variants is important, the one on the top has the highest priority
2018
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Ord, PartialOrd, Hash)]
21-
#[repr(u8)]
22-
#[bitflags]
2319
#[cfg_attr(
2420
feature = "serde",
2521
derive(serde::Serialize, serde::Deserialize),
2622
serde(rename_all = "camelCase")
2723
)]
2824
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
29-
// NOTE: The order of the variants is important, the one on the top has the highest priority
30-
pub enum FileKind {
25+
pub enum FileKinds {
3126
/// A configuration file has the highest priority. It's usually `biome.json` and `biome.jsonc`
3227
///
3328
/// Other third-party configuration files might be added in the future
@@ -47,71 +42,8 @@ pub enum FileKind {
4742
Handleable,
4843
}
4944

50-
#[derive(Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Default)]
51-
#[cfg_attr(
52-
feature = "serde",
53-
derive(serde::Serialize, serde::Deserialize),
54-
serde(
55-
from = "smallvec::SmallVec<[FileKind; 5]>",
56-
into = "smallvec::SmallVec<[FileKind; 5]>"
57-
)
58-
)]
59-
pub struct FileKinds(BitFlags<FileKind>);
60-
61-
impl From<SmallVec<[FileKind; 5]>> for FileKinds {
62-
fn from(value: SmallVec<[FileKind; 5]>) -> Self {
63-
value.into_iter().fold(Self::default(), |mut acc, kind| {
64-
acc.insert(kind);
65-
acc
66-
})
67-
}
68-
}
69-
70-
impl Debug for FileKinds {
71-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
72-
let mut list = f.debug_list();
73-
for kind in self.iter() {
74-
match kind {
75-
FileKind::Config => list.entry(&"Config"),
76-
FileKind::Manifest => list.entry(&"Manifest"),
77-
FileKind::Ignore => list.entry(&"Ignore"),
78-
FileKind::Inspectable => list.entry(&"Inspectable"),
79-
FileKind::Handleable => list.entry(&"Handleable"),
80-
FileKind::Directory => list.entry(&"Directory"),
81-
};
82-
}
83-
list.finish()
84-
}
85-
}
86-
87-
impl From<FileKinds> for SmallVec<[FileKind; 5]> {
88-
fn from(value: FileKinds) -> Self {
89-
value.iter().collect()
90-
}
91-
}
92-
93-
impl Deref for FileKinds {
94-
type Target = BitFlags<FileKind>;
95-
96-
fn deref(&self) -> &Self::Target {
97-
&self.0
98-
}
99-
}
100-
101-
impl DerefMut for FileKinds {
102-
fn deref_mut(&mut self) -> &mut Self::Target {
103-
&mut self.0
104-
}
105-
}
106-
107-
impl From<FileKind> for FileKinds {
108-
fn from(flag: FileKind) -> Self {
109-
Self(BitFlags::from(flag))
110-
}
111-
}
112-
11345
/// This is an internal representation of a path inside the Biome daemon.
114-
/// This type has its own [Ord] implementation driven by its [FileKind], where certain files must be inspected
46+
/// This type has its own [Ord] implementation driven by its [FileKinds], where certain files must be inspected
11547
/// before others. For example, configuration files and ignore files must have priority over other files.
11648
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
11749
pub struct BiomePath {
@@ -127,7 +59,7 @@ impl BiomePath {
12759
pub fn new(path_to_file: impl Into<Utf8PathBuf>) -> Self {
12860
let path = path_to_file.into();
12961
let kind = if path.is_dir() {
130-
FileKind::Directory.into()
62+
FileKinds::Directory
13163
} else {
13264
path.file_name().map(Self::priority).unwrap_or_default()
13365
};
@@ -152,7 +84,7 @@ impl BiomePath {
15284
pub fn to_written(&self) -> Self {
15385
Self {
15486
path: self.path.clone(),
155-
kind: self.kind.clone(),
87+
kind: self.kind,
15688
was_written: true,
15789
}
15890
}
@@ -189,41 +121,41 @@ impl BiomePath {
189121
/// - Other files are considered as files to handle
190122
fn priority(file_name: &str) -> FileKinds {
191123
if file_name == ConfigName::biome_json() || file_name == ConfigName::biome_jsonc() {
192-
FileKind::Config.into()
124+
FileKinds::Config
193125
} else if matches!(
194126
file_name,
195127
"package.json" | "tsconfig.json" | "jsconfig.json"
196128
) {
197-
FileKind::Manifest.into()
129+
FileKinds::Manifest
198130
} else if matches!(file_name, ".gitignore" | ".ignore") {
199-
FileKind::Ignore.into()
131+
FileKinds::Ignore
200132
} else {
201-
FileKind::Handleable.into()
133+
FileKinds::Handleable
202134
}
203135
}
204136

205137
#[inline(always)]
206138
pub fn is_config(&self) -> bool {
207-
self.kind.contains(FileKind::Config)
139+
matches!(self.kind, FileKinds::Config)
208140
}
209141

210142
#[inline(always)]
211143
pub fn is_manifest(&self) -> bool {
212-
self.kind.contains(FileKind::Manifest)
144+
matches!(self.kind, FileKinds::Manifest)
213145
}
214146

215147
#[inline(always)]
216148
pub fn is_ignore(&self) -> bool {
217-
self.kind.contains(FileKind::Ignore)
149+
matches!(self.kind, FileKinds::Ignore)
218150
}
219151

220152
#[inline(always)]
221153
pub fn is_dir(&self) -> bool {
222-
self.kind.contains(FileKind::Directory)
154+
matches!(self.kind, FileKinds::Directory)
223155
}
224156
#[inline(always)]
225157
pub fn is_handleable(&self) -> bool {
226-
self.kind.contains(FileKind::Handleable)
158+
matches!(self.kind, FileKinds::Handleable)
227159
}
228160

229161
/// Returns `true` if the path is inside `node_modules`
@@ -323,17 +255,6 @@ impl schemars::JsonSchema for BiomePath {
323255
}
324256
}
325257

326-
#[cfg(feature = "schema")]
327-
impl schemars::JsonSchema for FileKinds {
328-
fn schema_name() -> String {
329-
String::from("FileKind")
330-
}
331-
332-
fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
333-
<Vec<FileKind>>::json_schema(generator)
334-
}
335-
}
336-
337258
impl From<BiomePath> for Utf8PathBuf {
338259
fn from(path: BiomePath) -> Self {
339260
path.path
@@ -357,7 +278,7 @@ impl Ord for BiomePath {
357278

358279
#[cfg(test)]
359280
mod test {
360-
use crate::path::{FileKind, FileKinds};
281+
use crate::path::FileKinds;
361282

362283
#[test]
363284
fn test_biome_paths() {
@@ -367,14 +288,11 @@ mod test {
367288
let path = Utf8PathBuf::from("src/package.json");
368289
let biome_path = BiomePath::new(path);
369290
assert_eq!(biome_path.file_name(), Some("package.json"));
370-
assert_eq!(
371-
BiomePath::priority("package.json"),
372-
FileKind::Manifest.into()
373-
);
374-
assert_eq!(BiomePath::priority("biome.json"), FileKind::Config.into());
375-
assert_eq!(BiomePath::priority("biome.jsonc"), FileKind::Config.into());
376-
assert_eq!(BiomePath::priority(".gitignore"), FileKind::Ignore.into());
377-
assert_eq!(BiomePath::priority(".ignore"), FileKind::Ignore.into());
291+
assert_eq!(BiomePath::priority("package.json"), FileKinds::Manifest);
292+
assert_eq!(BiomePath::priority("biome.json"), FileKinds::Config);
293+
assert_eq!(BiomePath::priority("biome.jsonc"), FileKinds::Config);
294+
assert_eq!(BiomePath::priority(".gitignore"), FileKinds::Ignore);
295+
assert_eq!(BiomePath::priority(".ignore"), FileKinds::Ignore);
378296
}
379297

380298
#[test]
@@ -434,13 +352,13 @@ mod test {
434352
let result = serde_json::from_str::<FileKinds>("[\"config\"]");
435353
assert!(result.is_ok());
436354
let file_kinds = result.unwrap();
437-
assert!(file_kinds.contains(FileKind::Config));
355+
assert_eq!(file_kinds, FileKinds::Config);
438356
}
439357

440358
#[test]
441359
#[cfg(feature = "serde")]
442360
fn serialize_file_kind_into_vec() {
443-
let file_kinds = FileKinds::from(FileKind::Config);
361+
let file_kinds = FileKinds::Config;
444362
let result = serde_json::to_string(&file_kinds);
445363
assert!(result.is_ok());
446364
assert_eq!(result.unwrap(), "[\"config\"]");

crates/biome_service/src/dome.rs

Lines changed: 0 additions & 105 deletions
This file was deleted.

crates/biome_service/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod workspace_watcher;
1010

1111
pub mod configuration;
1212
pub mod diagnostics;
13-
pub mod dome;
1413
#[cfg(feature = "schema")]
1514
pub mod workspace_types;
1615

crates/biome_service/src/workspace/scanner.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use super::server::WorkspaceServer;
1212
use super::{FeaturesBuilder, IsPathIgnoredParams};
1313
use crate::diagnostics::Panic;
14-
use crate::dome::Dome;
1514
use crate::projects::ProjectKey;
1615
use crate::workspace::DocumentFileSource;
1716
use crate::{Workspace, WorkspaceError};
@@ -99,9 +98,7 @@ fn scan_folder(folder: &Utf8Path, ctx: ScanContext) -> (Duration, Vec<BiomePath>
9998
scope.evaluate(ctx_ref, folder.to_path_buf());
10099
}));
101100

102-
let interner = ctx.interner();
103101
let evaluated_paths = ctx.evaluated_paths();
104-
105102
let mut configs = Vec::new();
106103
let mut manifests = Vec::new();
107104
let mut handleable_paths = Vec::new();

crates/biome_service/src/workspace/server.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ impl WorkspaceServer {
216216
}
217217

218218
/// Gets the supported capabilities for a given file path.
219-
220219
fn get_file_capabilities(&self, path: &BiomePath) -> Capabilities {
221220
let language = self.get_file_source(path);
222221
self.features.get_capabilities(language)

0 commit comments

Comments
 (0)