import * as vscode from 'vscode' ; import * as path from 'path' ; import { DevToolsExtensionContext } from '../devToolsExtensionContext' ; import { AZSymbolInformation } from '../symbollibraries/azSymbolInformation' ; import { ToolsGetSyntaxTreeRequest } from '../langserver/toolsGetSyntaxTreeRequest' ; import { TextEditorHelper } from '../tools/textEditorHelper' ; import { ToolsGetSyntaxTreeSymbolsRequest } from '../langserver/toolsGetSyntaxTreeSymbolRequest' ; import { ToolsCloseSyntaxTreeRequest } from '../langserver/toolsCloseSyntaxTreeRequest' ; import { BaseSymbolsWebView } from '../webviews/baseSymbolsWebView' ; export class SyntaxTreeView extends BaseSymbolsWebView { protected _firstLoad : boolean ; constructor ( devToolsContext , documentUri ) { super ( devToolsContext , undefined , documentUri ) ; this . _firstLoad = true ; this . _disposables . push ( vscode . workspace . onDidChangeTextDocument ( e => { if ( ( e . document ) && ( this . _documentUri ) && ( e . document . uri . fsPath == this . _documentUri . fsPath ) ) this . loadSymbols ( ) ; } ) ) ; vscode . window . onDidChangeActiveTextEditor ( editor => { this . loadSymbols ( ) ; } ) ; } protected getHtmlContentPath ( ) { return path . join ( 'htmlresources' , 'syntaxtreeview' , 'syntaxtreeview.html' ) ; } protected getViewType ( ) { return 'azALDevTools.SyntaxTreeView' ; } protected async loadSymbols ( ) { if ( ! this . _documentUri ) return ; let editor = TextEditorHelper . findDocumentEditor ( this . _documentUri ) ; let source = '' ; if ( editor ) source = editor . document . getText ( ) ; let request = new ToolsGetSyntaxTreeRequest ( source , this . _documentUri . fsPath , this . _firstLoad ) ; this . _firstLoad = false ; let response = await this . _devToolsContext . toolsLangServerClient . getSyntaxTree ( request ) ; if ( ( response ) && ( response . root ) ) { let rootSymbol = AZSymbolInformation . fromAny ( response . root ) ; rootSymbol . updateTree ( true , false ) ; this . setSymbols ( rootSymbol , undefined ) ; } else this . setSymbols ( undefined , undefined ) ; } protected async onSymbolSelected ( symbolPath ) { if ( ! this . _documentUri ) return ; let request = new ToolsGetSyntaxTreeSymbolsRequest ( this . _documentUri . fsPath , symbolPath ) ; let response = await this . _devToolsContext . toolsLangServerClient . getSyntaxTreeSymbol ( request ) ; if ( response ) { this . setSymbolInfo ( response . symbol ) ; if ( response . symbol ) { let editor = TextEditorHelper . findDocumentEditor ( this . _documentUri ) ; if ( editor ) { editor . selection = new vscode . Selection ( response . symbol . range . start . line , response . symbol . range . start . character , response . symbol . range . end . line , response . symbol . range . end . character ) ; editor . revealRange ( editor . selection ) ; } } } else this . setSymbolInfo ( undefined ) ; } setSymbolInfo ( symbol ) { this . sendMessage ( { command : 'setSymbolInfo' , data : symbol } ) ; } protected onPanelClosed ( ) { super . onPanelClosed ( ) ; if ( this . _documentUri ) { let request = new ToolsCloseSyntaxTreeRequest ( this . _documentUri . fsPath ) ; this . _devToolsContext . toolsLangServerClient . closeSyntaxTree ( request ) ; } } }