@@ -9,25 +9,27 @@ import { CommandNames } from './constants';
99const askHoogle = async ( variable : string ) : Promise < any > => {
1010 return await request ( {
1111 url : `https://hoogle.haskell.org/?hoogle=${ variable } &scope=set%3Astackage&mode=json` ,
12- json : true
12+ json : true ,
1313 } ) . promise ( ) ;
1414} ;
1515
16- const withCache = < T , U > ( theCache : LRU . Cache < T , U > , f : ( a : T ) => U ) => ( a : T ) => {
17- const maybeB = theCache . get ( a ) ;
18- if ( maybeB ) {
19- return maybeB ;
20- } else {
21- const b = f ( a ) ;
22- theCache . set ( a , b ) ;
23- return b ;
24- }
25- } ;
16+ const withCache =
17+ < T , U > ( theCache : LRU . Cache < T , U > , f : ( a : T ) => U ) =>
18+ ( a : T ) => {
19+ const maybeB = theCache . get ( a ) ;
20+ if ( maybeB ) {
21+ return maybeB ;
22+ } else {
23+ const b = f ( a ) ;
24+ theCache . set ( a , b ) ;
25+ return b ;
26+ }
27+ } ;
2628
2729const cache : LRU . Cache < string , Promise < any > > = LRU ( {
2830 // 1 MB
2931 max : 1000 * 1000 ,
30- length : ( r : any ) => JSON . stringify ( r ) . length
32+ length : ( r : any ) => JSON . stringify ( r ) . length ,
3133} ) ;
3234
3335const askHoogleCached = withCache ( cache , askHoogle ) ;
@@ -42,14 +44,14 @@ const doImport = async (arg: { mod: string; package: string }): Promise<void> =>
4244 const edit = new vscode . WorkspaceEdit ( ) ;
4345
4446 const lines = document . getText ( ) . split ( '\n' ) ;
45- const moduleLine = lines . findIndex ( line => {
47+ const moduleLine = lines . findIndex ( ( line ) => {
4648 const lineTrimmed = line . trim ( ) ;
4749 return lineTrimmed === 'where' || lineTrimmed . endsWith ( ' where' ) || lineTrimmed . endsWith ( ')where' ) ;
4850 } ) ;
49- const revInputLine = lines . reverse ( ) . findIndex ( l => l . startsWith ( 'import' ) ) ;
51+ const revInputLine = lines . reverse ( ) . findIndex ( ( l ) => l . startsWith ( 'import' ) ) ;
5052 const nextInputLine = revInputLine !== - 1 ? lines . length - 1 - revInputLine : moduleLine === - 1 ? 0 : moduleLine + 1 ;
5153
52- if ( ! lines . some ( line => new RegExp ( '^import.*' + escapeRegExp ( arg . mod ) ) . test ( line ) ) ) {
54+ if ( ! lines . some ( ( line ) => new RegExp ( '^import.*' + escapeRegExp ( arg . mod ) ) . test ( line ) ) ) {
5355 edit . insert ( document . uri , new vscode . Position ( nextInputLine , 0 ) , 'import ' + arg . mod + '\n' ) ;
5456 }
5557
@@ -99,11 +101,13 @@ export namespace ImportIdentifier {
99101 const response : any [ ] = await askHoogleCached ( editor . document . getText ( identifierRange ) ) ;
100102
101103 const choice = await vscode . window . showQuickPick (
102- response . filter ( result => result . module . name ) . map ( result => ( {
103- result,
104- label : result . package . name ,
105- description : result . module . name + ' -- ' + ( cheerio . load as any ) ( result . item , { xml : { } } ) . text ( )
106- } ) )
104+ response
105+ . filter ( ( result ) => result . module . name )
106+ . map ( ( result ) => ( {
107+ result,
108+ label : result . package . name ,
109+ description : result . module . name + ' -- ' + ( cheerio . load as any ) ( result . item , { xml : { } } ) . text ( ) ,
110+ } ) )
107111 ) ;
108112
109113 if ( ! choice ) {
0 commit comments