@@ -348,18 +348,24 @@ export class ShaderVariantTreeDataProvider implements vscode.TreeDataProvider<Sh
348348 // We have to rely on a dirty hack instead.
349349 // Need to check this does not break anything
350350 // Dirty hack to trigger document symbol update
351- for ( let editor of vscode . window . visibleTextEditors ) {
352- if ( editor . document . uri . path === uri . path ) {
353- editor . edit ( editBuilder => {
354- let line = editor . document . lineAt ( 0 ) ;
355- const text = line . text ;
356- const c = line . range . end . character ;
357- // Remove last character of first line and add it back.
358- editBuilder . delete ( new vscode . Range ( 0 , c - 1 , 0 , c ) ) ;
359- editBuilder . insert ( new vscode . Position ( 0 , c ) , text [ c - 1 ] ) ;
360- } ) ;
361- break ;
362- }
351+ let visibleEditor = vscode . window . visibleTextEditors . find ( e => e . document . uri . path === uri . path ) ;
352+ if ( visibleEditor ) {
353+ let editor = visibleEditor ;
354+ editor . edit ( editBuilder => {
355+ for ( let iLine = 0 ; iLine < editor . document . lineCount ; iLine ++ ) {
356+ // Find first non-empty line to avoid crashing on empty line with negative position.
357+ let line = editor . document . lineAt ( iLine ) ;
358+ if ( line . text . length > 0 ) {
359+ const text = line . text ;
360+ const c = line . range . end . character ;
361+ // Remove last character of first line and add it back.
362+ editBuilder . delete ( new vscode . Range ( iLine , c - 1 , iLine , c ) ) ;
363+ editBuilder . insert ( new vscode . Position ( iLine , c ) , text [ c - 1 ] ) ;
364+ break ;
365+ }
366+ }
367+ // All empty lines means no symbols !
368+ } ) ;
363369 }
364370 }
365371 private updateDependency ( file : ShaderVariantFile ) {
0 commit comments