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

fix(grit): linting inside workspace #4477

Merged
merged 1 commit into from
Nov 6, 2024
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
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