22
33import { exec } from 'child_process' ;
44import { quote } from 'shell-quote' ;
5- import { window , commands , ExtensionContext , workspace , Selection } from 'vscode' ;
5+ import { window , commands , ExtensionContext , workspace , Selection , QuickPickItem , QuickPickOptions } from 'vscode' ;
6+
7+ interface QuickPickItemWithPath extends QuickPickItem {
8+ fullpath ?: string ;
9+ }
610
711const projectRoot = workspace . rootPath ? workspace . rootPath : '.' ;
812
@@ -18,12 +22,31 @@ export function activate(context: ExtensionContext) {
1822 window . showErrorMessage ( stderr ) ;
1923 return Promise . resolve ( ) ;
2024 }
21- const lines = stdout . split ( / \n / ) ;
22- if ( lines . length === 1 && lines [ 0 ] === '' ) {
25+ const lines = stdout . split ( / \n / ) . filter ( l => l !== '' ) ;
26+ const items : QuickPickItemWithPath [ ] = lines . map ( l => {
27+ const [ fullPath , line , desc ] = l . split ( ':' ) ;
28+ const path = fullPath . split ( '/' ) ;
29+ return {
30+ label : `${ path [ path . length - 1 ] } : ${ line } ` ,
31+ description : desc ,
32+ fullPath : l ,
33+ } ;
34+ } ) ;
35+ if ( ! lines . length ) {
2336 window . showInformationMessage ( 'There are no items' )
2437 return Promise . resolve ( ) ;
2538 }
26- const [ file , line ] = ( await window . showQuickPick ( lines ) ) . split ( ':' ) ;
39+ let item ;
40+ try {
41+ const options : QuickPickOptions = {
42+ matchOnDescription : true ,
43+ }
44+ item = await window . showQuickPick ( items , options ) ;
45+ } catch ( e ) {
46+ window . showErrorMessage ( e ) ;
47+ }
48+
49+ const [ file , line ] = item . fullPath . split ( ':' ) ;
2750 const doc = await workspace . openTextDocument ( projectRoot + '/' + file ) ;
2851 await window . showTextDocument ( doc ) ;
2952 window . activeTextEditor . selection = new Selection ( ~ ~ line , 0 , ~ ~ line , 0 ) ;
0 commit comments