Skip to content

Commit

Permalink
feat: add additional FeatureKind entries for debug features
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Sep 14, 2024
1 parent 12688b6 commit 109e6ab
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
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.

1 change: 1 addition & 0 deletions crates/biome_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ schemars = { workspace = true, features = ["indexmap1"], optiona
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["raw_value"] }
slotmap = { workspace = true, features = ["serde"] }
smallvec = { workspace = true, features = ["serde"] }
tracing = { workspace = true, features = ["attributes", "log"] }

[features]
Expand Down
44 changes: 44 additions & 0 deletions crates/biome_service/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use enumflags2::{bitflags, BitFlags};
#[cfg(feature = "schema")]
use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
use slotmap::{new_key_type, DenseSlotMap};
use smallvec::SmallVec;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::{borrow::Cow, panic::RefUnwindSafe, sync::Arc};
Expand Down Expand Up @@ -157,6 +158,21 @@ impl FileFeaturesResult {
.insert(FeatureKind::Search, SupportKind::Supported);
}

if capabilities.debug.debug_syntax_tree.is_some() {
self.features_supported
.insert(FeatureKind::SyntaxTree, SupportKind::Supported);
}

if capabilities.debug.debug_formatter_ir.is_some() {
self.features_supported
.insert(FeatureKind::FormatterIr, SupportKind::Supported);
}

if capabilities.debug.debug_control_flow.is_some() {
self.features_supported
.insert(FeatureKind::ControlFlowGraph, SupportKind::Supported);
}

self
}

Expand Down Expand Up @@ -403,9 +419,16 @@ pub enum FeatureKind {
OrganizeImports,
Search,
Assists,
SyntaxTree,
FormatterIr,
ControlFlowGraph,
}

#[derive(Debug, Copy, Clone, Hash, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
#[serde(
from = "smallvec::SmallVec<[FeatureKind; 8]>",
into = "smallvec::SmallVec<[FeatureKind; 8]>"
)]
pub struct FeatureName(BitFlags<FeatureKind>);

impl FeatureName {
Expand All @@ -415,6 +438,27 @@ impl FeatureName {
pub fn empty() -> Self {
Self(BitFlags::empty())
}

pub fn insert(&mut self, kind: FeatureKind) {
self.0.insert(kind);
}
}

impl From<SmallVec<[FeatureKind; 8]>> for FeatureName {
fn from(value: SmallVec<[FeatureKind; 8]>) -> Self {
value
.into_iter()
.fold(FeatureName::empty(), |mut acc, kind| {
acc.insert(kind);
acc
})
}
}

impl From<FeatureName> for SmallVec<[FeatureKind; 8]> {
fn from(value: FeatureName) -> Self {
value.iter().collect()
}
}

#[cfg(feature = "schema")]
Expand Down
6 changes: 6 additions & 0 deletions crates/biome_service/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ impl WorkspaceServer {
}
// TODO: enable once the configuration is available
FeatureKind::Search => return false, // There is no search-specific config.
FeatureKind::FormatterIr => {
let formatter_ir = &settings.formatter;
(&formatter_ir.included_files, &formatter_ir.ignored_files)
}
FeatureKind::ControlFlowGraph => return false,
FeatureKind::SyntaxTree => return false,
};
let is_feature_included = feature_included_files.is_empty()
|| is_dir(path)
Expand Down

0 comments on commit 109e6ab

Please sign in to comment.