@@ -9,74 +9,74 @@ import {getPathCompletions} from "../../modules/getPathCompletions";
9
9
10
10
function getIdentifierAndFileNames ( error : ts . Diagnostic , project : Project ) {
11
11
12
- var errorText : string = < any > error . messageText ;
12
+ var errorText : string = < any > error . messageText ;
13
13
14
- // We don't support error chains yet
15
- if ( typeof errorText !== 'string' ) {
16
- return undefined ;
17
- } ;
14
+ // We don't support error chains yet
15
+ if ( typeof errorText !== 'string' ) {
16
+ return undefined ;
17
+ } ;
18
18
19
- var match = errorText . match ( / C a n n o t f i n d n a m e \' ( \w + ) \' ./ ) ;
19
+ var match = errorText . match ( / C a n n o t f i n d n a m e \' ( \w + ) \' ./ ) ;
20
20
21
- // If for whatever reason the error message doesn't match
22
- if ( ! match ) return ;
21
+ // If for whatever reason the error message doesn't match
22
+ if ( ! match ) return ;
23
23
24
- var [ , identifierName ] = match ;
25
- var { files} = getPathCompletions ( {
26
- project,
27
- filePath : error . file . fileName ,
28
- prefix : identifierName ,
29
- includeExternalModules : false
30
- } ) ;
31
- var file = files . length > 0 ? files [ 0 ] . relativePath : undefined ;
32
- var basename = files . length > 0 ? files [ 0 ] . name : undefined ;
33
- return { identifierName, file, basename } ;
24
+ var [ , identifierName ] = match ;
25
+ var { files} = getPathCompletions ( {
26
+ project,
27
+ filePath : error . file . fileName ,
28
+ prefix : identifierName ,
29
+ includeExternalModules : false
30
+ } ) ;
31
+ var file = files . length > 0 ? files [ 0 ] . relativePath : undefined ;
32
+ var basename = files . length > 0 ? files [ 0 ] . name : undefined ;
33
+ return { identifierName, file, basename } ;
34
34
}
35
35
36
36
export class AddImportDefaultStatement implements QuickFix {
37
- key = AddImportDefaultStatement . name ;
37
+ key = AddImportDefaultStatement . name ;
38
38
39
- canProvideFix ( info : QuickFixQueryInformation ) : CanProvideFixResponse {
40
- var relevantError = info . positionErrors . filter ( x => x . code == 2304 ) [ 0 ] ;
41
- if ( ! relevantError ) return ;
42
- if ( info . positionNode . kind !== ts . SyntaxKind . Identifier ) return ;
43
- var matches = getIdentifierAndFileNames ( relevantError , info . project ) ;
44
- if ( ! matches ) return ;
45
- var { identifierName, file} = matches ;
46
- return file ? { display : `import ${ identifierName } from \"${ file } \"` } : undefined ;
47
- }
39
+ canProvideFix ( info : QuickFixQueryInformation ) : CanProvideFixResponse {
40
+ var relevantError = info . positionErrors . filter ( x => x . code == 2304 ) [ 0 ] ;
41
+ if ( ! relevantError ) return ;
42
+ if ( info . positionNode . kind !== ts . SyntaxKind . Identifier ) return ;
43
+ var matches = getIdentifierAndFileNames ( relevantError , info . project ) ;
44
+ if ( ! matches ) return ;
45
+ var { identifierName, file} = matches ;
46
+ return file ? { display : `import ${ identifierName } from \"${ file } \"` } : undefined ;
47
+ }
48
48
49
- provideFix ( info : QuickFixQueryInformation ) : Refactoring [ ] {
50
- var relevantError = info . positionErrors . filter ( x => x . code == 2304 ) [ 0 ] ;
51
- var identifier = < ts . Identifier > info . positionNode ;
49
+ provideFix ( info : QuickFixQueryInformation ) : Refactoring [ ] {
50
+ var relevantError = info . positionErrors . filter ( x => x . code == 2304 ) [ 0 ] ;
51
+ var identifier = < ts . Identifier > info . positionNode ;
52
52
53
- var identifierName = identifier . text ;
54
- var fileNameforFix = getIdentifierAndFileNames ( relevantError , info . project ) ;
55
- // Add stuff at the top of the file
56
- let refactorings : Refactoring [ ] = [ {
57
- span : {
58
- start : 0 ,
59
- length : 0
60
- } ,
61
- newText : `import ${ identifierName } from \"${ fileNameforFix . file } \";${ EOL } ` ,
62
- filePath : info . sourceFile . fileName
63
- } ] ;
53
+ var identifierName = identifier . text ;
54
+ var fileNameforFix = getIdentifierAndFileNames ( relevantError , info . project ) ;
55
+ // Add stuff at the top of the file
56
+ let refactorings : Refactoring [ ] = [ {
57
+ span : {
58
+ start : 0 ,
59
+ length : 0
60
+ } ,
61
+ newText : `import ${ identifierName } from \"${ fileNameforFix . file } \";${ EOL } ` ,
62
+ filePath : info . sourceFile . fileName
63
+ } ] ;
64
64
65
- // Also refactor the variable name to match the file name
66
- // TODO: the following code only takes into account location
67
- // There may be other locations where this is used.
68
- // Better that they trigger a *rename* explicitly later if they want to rename the variable
69
- // if (identifierName !== fileNameforFix.basename) {
70
- // refactorings.push({
71
- // span: {
72
- // start: identifier.getStart(),
73
- // length: identifier.end - identifier.getStart()
74
- // },
75
- // newText: fileNameforFix.basename,
76
- // filePath: info.srcFile.fileName
77
- // })
78
- // }
65
+ // Also refactor the variable name to match the file name
66
+ // TODO: the following code only takes into account location
67
+ // There may be other locations where this is used.
68
+ // Better that they trigger a *rename* explicitly later if they want to rename the variable
69
+ // if (identifierName !== fileNameforFix.basename) {
70
+ // refactorings.push({
71
+ // span: {
72
+ // start: identifier.getStart(),
73
+ // length: identifier.end - identifier.getStart()
74
+ // },
75
+ // newText: fileNameforFix.basename,
76
+ // filePath: info.srcFile.fileName
77
+ // })
78
+ // }
79
79
80
- return refactorings ;
81
- }
80
+ return refactorings ;
81
+ }
82
82
}
0 commit comments