import { SymbolKind , SymbolInformation , DocumentSymbolParams , Range , Position , Location , Files as VscodeFiles } from 'vscode-languageserver' ; import { ILogger } from '../interfaces' ; import { AbstractTagsSymbolProvider } from './abstractTagsSymbolProvider' ; const fileUrl = require ( 'file-url' ) ; export class FastTagsSymbolProvider extends AbstractTagsSymbolProvider { public constructor ( executable , workspaceRoot , logger ) { super ( executable || 'fast-tags' , workspaceRoot , logger ) ; } protected getFileSymbolsCommand ( documentSymbolParams ) { let uri = documentSymbolParams . textDocument . uri ; return `${ this . executable } -o - ${ VscodeFiles . uriToFilePath ( uri ) }` ; } protected getWorkspaceSymbolsCommand ( ) { return `${ this . executable } -R ${ this . workspaceRoot } -o - ` ; } protected parseTags ( rawTags ) { let symbolInformation = rawTags . split ( '\n' ) . slice ( 1 ) . map ( ( tagLine ) => { return tagLine . split ( '\t' ) ; } ) . filter ( ( line ) => line . length === 4 ) . map ( ( [ name , path , line , kind ] ) => { let uri = fileUrl ( path , { resolve : true } ) ; let lineNumber = parseInt ( line , 10 ) - 1 ; let range = Range . create ( Position . create ( lineNumber , 0 ) , Position . create ( lineNumber , 0 ) ) ; let symbolKind = FastTagsSymbolProvider . toSymbolKind ( kind ) ; return < SymbolInformation > { name : name , kind : symbolKind , location : Location . create ( uri , range ) } ; } ) ; this . logger . log ( `Found ${ symbolInformation . length } tags` ) ; return symbolInformation ; } private static toSymbolKind ( rawKind ) { switch ( rawKind . trim ( ) ) { case 'm' : return SymbolKind . Module ; case 'f' : return SymbolKind . Function ; case 'c' : return SymbolKind . Class ; case 't' : return SymbolKind . Interface ; case 'C' : return SymbolKind . Constructor ; case 'o' : return SymbolKind . Method ; default : return SymbolKind . Function ; } } }