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

feat: add additional FeatureKind entries for debug features #3892

Merged
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.

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
38 changes: 37 additions & 1 deletion 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 @@ -119,12 +120,13 @@ impl FileFeaturesResult {
}

/// By default, all features are not supported by a file.
const WORKSPACE_FEATURES: [(FeatureKind, SupportKind); 5] = [
const WORKSPACE_FEATURES: [(FeatureKind, SupportKind); 6] = [
(FeatureKind::Lint, SupportKind::FileNotSupported),
(FeatureKind::Format, SupportKind::FileNotSupported),
(FeatureKind::OrganizeImports, SupportKind::FileNotSupported),
(FeatureKind::Search, SupportKind::FileNotSupported),
(FeatureKind::Assists, SupportKind::FileNotSupported),
(FeatureKind::Debug, SupportKind::FileNotSupported),
];

pub fn new() -> Self {
Expand Down Expand Up @@ -157,6 +159,14 @@ impl FileFeaturesResult {
.insert(FeatureKind::Search, SupportKind::Supported);
}

if capabilities.debug.debug_syntax_tree.is_some()
|| capabilities.debug.debug_formatter_ir.is_some()
|| capabilities.debug.debug_control_flow.is_some()
{
self.features_supported
.insert(FeatureKind::Debug, SupportKind::Supported);
}

self
}

Expand Down Expand Up @@ -402,9 +412,14 @@ pub enum FeatureKind {
OrganizeImports,
Search,
Assists,
Debug,
}

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

impl FeatureName {
Expand All @@ -414,6 +429,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; 6]>> for FeatureName {
fn from(value: SmallVec<[FeatureKind; 6]>) -> Self {
value
.into_iter()
.fold(FeatureName::empty(), |mut acc, kind| {
acc.insert(kind);
acc
})
}
}

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

#[cfg(feature = "schema")]
Expand Down
1 change: 1 addition & 0 deletions crates/biome_service/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ impl WorkspaceServer {
}
// TODO: enable once the configuration is available
FeatureKind::Search => return false, // There is no search-specific config.
FeatureKind::Debug => return false,
};
let is_feature_included = feature_included_files.is_empty()
|| is_dir(path)
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_service/src/workspace_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ macro_rules! workspace_method {
/// Returns a list of signature for all the methods in the [Workspace] trait
pub fn methods() -> [WorkspaceMethod; 19] {
[
WorkspaceMethod::of::<SupportsFeatureParams, SupportsFeatureResult>("file_features"),
workspace_method!(file_features),
workspace_method!(update_settings),
workspace_method!(register_project_folder),
workspace_method!(set_manifest_for_project),
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ impl Workspace {
pub fn file_features(
&self,
params: ISupportsFeatureParams,
) -> Result<ISupportsFeatureResult, Error> {
) -> Result<IFileFeaturesResult, Error> {
let params: SupportsFeatureParams =
serde_wasm_bindgen::from_value(params.into()).map_err(into_error)?;
let result = self.inner.file_features(params).map_err(into_error)?;
to_value(&result)
.map(ISupportsFeatureResult::from)
.map(IFileFeaturesResult::from)
.map_err(into_error)
}

Expand Down
17 changes: 6 additions & 11 deletions packages/@biomejs/backend-jsonrpc/src/workspace.ts

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

Loading