Skip to content

Commit

Permalink
fix(grit): linting inside workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 6, 2024
1 parent 931960e commit 150f3b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
27 changes: 25 additions & 2 deletions crates/biome_service/src/file_handlers/grit.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use super::{
AnalyzerCapabilities, Capabilities, DebugCapabilities, DocumentFileSource, ExtensionHandler,
FormatterCapabilities, ParseResult, ParserCapabilities, SearchCapabilities,
FormatterCapabilities, LintParams, LintResults, ParseResult, ParserCapabilities,
SearchCapabilities,
};
use crate::workspace::GetSyntaxTreeResult;
use crate::{
settings::{ServiceLanguage, Settings, WorkspaceSettingsHandle},
WorkspaceError,
};
use biome_analyze::{AnalyzerConfiguration, AnalyzerOptions};
use biome_diagnostics::{Diagnostic, Severity};
use biome_formatter::{IndentStyle, IndentWidth, LineEnding, LineWidth, Printed};
use biome_fs::BiomePath;
use biome_grit_formatter::{context::GritFormatOptions, format_node};
use biome_grit_parser::parse_grit_with_cache;
use biome_grit_syntax::{GritLanguage, GritRoot, GritSyntaxNode};
use biome_parser::AnyParse;
use biome_rowan::NodeCache;
use tracing::debug_span;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
Expand Down Expand Up @@ -118,7 +121,7 @@ impl ExtensionHandler for GritFileHandler {
debug_formatter_ir: Some(debug_formatter_ir),
},
analyzer: AnalyzerCapabilities {
lint: None,
lint: Some(lint),
code_actions: None,
rename: None,
fix_all: None,
Expand Down Expand Up @@ -192,3 +195,23 @@ fn format(
Err(error) => Err(WorkspaceError::FormatError(error.into())),
}
}

#[tracing::instrument(level = "debug", skip(params))]
fn lint(params: LintParams) -> LintResults {
let _ = debug_span!("Linting Grit file", path =? params.path, language =? params.language)
.entered();
let diagnostics = params.parse.into_diagnostics();

let diagnostic_count = diagnostics.len() as u32;
let skipped_diagnostics = diagnostic_count.saturating_sub(diagnostics.len() as u32);
let errors = diagnostics
.iter()
.filter(|diag| diag.severity() <= Severity::Error)
.count();

LintResults {
diagnostics,
errors,
skipped_diagnostics,
}
}
1 change: 0 additions & 1 deletion crates/biome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ impl DocumentFileSource {
if let Ok(file_source) = HtmlFileSource::try_from_extension(extension) {
return Ok(file_source.into());
}

if let Ok(file_source) = GritFileSource::try_from_extension(extension) {
return Ok(file_source.into());
}
Expand Down

0 comments on commit 150f3b0

Please sign in to comment.