1
1
import TsServerLibrary , { CodeFixAction , ScriptElementKind } from 'typescript/lib/tsserverlibrary' ;
2
2
import * as path from 'path' ;
3
- import { getCompletionEntries } from './lib/import' ;
3
+ import * as namespaceImportPlugin from './lib/import' ;
4
4
5
5
declare global {
6
6
namespace ts {
@@ -10,10 +10,6 @@ declare global {
10
10
}
11
11
}
12
12
13
- function stripExt ( filePath : string ) {
14
- return filePath . slice ( 0 , filePath . lastIndexOf ( '.' ) ) ;
15
- }
16
-
17
13
function init ( { typescript : ts } : { typescript : typeof TsServerLibrary } ) {
18
14
function create ( info : ts . server . PluginCreateInfo ) {
19
15
const log = ( ...params : unknown [ ] ) => {
@@ -31,7 +27,7 @@ function init({ typescript: ts }: { typescript: typeof TsServerLibrary }) {
31
27
return original ;
32
28
}
33
29
34
- original . entries = [ ...original . entries , ...getCompletionEntries ( info ) ] ;
30
+ original . entries = [ ...original . entries , ...namespaceImportPlugin . getCompletionEntries ( info ) ] ;
35
31
36
32
return original ;
37
33
} ;
@@ -40,34 +36,7 @@ function init({ typescript: ts }: { typescript: typeof TsServerLibrary }) {
40
36
info . languageService . getCompletionEntryDetails = ( fileName , position , name , options , source , preferences , data ) => {
41
37
log ( 'getCompletionEntryDetails' , { fileName, position, name, options, source } ) ;
42
38
if ( data ?. modulePath ) {
43
- const importPath = path . relative ( path . dirname ( fileName ) , data . modulePath ) ;
44
- const text = `import * as ${ name } from "${ stripExt ( importPath ) } ";\n` ;
45
- const action : CodeFixAction = {
46
- fixName : 'namespace-import' ,
47
- description : text ,
48
- changes : [
49
- {
50
- fileName : fileName ,
51
- textChanges : [
52
- {
53
- span : {
54
- start : 0 ,
55
- length : 0 ,
56
- } ,
57
- newText : text ,
58
- } ,
59
- ] ,
60
- } ,
61
- ] ,
62
- commands : [ ] ,
63
- } ;
64
- return {
65
- name : name ,
66
- kind : ScriptElementKind . alias ,
67
- kindModifiers : '' ,
68
- displayParts : [ ] ,
69
- codeActions : [ action ] ,
70
- } ;
39
+ return namespaceImportPlugin . getCompletionEntryDetails ( name , fileName , data . modulePath ) ;
71
40
}
72
41
73
42
return getCompletionEntryDetails ( fileName , position , name , options , source , preferences , data ) ;
0 commit comments