import { WorkspaceSymbolProvider , CancellationToken } from 'vscode' ; import { SystemVerilogIndexer } from '../indexer' ; import { getSymbolKind , SystemVerilogSymbol } from '../symbol' ; export class SystemVerilogWorkspaceSymbolProvider implements WorkspaceSymbolProvider { public indexer : SystemVerilogIndexer ; public NUM_FILES : number = 250 ; constructor ( indexer ) { this . indexer = indexer ; } param query param _token return public provideWorkspaceSymbols ( query , _token ) { return new Promise ( ( resolve , reject ) => { if ( query === undefined || query . length === 0 ) { resolve ( this . indexer . mostRecentSymbols ) ; } else { const pattern = new RegExp ( `.*${ query . replace ( " " , "" ) . split ( "" ) . map ( ( c ) => c ) . join ( ".*" ) }.*` , 'i' ) ; const results = new Array < SystemVerilogSymbol > ( ) ; let exactMatch = false ; if ( query . startsWith ( '¤' ) ) { exactMatch = true ; query = query . substr ( 1 ) ; } this . indexer . symbols . forEach ( ( list ) => { list . forEach ( ( symbol ) => { if ( exactMatch === true ) { if ( symbol . name === query ) { results . push ( symbol ) ; } } else if ( symbol . name . match ( pattern ) ) { results . push ( symbol ) ; } } ) ; } ) ; this . indexer . updateMostRecentSymbols ( results . slice ( 0 ) ) ; resolve ( results ) ; } } ) ; } param query return public provideWorkspaceModule ( query ) { if ( query . length === 0 ) { return undefined ; } let symbolInfo ; this . indexer . symbols . forEach ( ( list ) => { list . forEach ( ( symbol ) => { if ( symbol . name === query && symbol . kind === getSymbolKind ( 'module' ) ) { symbolInfo = symbol ; return false ; } } ) ; if ( symbolInfo ) { return false ; } } ) ; this . indexer . updateMostRecentSymbols ( [ symbolInfo ] ) ; return symbolInfo ; } }