@@ -84,8 +84,10 @@ export function configureTestController(
84
84
const testFileUris = new WeakMap < vscode . TestItem , vscode . Uri > ( ) ;
85
85
86
86
function getOrCreateWorkspaceFolderTestItem ( uri : vscode . Uri ) {
87
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
88
- let workspaceFolder = vscode . workspace . getWorkspaceFolder ( uri ) ! ;
87
+ let workspaceFolder = vscode . workspace . getWorkspaceFolder ( uri ) ;
88
+ if ( ! workspaceFolder ) {
89
+ return undefined ;
90
+ }
89
91
workspaceFolder =
90
92
workspaceTracker . getOuterMostWorkspaceFolder ( workspaceFolder ) ;
91
93
@@ -125,6 +127,9 @@ export function configureTestController(
125
127
fileTestItem . range = new vscode . Range ( 0 , 0 , 0 , 0 ) ;
126
128
127
129
const workspaceFolderTestItem = getOrCreateWorkspaceFolderTestItem ( uri ) ;
130
+ if ( ! workspaceFolderTestItem ) {
131
+ return undefined ;
132
+ }
128
133
workspaceFolderTestItem . children . add ( fileTestItem ) ;
129
134
130
135
testData . set ( fileTestItem , ItemType . File ) ;
@@ -170,18 +175,18 @@ export function configureTestController(
170
175
}
171
176
172
177
async function parseTestsInFileContents (
173
- file : vscode . TestItem ,
178
+ file : vscode . TestItem | undefined ,
174
179
) : Promise < void > {
180
+ if ( ! file ) {
181
+ return ;
182
+ }
175
183
if ( ! file . uri ?. toString ( ) . endsWith ( ".exs" ) ) {
176
184
return ;
177
185
}
178
186
// If a document is open, VS Code already knows its contents. If this is being
179
187
// called from the resolveHandler when a document isn't open, we'll need to
180
188
// read them from disk ourselves.
181
- const clientPromise = languageClientManager . getClientPromiseByUri (
182
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
183
- file . uri ! ,
184
- ) ;
189
+ const clientPromise = languageClientManager . getClientPromiseByUri ( file . uri ) ;
185
190
186
191
if ( ! clientPromise ) {
187
192
console . error (
@@ -228,8 +233,7 @@ export function configureTestController(
228
233
const moduleTestItem = controller . createTestItem (
229
234
moduleEntry . module ,
230
235
moduleEntry . module ,
231
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
232
- file . uri ! ,
236
+ file . uri ,
233
237
) ;
234
238
moduleTestItem . range = new vscode . Range (
235
239
moduleEntry . line ,
@@ -245,8 +249,7 @@ export function configureTestController(
245
249
const describeTestItem = controller . createTestItem (
246
250
describeEntry . describe ,
247
251
describeEntry . describe ,
248
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
249
- file . uri ! ,
252
+ file . uri ,
250
253
) ;
251
254
describeTestItem . range = new vscode . Range (
252
255
describeEntry . line ,
@@ -324,8 +327,7 @@ export function configureTestController(
324
327
testItem . tags = testEntry . tags . map (
325
328
( tag : string ) => new vscode . TestTag ( tag ) ,
326
329
) ;
327
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
328
- testFileUris . set ( testItem , file . uri ! ) ;
330
+ testFileUris . set ( testItem , file . uri ) ;
329
331
330
332
doctestGroupItem . children . add ( testItem ) ;
331
333
}
@@ -489,8 +491,11 @@ export function configureTestController(
489
491
// The `TestMessage` can contain extra information, like a failing location or
490
492
// a diff output. But here we'll just give it a textual message.
491
493
while ( queue . length > 0 && ! token . isCancellationRequested ) {
492
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
493
- const test = queue . pop ( ) ! ;
494
+ const test = queue . pop ( ) ;
495
+
496
+ if ( ! test || ! test . uri ) {
497
+ continue ;
498
+ }
494
499
495
500
// Skip tests the user asked to exclude
496
501
if ( request . exclude ?. includes ( test ) ) {
@@ -500,11 +505,15 @@ export function configureTestController(
500
505
const includeChildren = false ;
501
506
let runArgs : RunTestArgs ;
502
507
503
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
504
- const projectDir = workspaceTracker . getProjectDirForUri ( test . uri ! ) ! ;
508
+ const projectDir = workspaceTracker . getProjectDirForUri ( test . uri ) ;
509
+ if ( ! projectDir ) {
510
+ continue ;
511
+ }
505
512
const relativePath = test . uri ?. fsPath . slice ( projectDir . length + 1 ) ;
506
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
507
- const workspaceFolder = vscode . workspace . getWorkspaceFolder ( test . uri ! ) ! ;
513
+ const workspaceFolder = vscode . workspace . getWorkspaceFolder ( test . uri ) ;
514
+ if ( ! workspaceFolder ) {
515
+ continue ;
516
+ }
508
517
509
518
// Note that we don't need to manually
510
519
// set the state of parent tests; they'll be set automatically.
@@ -618,17 +627,24 @@ export function configureTestController(
618
627
619
628
case ItemType . TestCase :
620
629
if ( test . description === "doctest" ) {
621
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
622
- const testFileUri = testFileUris . get ( test ) ! ;
630
+ const testFileUri = testFileUris . get ( test ) ;
631
+ if ( ! testFileUri ) {
632
+ continue ;
633
+ }
623
634
const projectDir =
624
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
625
- workspaceTracker . getProjectDirForUri ( testFileUri ) ! ;
635
+ workspaceTracker . getProjectDirForUri ( testFileUri ) ;
636
+ if ( ! projectDir ) {
637
+ continue ;
638
+ }
626
639
const relativePath = testFileUri . fsPath . slice (
627
640
projectDir . length + 1 ,
628
641
) ;
629
642
const workspaceFolder =
630
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
631
- vscode . workspace . getWorkspaceFolder ( testFileUri ) ! ;
643
+ vscode . workspace . getWorkspaceFolder ( testFileUri ) ;
644
+
645
+ if ( ! workspaceFolder ) {
646
+ continue ;
647
+ }
632
648
633
649
runArgs = {
634
650
cwd : projectDir ,
@@ -733,8 +749,10 @@ export function configureTestController(
733
749
RUN_TEST_FROM_CODELENS ,
734
750
async ( args : RunArgs ) => {
735
751
const fileTestItemUri = vscode . Uri . file ( args . filePath ) ;
736
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
737
- const projectDir = workspaceTracker . getProjectDirForUri ( fileTestItemUri ) ! ;
752
+ const projectDir = workspaceTracker . getProjectDirForUri ( fileTestItemUri ) ;
753
+ if ( ! projectDir ) {
754
+ throw `Unable to find project dir for ${ fileTestItemUri } ` ;
755
+ }
738
756
await parseTestsInFileContents (
739
757
getOrCreateFile ( fileTestItemUri , projectDir ) ,
740
758
) ;
0 commit comments