Skip to content

Commit

Permalink
Does not add a duplicate completion when offering an export which was…
Browse files Browse the repository at this point in the history
… re-declared as a global - fixes #32675
  • Loading branch information
orta committed Oct 16, 2019
1 parent b7c85c7 commit c40ddb1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
Expand Down
33 changes: 33 additions & 0 deletions tests/cases/fourslash/completionsRedeclareModuleAsGlobal.ts
Original file line number Diff line number Diff line change
@@ -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 }
});

0 comments on commit c40ddb1

Please sign in to comment.