Skip to content

Commit d879880

Browse files
authored
Don’t let other completions shadow type keywords in type locations (microsoft#48939)
* Allow type keywords with the same names as other completions * Only add type keywords that are the same as other completions in type locations
1 parent d337cbc commit d879880

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/services/completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace ts.Completions {
164164
TypeAssertionKeywords,
165165
TypeKeywords,
166166
TypeKeyword, // Literally just `type`
167-
Last = TypeKeywords
167+
Last = TypeKeyword
168168
}
169169

170170
const enum GlobalsSearch { Continue, Success, Fail }
@@ -574,7 +574,7 @@ namespace ts.Completions {
574574
if (keywordFilters !== KeywordCompletionFilters.None) {
575575
const entryNames = new Set(entries.map(e => e.name));
576576
for (const keywordEntry of getKeywordCompletions(keywordFilters, !insideJsDocTagTypeExpression && isSourceFileJS(sourceFile))) {
577-
if (!entryNames.has(keywordEntry.name)) {
577+
if (isTypeOnlyLocation && isTypeKeyword(stringToToken(keywordEntry.name)!) || !entryNames.has(keywordEntry.name)) {
578578
insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
579579
}
580580
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
// @Filename: /node_modules/fp-ts/package.json
4+
//// { "name": "fp-ts", "version": "0.10.4" }
5+
6+
// @Filename: /node_modules/fp-ts/index.d.ts
7+
//// export * as string from "./lib/string";
8+
9+
// @Filename: /node_modules/fp-ts/lib/string.d.ts
10+
//// export declare const fromString: (s: string) => string;
11+
//// export type SafeString = string;
12+
13+
// @Filename: /package.json
14+
//// { "dependencies": { "fp-ts": "^0.10.4" } }
15+
16+
// @Filename: /tsconfig.json
17+
//// { "compilerOptions": { "module": "commonjs" } }
18+
19+
// @Filename: /index.ts
20+
//// type A = { name: string/**/ }
21+
22+
goTo.marker("");
23+
verify.completions({
24+
marker: "",
25+
includes: [{
26+
name: "string",
27+
sortText: completion.SortText.GlobalsOrKeywords,
28+
}, {
29+
name: "string",
30+
sortText: completion.SortText.AutoImportSuggestions,
31+
source: "fp-ts",
32+
sourceDisplay: "fp-ts",
33+
hasAction: true,
34+
}],
35+
preferences: {
36+
includeCompletionsForModuleExports: true,
37+
allowIncompleteCompletions: true,
38+
},
39+
});

0 commit comments

Comments
 (0)