@@ -7,20 +7,9 @@ use djls_templates::TemplateError;
77use djls_templates:: TemplateErrorAccumulator ;
88use tower_lsp_server:: lsp_types;
99
10+ use crate :: ext:: DiagnosticSeverityExt ;
1011use crate :: ext:: SpanExt ;
1112
12- /// Convert `DiagnosticSeverity` to LSP diagnostic severity.
13- /// Returns None for Off (diagnostic should not be shown).
14- fn to_lsp_severity ( severity : DiagnosticSeverity ) -> Option < lsp_types:: DiagnosticSeverity > {
15- match severity {
16- DiagnosticSeverity :: Off => None ,
17- DiagnosticSeverity :: Error => Some ( lsp_types:: DiagnosticSeverity :: ERROR ) ,
18- DiagnosticSeverity :: Warning => Some ( lsp_types:: DiagnosticSeverity :: WARNING ) ,
19- DiagnosticSeverity :: Info => Some ( lsp_types:: DiagnosticSeverity :: INFORMATION ) ,
20- DiagnosticSeverity :: Hint => Some ( lsp_types:: DiagnosticSeverity :: HINT ) ,
21- }
22- }
23-
2413trait DiagnosticError : std:: fmt:: Display {
2514 fn span ( & self ) -> Option < ( u32 , u32 ) > ;
2615 fn diagnostic_code ( & self ) -> & ' static str ;
@@ -139,7 +128,7 @@ pub fn collect_diagnostics(
139128 let severity = config. get_severity ( code) ;
140129
141130 // Skip if diagnostic is disabled (severity = off)
142- if let Some ( lsp_severity) = to_lsp_severity ( severity ) {
131+ if let Some ( lsp_severity) = severity . to_lsp_severity ( ) {
143132 diagnostic. severity = Some ( lsp_severity) ;
144133 diagnostics. push ( diagnostic) ;
145134 }
@@ -160,7 +149,7 @@ pub fn collect_diagnostics(
160149 let severity = config. get_severity ( code) ;
161150
162151 // Skip if diagnostic is disabled (severity = off)
163- if let Some ( lsp_severity) = to_lsp_severity ( severity ) {
152+ if let Some ( lsp_severity) = severity . to_lsp_severity ( ) {
164153 diagnostic. severity = Some ( lsp_severity) ;
165154 diagnostics. push ( diagnostic) ;
166155 }
@@ -180,21 +169,21 @@ mod tests {
180169
181170 #[ test]
182171 fn test_to_lsp_severity ( ) {
183- assert_eq ! ( to_lsp_severity ( DiagnosticSeverity :: Off ) , None ) ;
172+ assert_eq ! ( DiagnosticSeverity :: Off . to_lsp_severity ( ) , None ) ;
184173 assert_eq ! (
185- to_lsp_severity ( DiagnosticSeverity :: Error ) ,
174+ DiagnosticSeverity :: Error . to_lsp_severity ( ) ,
186175 Some ( lsp_types:: DiagnosticSeverity :: ERROR )
187176 ) ;
188177 assert_eq ! (
189- to_lsp_severity ( DiagnosticSeverity :: Warning ) ,
178+ DiagnosticSeverity :: Warning . to_lsp_severity ( ) ,
190179 Some ( lsp_types:: DiagnosticSeverity :: WARNING )
191180 ) ;
192181 assert_eq ! (
193- to_lsp_severity ( DiagnosticSeverity :: Info ) ,
182+ DiagnosticSeverity :: Info . to_lsp_severity ( ) ,
194183 Some ( lsp_types:: DiagnosticSeverity :: INFORMATION )
195184 ) ;
196185 assert_eq ! (
197- to_lsp_severity ( DiagnosticSeverity :: Hint ) ,
186+ DiagnosticSeverity :: Hint . to_lsp_severity ( ) ,
198187 Some ( lsp_types:: DiagnosticSeverity :: HINT )
199188 ) ;
200189 }
0 commit comments