|
1 | 1 | use super::{ |
2 | 2 | AnalyzerCapabilities, Capabilities, DebugCapabilities, DocumentFileSource, ExtensionHandler, |
3 | | - FormatterCapabilities, ParseResult, ParserCapabilities, SearchCapabilities, |
| 3 | + FormatterCapabilities, LintParams, LintResults, ParseResult, ParserCapabilities, |
| 4 | + SearchCapabilities, |
4 | 5 | }; |
5 | 6 | use crate::workspace::GetSyntaxTreeResult; |
6 | 7 | use crate::{ |
7 | 8 | settings::{ServiceLanguage, Settings, WorkspaceSettingsHandle}, |
8 | 9 | WorkspaceError, |
9 | 10 | }; |
10 | 11 | use biome_analyze::{AnalyzerConfiguration, AnalyzerOptions}; |
| 12 | +use biome_diagnostics::{Diagnostic, Severity}; |
11 | 13 | use biome_formatter::{IndentStyle, IndentWidth, LineEnding, LineWidth, Printed}; |
12 | 14 | use biome_fs::BiomePath; |
13 | 15 | use biome_grit_formatter::{context::GritFormatOptions, format_node}; |
14 | 16 | use biome_grit_parser::parse_grit_with_cache; |
15 | 17 | use biome_grit_syntax::{GritLanguage, GritRoot, GritSyntaxNode}; |
16 | 18 | use biome_parser::AnyParse; |
17 | 19 | use biome_rowan::NodeCache; |
| 20 | +use tracing::debug_span; |
18 | 21 |
|
19 | 22 | #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] |
20 | 23 | #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] |
@@ -118,7 +121,7 @@ impl ExtensionHandler for GritFileHandler { |
118 | 121 | debug_formatter_ir: Some(debug_formatter_ir), |
119 | 122 | }, |
120 | 123 | analyzer: AnalyzerCapabilities { |
121 | | - lint: None, |
| 124 | + lint: Some(lint), |
122 | 125 | code_actions: None, |
123 | 126 | rename: None, |
124 | 127 | fix_all: None, |
@@ -192,3 +195,23 @@ fn format( |
192 | 195 | Err(error) => Err(WorkspaceError::FormatError(error.into())), |
193 | 196 | } |
194 | 197 | } |
| 198 | + |
| 199 | +#[tracing::instrument(level = "debug", skip(params))] |
| 200 | +fn lint(params: LintParams) -> LintResults { |
| 201 | + let _ = debug_span!("Linting Grit file", path =? params.path, language =? params.language) |
| 202 | + .entered(); |
| 203 | + let diagnostics = params.parse.into_diagnostics(); |
| 204 | + |
| 205 | + let diagnostic_count = diagnostics.len() as u32; |
| 206 | + let skipped_diagnostics = diagnostic_count.saturating_sub(diagnostics.len() as u32); |
| 207 | + let errors = diagnostics |
| 208 | + .iter() |
| 209 | + .filter(|diag| diag.severity() <= Severity::Error) |
| 210 | + .count(); |
| 211 | + |
| 212 | + LintResults { |
| 213 | + diagnostics, |
| 214 | + errors, |
| 215 | + skipped_diagnostics, |
| 216 | + } |
| 217 | +} |
0 commit comments