Does not add a duplicate completion when offering an export which was re-declared as a global - fixes #32675

This commit is contained in:
Orta Therox 2019-10-16 17:02:35 -04:00
parent b7c85c7382
commit c40ddb183e
2 changed files with 40 additions and 3 deletions

View File

@ -1000,6 +1000,7 @@ namespace ts.Completions {
let completionKind = CompletionKind.None;
let isNewIdentifierLocation = false;
let keywordFilters = KeywordCompletionFilters.None;
// This also gets mutated in nested-functions after the return
let symbols: Symbol[] = [];
const symbolToOriginInfoMap: SymbolOriginInfoMap = [];
const symbolToSortTextMap: SymbolSortTextMap = [];
@ -1342,9 +1343,12 @@ namespace ts.Completions {
}
const symbolId = getSymbolId(symbol);
symbols.push(symbol);
symbolToOriginInfoMap[symbolId] = origin;
symbolToSortTextMap[symbolId] = SortText.AutoImportSuggestions;
const existingSymbol = findLast(symbols, symbol => symbol.id === symbolId);
if (!existingSymbol) {
symbols.push(symbol);
symbolToOriginInfoMap[symbolId] = origin;
symbolToSortTextMap[symbolId] = SortText.AutoImportSuggestions;
}
});
}
filterGlobalCompletion(symbols);

View File

@ -0,0 +1,33 @@
/// <reference path="fourslash.ts" />
// @esModuleInterop: true,
// @target: esnext
// @Filename: /myAssert.d.ts
////declare function assert(value:any, message?:string):void;
////export = assert;
////export as namespace assert;
// @Filename: /ambient.d.ts
////import assert from './myAssert';
////
////type Assert = typeof assert;
////
////declare global {
//// const assert: Assert;
////}
// @Filename: /index.ts
/////// <reference path="./ambient.d.ts" />
////asser/**/;
verify.completions({
marker: "",
includes: [
{
name: "assert",
sortText: completion.SortText.GlobalsOrKeywords
}
],
preferences: { includeCompletionsForModuleExports: true, includeInsertTextCompletions: true }
});