Skip to content

Commit

Permalink
feat(language-core): add option to resolve hidden extensions (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk authored May 31, 2024
1 parent a2ca6e0 commit 3231202
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/language-core/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export interface LanguagePlugin<T, K extends VirtualCode = VirtualCode> {
* LSP + TS Plugin
*/
extraFileExtensions: ts.FileExtensionInfo[];
/**
* LSP + TS Plugin
*/
resolveHiddenExtensions?: boolean;
/**
* LSP + TS Plugin
*/
Expand Down
18 changes: 18 additions & 0 deletions packages/typescript/lib/resolveModuleName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ export function createResolveModuleName<T>(
}
}
}
if (typescript.resolveHiddenExtensions && fileName.endsWith(`.d.ts`)) {
for (const { extension } of typescript.extraFileExtensions) {
const sourceFileName = fileName.slice(0, -`.d.ts`.length) + `.${extension}`;
if (fileExists(sourceFileName)) {
const sourceScript = getSourceScript(sourceFileName);
if (sourceScript?.generated) {
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
if (serviceScript) {
toSourceFileInfo.set(fileName, {
sourceFileName,
extension: serviceScript.extension,
});
return true;
}
}
}
}
}
}
return host.fileExists(fileName);
},
Expand Down

0 comments on commit 3231202

Please sign in to comment.