Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit cac55f5

Browse files
lsagetlethiasjustjavac
authored andcommitted
Add .ts extension on automatic import (#10)
1 parent 86ecd59 commit cac55f5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,42 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
8787
return scriptFileNames;
8888
};
8989

90+
const getCompletionEntryDetails = info.languageService.getCompletionEntryDetails;
91+
info.languageService.getCompletionEntryDetails = (
92+
fileName: string,
93+
position: number,
94+
name: string,
95+
formatOptions?: ts_module.FormatCodeOptions | ts_module.FormatCodeSettings,
96+
source?: string,
97+
preferences?: ts_module.UserPreferences) => {
98+
99+
const details = getCompletionEntryDetails.call(
100+
info.languageService,
101+
fileName,
102+
position,
103+
name,
104+
formatOptions,
105+
source,
106+
preferences
107+
);
108+
109+
if (details) {
110+
if (details.codeActions && details.codeActions.length) {
111+
for (const ca of details.codeActions) {
112+
for (const change of ca.changes) {
113+
if (!change.isNewFile) {
114+
for (const tc of change.textChanges) {
115+
tc.newText = tc.newText.replace(/^(import .* from ['"])(\..*)(['"];\n)/i, "$1$2.ts$3");
116+
}
117+
}
118+
}
119+
}
120+
}
121+
}
122+
123+
return details;
124+
};
125+
90126
return info.languageService;
91127
},
92128

0 commit comments

Comments
 (0)