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
16 changes: 15 additions & 1 deletion crates/biome_css_parser/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::lexer::CssReLexContext;
use crate::state::CssParserState;
use crate::token_source::{CssTokenSource, CssTokenSourceCheckpoint};
use biome_css_syntax::CssSyntaxKind;
use biome_css_syntax::{CssFileSource, CssSyntaxKind};
use biome_parser::ParserContext;
use biome_parser::diagnostic::merge_diagnostics;
use biome_parser::event::Event;
Expand Down Expand Up @@ -170,3 +170,17 @@ pub struct CssParserCheckpoint {
// scoped properties that aren't only dependent on checkpoints and
// should be reset manually when the scope of their use is exited.
}

impl From<&CssFileSource> for CssParserOptions {
fn from(file_source: &CssFileSource) -> Self {
let mut options = Self::default();
if file_source.is_css_modules() {
options.css_modules = true;
}
if file_source.is_tailwind_css() {
options.tailwind_directives = true;
}

options
}
}
26 changes: 24 additions & 2 deletions crates/biome_css_syntax/src/file_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ pub struct CssFileSource {
Debug, Clone, Default, Copy, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize,
)]
#[serde(rename_all = "camelCase")]
enum CssVariant {
pub enum CssVariant {
#[default]
Standard,
/// The file is a CSS module
CssModules,
/// The file belongs to tailwind
TailwindCss,
}

impl CssFileSource {
Expand All @@ -34,6 +38,24 @@ impl CssFileSource {
}
}

pub fn tailwind_css() -> Self {
Self {
variant: CssVariant::TailwindCss,
}
}

pub fn is_css_modules(&self) -> bool {
self.variant == CssVariant::CssModules
}

pub fn is_tailwind_css(&self) -> bool {
self.variant == CssVariant::TailwindCss
}

pub fn set_variant(&mut self, variant: CssVariant) {
self.variant = variant;
}

/// Try to return the CSS file source corresponding to this file name from well-known files
pub fn try_from_well_known(_: &Utf8Path) -> Result<Self, FileSourceError> {
// TODO: to be implemented
Expand All @@ -58,7 +80,7 @@ impl CssFileSource {
pub fn try_from_language_id(language_id: &str) -> Result<Self, FileSourceError> {
match language_id {
"css" => Ok(Self::css()),
"tailwindcss" => Ok(Self::css()),
"tailwindcss" => Ok(Self::tailwind_css()),
_ => Err(FileSourceError::UnknownLanguageId),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_css_syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use self::generated::*;
pub use biome_rowan::{
SyntaxNodeText, TextLen, TextRange, TextSize, TokenAtOffset, TriviaPieceKind, WalkEvent,
};
pub use file_source::CssFileSource;
pub use file_source::{CssFileSource, CssVariant};
pub use syntax_node::*;

use crate::CssSyntaxKind::*;
Expand Down
23 changes: 23 additions & 0 deletions crates/biome_service/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use biome_configuration::bool::Bool;
use biome_configuration::max_size::MaxSize;
use biome_configuration::vcs::VcsClientKind;
use biome_configuration::{BiomeDiagnostic, Configuration, ConfigurationPathHint};
use biome_css_syntax::CssVariant;
use biome_deserialize::json::deserialize_from_json_str;
use biome_deserialize::{Deserialized, Merge};
use biome_diagnostics::print_diagnostic_to_string;
Expand Down Expand Up @@ -352,6 +353,28 @@ impl WorkspaceServer {
}
}

if let DocumentFileSource::Css(css) = &mut source {
if settings
.languages
.css
.parser
.css_modules_enabled
.unwrap_or_default()
.into()
{
css.set_variant(CssVariant::CssModules)
} else if settings
.languages
.css
.parser
.tailwind_directives
.unwrap_or_default()
.into()
{
css.set_variant(CssVariant::TailwindCss)
}
}

let (content, version) = match content {
FileContent::FromClient { content, version } => (content, Some(version)),
FileContent::FromServer => (self.fs.read_file_from_path(&path)?, None),
Expand Down
2 changes: 1 addition & 1 deletion packages/@biomejs/backend-jsonrpc/src/workspace.ts

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