Unmangle package names from typings during completion

This commit is contained in:
Andrew Casey 2018-01-09 15:40:32 -08:00
parent fa758cc357
commit db09a593d3
2 changed files with 13 additions and 5 deletions

View File

@ -1097,13 +1097,18 @@ namespace ts {
export function getPackageNameFromAtTypesDirectory(mangledName: string): string {
const withoutAtTypePrefix = removePrefix(mangledName, "@types/");
if (withoutAtTypePrefix !== mangledName) {
return stringContains(withoutAtTypePrefix, mangledScopedPackageSeparator) ?
"@" + withoutAtTypePrefix.replace(mangledScopedPackageSeparator, ts.directorySeparator) :
withoutAtTypePrefix;
return getPackageNameFromAtTypesDirectoryWithoutPrefix(withoutAtTypePrefix);
}
return mangledName;
}
/* @internal */
export function getPackageNameFromAtTypesDirectoryWithoutPrefix(withoutAtTypePrefix: string): string {
return stringContains(withoutAtTypePrefix, mangledScopedPackageSeparator) ?
"@" + withoutAtTypePrefix.replace(mangledScopedPackageSeparator, ts.directorySeparator) :
withoutAtTypePrefix;
}
function tryFindNonRelativeModuleNameInCache(cache: PerModuleNameCache | undefined, moduleName: string, containingDirectory: string, traceEnabled: boolean, host: ModuleResolutionHost): SearchResult<Resolved> {
const result = cache && cache.get(containingDirectory);
if (result) {

View File

@ -313,7 +313,8 @@ namespace ts.Completions.PathCompletions {
function getCompletionEntriesFromTypings(host: LanguageServiceHost, options: CompilerOptions, scriptPath: string, span: TextSpan, result: CompletionEntry[] = []): CompletionEntry[] {
// Check for typings specified in compiler options
if (options.types) {
for (const moduleName of options.types) {
for (const typesName of options.types) {
const moduleName = getPackageNameFromAtTypesDirectoryWithoutPrefix(typesName);
result.push(createCompletionEntryForModule(moduleName, ScriptElementKind.externalModuleName, span));
}
}
@ -346,7 +347,9 @@ namespace ts.Completions.PathCompletions {
if (directories) {
for (let typeDirectory of directories) {
typeDirectory = normalizePath(typeDirectory);
result.push(createCompletionEntryForModule(getBaseFileName(typeDirectory), ScriptElementKind.externalModuleName, span));
const directoryName = getBaseFileName(typeDirectory);
const moduleName = getPackageNameFromAtTypesDirectoryWithoutPrefix(directoryName);
result.push(createCompletionEntryForModule(moduleName, ScriptElementKind.externalModuleName, span));
}
}
}