@@ -1455,39 +1455,33 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
14551455 } ) ,
14561456 vscode . window . onDidChangeActiveTextEditor ( async ( textEditor : vscode . TextEditor ) => {
14571457 if ( ! textEditor ) return ;
1458- posPanel . text = "" ;
14591458 await checkConnection ( false , textEditor . document . uri ) ;
14601459 if ( textEditor . document . uri . path . toLowerCase ( ) . endsWith ( ".xml" ) && config ( "autoPreviewXML" ) ) {
14611460 return previewXMLAsUDL ( textEditor , true ) ;
14621461 }
14631462 } ) ,
1464- vscode . window . onDidChangeTextEditorSelection ( ( event : vscode . TextEditorSelectionChangeEvent ) => {
1463+ vscode . window . onDidChangeTextEditorSelection ( async ( event : vscode . TextEditorSelectionChangeEvent ) => {
14651464 const document = event . textEditor . document ;
1466-
1467- // Avoid losing position indicator if event came from output channel
1468- if ( document . uri . scheme == "output" ) {
1469- return ;
1470- }
1471- posPanel . text = "" ;
1472- if ( ! [ macLangId , intLangId ] . includes ( document . languageId ) ) {
1473- return ;
1474- }
1475- if ( event . selections . length > 1 || ! event . selections [ 0 ] . isEmpty ) {
1476- return ;
1477- }
1478-
1479- const file = currentFile ( document ) ;
1480- const nameMatch = file . name . match ( / ( .* ) \. ( i n t | m a c ) $ / i) ;
1481- if ( ! nameMatch ) {
1482- return ;
1483- }
1484- const [ , routine ] = nameMatch ;
1485- let label = "" ;
1486- let pos = 0 ;
1487- vscode . commands
1488- . executeCommand < vscode . DocumentSymbol [ ] > ( "vscode.executeDocumentSymbolProvider" , document . uri )
1489- . then ( ( symbols ) => {
1490- if ( symbols != undefined ) {
1465+ // Avoid losing position indicator if event came from output channel or a non-active editor
1466+ if ( document . uri . scheme == "output" || vscode . window . activeTextEditor != event . textEditor ) return ;
1467+ try {
1468+ if (
1469+ ! [ macLangId , intLangId ] . includes ( document . languageId ) ||
1470+ event . selections . length > 1 ||
1471+ ! event . selections [ 0 ] . isEmpty
1472+ ) {
1473+ throw undefined ;
1474+ }
1475+ const file = currentFile ( document ) ;
1476+ const nameMatch = file . name . match ( / ( .* ) \. ( i n t | m a c ) $ / i) ;
1477+ if ( ! nameMatch ) throw undefined ;
1478+ const [ , routine ] = nameMatch ;
1479+ let label = "" ;
1480+ let pos = 0 ;
1481+ await vscode . commands
1482+ . executeCommand < vscode . DocumentSymbol [ ] > ( "vscode.executeDocumentSymbolProvider" , document . uri )
1483+ . then ( ( symbols ) => {
1484+ if ( ! symbols ) throw undefined ;
14911485 const cursor = event . selections [ 0 ] . active ;
14921486 if ( symbols . length == 0 || cursor . isBefore ( symbols [ 0 ] . range . start ) ) {
14931487 pos = cursor . line - 1 ;
@@ -1501,8 +1495,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
15011495 }
15021496 }
15031497 posPanel . text = `${ label } ${ pos > 0 ? "+" + pos : "" } ^${ routine } ` ;
1504- }
1505- } ) ;
1498+ } ) ;
1499+ } catch {
1500+ // If we couldn't resolve the cursor location to a label+offset^routine
1501+ // for any reason, hide the status bar item
1502+ posPanel . text = "" ;
1503+ }
15061504 } ) ,
15071505 vscode . commands . registerCommand ( "vscode-objectscript.loadStudioSnippets" , loadStudioSnippets ) ,
15081506 vscode . commands . registerCommand ( "vscode-objectscript.loadStudioColors" , ( ) => {
0 commit comments