@@ -14,13 +14,14 @@ import { assert } from '../transform/util.js';
14
14
import { ConfigLoader } from '../config/loader.js' ;
15
15
import ts from 'typescript' ;
16
16
import type { TextDocument } from 'vscode-languageserver-textdocument' ;
17
- import type * as vscode from 'vscode-languageserver-protocol' ;
17
+ import * as vscode from 'vscode-languageserver-protocol' ;
18
18
import { URI } from 'vscode-uri' ;
19
19
import { VirtualGtsCode } from './gts-virtual-code.js' ;
20
20
import { augmentDiagnostic } from '../transform/diagnostics/augmentation.js' ;
21
21
import MappingTree from '../transform/template/mapping-tree.js' ;
22
22
import { Directive , TransformedModule } from '../transform/index.js' ;
23
23
import { Range } from '../transform/template/transformed-module.js' ;
24
+ import { offsetToPosition } from '../language-server/util/position.js' ;
24
25
25
26
const connection = createConnection ( ) ;
26
27
@@ -112,10 +113,6 @@ function filterAndAugmentDiagnostics(
112
113
return null ;
113
114
}
114
115
115
- if ( diagnostics . length == 0 ) {
116
- return diagnostics ;
117
- }
118
-
119
116
// Lazily fetch and cache the VirtualCode -- this might be a premature optimization
120
117
// after the code went through enough changes, so maybe safe to simplify in the future.
121
118
let cachedVirtualCode : VirtualGtsCode | null | undefined = undefined ;
@@ -161,10 +158,6 @@ function filterAndAugmentDiagnostics(
161
158
return augmentDiagnostic ( diagnostic as any , mappingForDiagnostic ) ;
162
159
} ) ;
163
160
164
- if ( augmentedDiagnostics . length === 0 ) {
165
- return [ ] ;
166
- }
167
-
168
161
let unusedExpectErrors = new Set < Directive > ( ) ;
169
162
const transformedModule = fetchVirtualCode ( ) ?. transformedModule ;
170
163
if ( transformedModule ) {
@@ -195,7 +188,6 @@ function filterAndAugmentDiagnostics(
195
188
let originalGtsDiagnosticStart = transformedModule ?. getOriginalOffset ( diagnosticStart ) ;
196
189
197
190
appliedDirective = transformedModule ?. directives . find ( ( directive ) => {
198
- const diagnosticStart = document . offsetAt ( diagnostic . range . start ) ;
199
191
return (
200
192
// TODO: when would the filename ever be different? uncomment and fix?
201
193
// directive.source.filename === diagnostic.file.fileName &&
@@ -212,16 +204,71 @@ function filterAndAugmentDiagnostics(
212
204
}
213
205
} ) ;
214
206
215
- // for (let directive of unusedExpectErrors) {
216
- // allDiagnostics.push(
217
- // createTransformDiagnostic(
218
- // ts,
219
- // directive.source,
220
- // `Unused '@glint-expect-error' directive.`,
221
- // directive.location
222
- // )
223
- // );
224
- // }
207
+ for ( let directive of unusedExpectErrors ) {
208
+
209
+ // desired methond on transformedModule:
210
+ // - it accepts a source offset and finds the transformed offset
211
+ // - in which file? there are multiple embeddedCodes in a .gts file
212
+ // - root: gts
213
+ // - embeddedCodes[0]: ts (IR)
214
+ // - embeddedCodes[1, 2, 3]: however many Handlebars templates
215
+ //
216
+ // transformedModule.correlatedSpans[1].mapping.children[0].children[1].sourceNode
217
+ // - {type: 'MustacheCommentStatement', value: ' @glint -expect-error ', loc: SourceSpan}
218
+ //
219
+ // this is what we want.
220
+ //
221
+ // OK what is our input?
222
+ // the starting point is directive that is left over.
223
+ // directive.areaOfEffect.start/end reference to the offset within the .gts file delineating: |{{! @glint -expect-error }}|
224
+ //
225
+ // directive.source: {
226
+ // contents: <GTS source code with untransformed template>
227
+ // filename: "disregard.gts"
228
+ // }
229
+ //
230
+ // determineTransformedOffsetAndSpan(
231
+ // originalFileName: string,
232
+ // originalOffset: number
233
+ // )
234
+ //
235
+ // transformedModule.determineTransformedOffsetAndSpan(directive.source.filename, directive.location.start)
236
+ //
237
+ // this returns a transformedOffset and correlatedSpan with mapping pointing to the template embedded.
238
+ //
239
+
240
+ allDiagnostics . push (
241
+ {
242
+ message : `Unused '@glint-expect-error' directive.` ,
243
+
244
+ // this range... should be... for the TS file. Currently we're sending
245
+ // a range for the source .gts. That can't be right.
246
+ // The info we have is....... we know an unused glint directive exists.
247
+ // We need to find a range in the IR .ts file.
248
+ //
249
+ // 1. need to translate directive.areaOfEffect into the IR .ts file location
250
+ // - this is going to be the beginning of line in .gts and end of line in .gts.
251
+ // - actually maybe it's not area of effect, but rather the comment node. YES.
252
+ // emit.forNode(node, () => {
253
+ // emit.text(`// @glint-${kind}`);
254
+ // emit.newline();
255
+ // });
256
+ //
257
+ // - can we take the souce and query the CommentNode
258
+ // - node: AST.MustacheCommentStatement | AST.CommentStatement
259
+ // - what/how do we query now?
260
+ //
261
+ // 2. need to make sure it fits error boundary
262
+ range : vscode . Range . create (
263
+ offsetToPosition ( document . getText ( ) , directive . areaOfEffect . start ) ,
264
+ offsetToPosition ( document . getText ( ) , directive . areaOfEffect . end )
265
+ ) ,
266
+ severity : vscode . DiagnosticSeverity . Error ,
267
+ code : 0 ,
268
+ source : directive . source . filename , // not sure if this is right
269
+ }
270
+ ) ;
271
+ }
225
272
226
273
return allDiagnostics ;
227
274
}
0 commit comments