import * as vscode from 'vscode' ; import { DevToolsExtensionContext } from '../devToolsExtensionContext' ; import { SymbolsTreeView } from '../symbolstreeview/symbolsTreeView' ; import { SyntaxTreeView } from '../syntaxtreeview/syntaxTreeView' ; import { DevToolsExtensionService } from './devToolsExtensionService' ; export class ALSymbolsTreeService extends DevToolsExtensionService { protected _uriSymbolTreeViews : { [ id ] : SymbolsTreeView | undefined ; } ; constructor ( newContext ) { super ( newContext ) ; this . _uriSymbolTreeViews = { } ; this . registerCommands ( ) ; } protected registerCommands ( ) { let that = this ; this . _context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'azALDevTools.showDocumentSymbols' , ( ) => that . showEditorSymbolsTreeView ( ) ) ) ; this . _context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'azALDevTools.goToDefinitionSymbolTree' , ( ) => that . goToDefinitionSymbolTree ( ) ) ) ; this . _context . vscodeExtensionContext . subscriptions . push ( vscode . commands . registerCommand ( 'azALDevTools.showSyntaxTree' , ( ) => that . showSyntaxTreeAnalyzer ( ) ) ) ; } showSyntaxTreeAnalyzer ( ) { let editor = vscode . window . activeTextEditor ; if ( ( editor ) && ( editor . document ) && ( editor . document . uri ) ) { let syntaxTree = new SyntaxTreeView ( this . _context , editor . document . uri ) ; syntaxTree . show ( ) ; } } showEditorSymbolsTreeView ( ) { let editor = vscode . window . activeTextEditor ; if ( ( editor ) && ( editor . document ) && ( editor . document . uri ) ) this . showDocumentSymbols ( editor . document . uri , new vscode . Range ( editor . selection . start , editor . selection . end ) ) ; } async showDocumentSymbols ( docUri , range ) { let symbolsTreeView = this . _uriSymbolTreeViews [ docUri . toString ( ) ] ; if ( ! symbolsTreeView ) { symbolsTreeView = new SymbolsTreeView ( this . _context , undefined , docUri ) ; symbolsTreeView . selectedSymbolRange = range ; this . addUriSymbolsTreeView ( docUri , symbolsTreeView ) ; symbolsTreeView . show ( ) ; } else { symbolsTreeView . reveal ( ) ; if ( range ) symbolsTreeView . selectSymbolInRange ( range ) ; } } async goToDefinitionSymbolTree ( ) { let editor = vscode . window . activeTextEditor ; if ( ( editor ) && ( editor . document ) && ( editor . document . uri ) ) { let locationList = await vscode . window . withProgress < vscode . Location [ ] | undefined > ( { location : vscode . ProgressLocation . Notification , title : 'Loading object definition' } , async ( progress ) => { return await vscode . commands . executeCommand < vscode . Location [ ] | undefined > ( 'vscode.executeDefinitionProvider' , editor ! . document . uri , editor ! . selection . start ) ; } ) ; if ( ( locationList ) && ( locationList . length > 0 ) ) { let range = locationList [ 0 ] . range ; this . showDocumentSymbols ( locationList [ 0 ] . uri , range ) ; } else this . showDocumentSymbols ( editor . document . uri , undefined ) ; } } addUriSymbolsTreeView ( uri , symbolsTreeView ) { this . _uriSymbolTreeViews [ uri . toString ( ) ] = symbolsTreeView ; } removeUriSymbolsTreeView ( uri ) { this . _uriSymbolTreeViews [ uri . toString ( ) ] = undefined ; } }