@@ -115,45 +115,51 @@ function filterAndAugmentDiagnostics(
115
115
return diagnostics ;
116
116
}
117
117
118
- let cachedTransformedModule : TransformedModule | null | undefined = undefined ;
119
-
120
- const mappingForDiagnostic = ( diagnostic : vscode . Diagnostic ) : MappingTree | null = > {
121
- if ( typeof cachedTransformedModule === 'undefined' ) {
122
- cachedTransformedModule = null ;
118
+ // Lazily fetch and cache the VirtualCode -- this might be a premature optimization
119
+ // after the code went through enough changes, so maybe safe to simplify in the future.
120
+ let cachedVirtualCode : VirtualGtsCode | null | undefined = undefined ;
121
+ const fetchVirtualCode = ( ) : VirtualGtsCode | null = > {
122
+ if ( typeof cachedVirtualCode === 'undefined' ) {
123
+ cachedVirtualCode = null ;
123
124
124
125
const decoded = context . decodeEmbeddedDocumentUri ( URI . parse ( document . uri ) ) ;
125
126
if ( decoded ) {
126
127
const script = context . language . scripts . get ( decoded [ 0 ] ) ;
127
128
const scriptRoot = script ?. generated ?. root ;
128
129
if ( scriptRoot instanceof VirtualGtsCode ) {
129
- const transformedModule = scriptRoot . transformedModule ;
130
- if ( transformedModule ) {
131
- cachedTransformedModule = transformedModule ;
132
- }
130
+ cachedVirtualCode = scriptRoot ;
133
131
}
134
132
}
135
133
}
136
134
137
- if ( ! cachedTransformedModule ) {
135
+ return cachedVirtualCode ;
136
+ }
137
+
138
+ const mappingForDiagnostic = ( diagnostic : vscode . Diagnostic ) : MappingTree | null = > {
139
+ const transformedModule = fetchVirtualCode ( ) ?. transformedModule ;
140
+
141
+ if ( ! transformedModule ) {
138
142
return null ;
139
143
}
140
144
141
145
const range = diagnostic . range ;
142
146
const start = document . offsetAt ( range . start ) ;
143
147
const end = document . offsetAt ( range . end ) ;
144
- const rangeWithMappingAndSource = cachedTransformedModule . getOriginalRange ( start , end ) ;
148
+ const rangeWithMappingAndSource = transformedModule . getOriginalRange ( start , end ) ;
145
149
return rangeWithMappingAndSource . mapping || null ;
146
150
} ;
147
151
148
- return diagnostics . map ( ( diagnostic ) => {
152
+ const allDiagnostics : vscode . Diagnostic [ ] = [ ] ;
153
+
154
+ return diagnostics . forEach ( ( diagnostic ) => {
149
155
diagnostic = {
150
156
...diagnostic ,
151
157
source : 'glint' ,
152
158
} ;
153
159
154
160
diagnostic = augmentDiagnostic ( diagnostic as any , mappingForDiagnostic ) ;
155
161
156
- return diagnostic ;
162
+ allDiagnostics . push ( diagnostic ) ;
157
163
} ) ;
158
164
}
159
165
0 commit comments