1
1
import TsServerLibrary , { CodeFixAction , ScriptElementKind } from 'typescript/lib/tsserverlibrary' ;
2
2
import * as path from 'path' ;
3
+ import { getCompletionEntries } from './lib/import' ;
3
4
4
5
declare global {
5
6
namespace ts {
@@ -14,7 +15,7 @@ function stripExt(filePath: string) {
14
15
}
15
16
16
17
function init ( { typescript : ts } : { typescript : typeof TsServerLibrary } ) {
17
- function create ( info : TsServerLibrary . server . PluginCreateInfo ) {
18
+ function create ( info : ts . server . PluginCreateInfo ) {
18
19
const log = ( ...params : unknown [ ] ) => {
19
20
const text = params . map ( ( p ) => ( p ? JSON . stringify ( p ) : p ) ) . join ( ' ' ) ;
20
21
info . project . projectService . logger . info ( `[namespace-import] ${ text } ` ) ;
@@ -30,27 +31,15 @@ function init({ typescript: ts }: { typescript: typeof TsServerLibrary }) {
30
31
return original ;
31
32
}
32
33
33
- const entry : ts . CompletionEntry = {
34
- name : 'TestService' ,
35
- kind : ts . ScriptElementKind . alias ,
36
- source : '/Users/yukukotani/ghq/github.com/ubie-inc/yukustory/packages/client/src/TestService.ts' ,
37
- sortText : 'TestService' ,
38
- hasAction : true ,
39
- isImportStatementCompletion : true ,
40
- data : {
41
- exportName : 'TestService' ,
42
- modulePath : '/Users/yukukotani/ghq/github.com/ubie-inc/yukustory/packages/client/src/TestService.ts' ,
43
- } ,
44
- } ;
45
- original . entries . push ( entry ) ;
34
+ original . entries = [ ...original . entries , ...getCompletionEntries ( info ) ] ;
46
35
47
36
return original ;
48
37
} ;
49
38
50
39
const getCompletionEntryDetails = info . languageService . getCompletionEntryDetails ;
51
40
info . languageService . getCompletionEntryDetails = ( fileName , position , name , options , source , preferences , data ) => {
52
41
log ( 'getCompletionEntryDetails' , { fileName, position, name, options, source } ) ;
53
- if ( name === 'TestService' && data ?. modulePath ) {
42
+ if ( data ?. modulePath ) {
54
43
const importPath = path . relative ( path . dirname ( fileName ) , data . modulePath ) ;
55
44
const text = `import * as ${ name } from "${ stripExt ( importPath ) } ";\n` ;
56
45
const action : CodeFixAction = {
0 commit comments