@@ -7,6 +7,8 @@ use djls_templates::TemplateError;
77use djls_templates:: TemplateErrorAccumulator ;
88use tower_lsp_server:: lsp_types;
99
10+ use crate :: ext:: SpanExt ;
11+
1012trait DiagnosticError : std:: fmt:: Display {
1113 fn span ( & self ) -> Option < ( u32 , u32 ) > ;
1214 fn diagnostic_code ( & self ) -> & ' static str ;
@@ -18,10 +20,7 @@ trait DiagnosticError: std::fmt::Display {
1820 fn as_diagnostic ( & self , line_index : & LineIndex ) -> lsp_types:: Diagnostic {
1921 let range = self
2022 . span ( )
21- . map ( |( start, length) | {
22- let span = Span :: new ( start, length) ;
23- LspRange :: from ( ( & span, line_index) ) . into ( )
24- } )
23+ . map ( |( start, length) | Span :: new ( start, length) . to_lsp_range ( line_index) )
2524 . unwrap_or_default ( ) ;
2625
2726 lsp_types:: Diagnostic {
@@ -84,46 +83,6 @@ impl DiagnosticError for ValidationError {
8483 }
8584}
8685
87- #[ derive( Debug , Clone , Copy , PartialEq ) ]
88- #[ repr( transparent) ]
89- pub struct LspRange ( pub lsp_types:: Range ) ;
90-
91- impl From < ( & Span , & LineIndex ) > for LspRange {
92- #[ inline]
93- fn from ( ( s, line_index) : ( & Span , & LineIndex ) ) -> Self {
94- let start = LspPosition :: from ( ( s. start_offset ( ) , line_index) ) . into ( ) ;
95- let end = LspPosition :: from ( ( s. end_offset ( ) , line_index) ) . into ( ) ;
96-
97- LspRange ( lsp_types:: Range { start, end } )
98- }
99- }
100-
101- impl From < LspRange > for lsp_types:: Range {
102- #[ inline]
103- fn from ( value : LspRange ) -> Self {
104- value. 0
105- }
106- }
107-
108- #[ derive( Debug , Clone , Copy , PartialEq ) ]
109- #[ repr( transparent) ]
110- pub struct LspPosition ( pub lsp_types:: Position ) ;
111-
112- impl From < ( Offset , & LineIndex ) > for LspPosition {
113- #[ inline]
114- fn from ( ( offset, line_index) : ( Offset , & LineIndex ) ) -> Self {
115- let ( line, character) = line_index. to_line_col ( offset) . into ( ) ;
116- Self ( lsp_types:: Position { line, character } )
117- }
118- }
119-
120- impl From < LspPosition > for lsp_types:: Position {
121- #[ inline]
122- fn from ( value : LspPosition ) -> Self {
123- value. 0
124- }
125- }
126-
12786/// Collect all diagnostics for a template file.
12887///
12988/// This function collects and converts errors that were accumulated during
0 commit comments