@@ -9,25 +9,27 @@ import { CommandNames } from './constants';
9
9
const askHoogle = async ( variable : string ) : Promise < any > => {
10
10
return await request ( {
11
11
url : `https://hoogle.haskell.org/?hoogle=${ variable } &scope=set%3Astackage&mode=json` ,
12
- json : true
12
+ json : true ,
13
13
} ) . promise ( ) ;
14
14
} ;
15
15
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
+ } ;
26
28
27
29
const cache : LRU . Cache < string , Promise < any > > = LRU ( {
28
30
// 1 MB
29
31
max : 1000 * 1000 ,
30
- length : ( r : any ) => JSON . stringify ( r ) . length
32
+ length : ( r : any ) => JSON . stringify ( r ) . length ,
31
33
} ) ;
32
34
33
35
const askHoogleCached = withCache ( cache , askHoogle ) ;
@@ -42,14 +44,14 @@ const doImport = async (arg: { mod: string; package: string }): Promise<void> =>
42
44
const edit = new vscode . WorkspaceEdit ( ) ;
43
45
44
46
const lines = document . getText ( ) . split ( '\n' ) ;
45
- const moduleLine = lines . findIndex ( line => {
47
+ const moduleLine = lines . findIndex ( ( line ) => {
46
48
const lineTrimmed = line . trim ( ) ;
47
49
return lineTrimmed === 'where' || lineTrimmed . endsWith ( ' where' ) || lineTrimmed . endsWith ( ')where' ) ;
48
50
} ) ;
49
- const revInputLine = lines . reverse ( ) . findIndex ( l => l . startsWith ( 'import' ) ) ;
51
+ const revInputLine = lines . reverse ( ) . findIndex ( ( l ) => l . startsWith ( 'import' ) ) ;
50
52
const nextInputLine = revInputLine !== - 1 ? lines . length - 1 - revInputLine : moduleLine === - 1 ? 0 : moduleLine + 1 ;
51
53
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 ) ) ) {
53
55
edit . insert ( document . uri , new vscode . Position ( nextInputLine , 0 ) , 'import ' + arg . mod + '\n' ) ;
54
56
}
55
57
@@ -99,11 +101,13 @@ export namespace ImportIdentifier {
99
101
const response : any [ ] = await askHoogleCached ( editor . document . getText ( identifierRange ) ) ;
100
102
101
103
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
+ } ) )
107
111
) ;
108
112
109
113
if ( ! choice ) {
0 commit comments