Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
feat: support external type definitions with '/// <reference types=ht…
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Feb 10, 2020
1 parent b33ea3c commit f7affb2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions typescript-deno-plugin/src/module_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ function trimQueryAndHashFromPath(moduleName: string): string {
}

function trimExtensionName(moduleName: string): string {
if (/\.(t|j)sx?$/.test(moduleName) === false) {
if (/(\.d)?\.(t|j)sx?$/.test(moduleName) === false) {
return moduleName;
}
const name = moduleName.replace(/\.(t|j)sx?$/, "");
const name = moduleName.replace(/(\.d)?\.(t|j)sx?$/, "");
return name;
}
38 changes: 38 additions & 0 deletions typescript-deno-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export class DenoPlugin implements ts_module.server.PluginModule {
info.languageService
);

const resolveTypeReferenceDirectives = info.languageServiceHost
.resolveTypeReferenceDirectives?.bind(
info.languageServiceHost
);

info.languageServiceHost.getCompilationSettings = () => {
const projectConfig = getCompilationSettings();

Expand Down Expand Up @@ -118,6 +123,39 @@ export class DenoPlugin implements ts_module.server.PluginModule {
return scriptFileNames;
};

if (resolveTypeReferenceDirectives) {
info.languageServiceHost.resolveTypeReferenceDirectives = (
typeDirectiveNames: string[],
containingFile: string,
redirectedReference: ts_module.ResolvedProjectReference | undefined,
options: ts_module.CompilerOptions
) => {
if (!this.configurationManager.config.enable) {
return resolveTypeReferenceDirectives(
typeDirectiveNames,
containingFile,
redirectedReference,
options
);
}

const resolver = new ModuleResolver(
containingFile,
this.logger,
info.project.getCurrentDirectory()
);

const modules = resolver.resolveModuleNames(typeDirectiveNames);

return resolveTypeReferenceDirectives(
modules.map(v => v.module),
containingFile,
redirectedReference,
options
);
};
}

info.languageService.getSemanticDiagnostics = (filename: string) => {
const diagnostics = getSemanticDiagnostics(filename);

Expand Down

0 comments on commit f7affb2

Please sign in to comment.