Skip to content

Commit

Permalink
Don’t let other completions shadow type keywords in type locations (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
andrewbranch committed May 4, 2022
1 parent d337cbc commit d879880
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace ts.Completions {
TypeAssertionKeywords,
TypeKeywords,
TypeKeyword, // Literally just `type`
Last = TypeKeywords
Last = TypeKeyword
}

const enum GlobalsSearch { Continue, Success, Fail }
Expand Down Expand Up @@ -574,7 +574,7 @@ namespace ts.Completions {
if (keywordFilters !== KeywordCompletionFilters.None) {
const entryNames = new Set(entries.map(e => e.name));
for (const keywordEntry of getKeywordCompletions(keywordFilters, !insideJsDocTagTypeExpression && isSourceFileJS(sourceFile))) {
if (!entryNames.has(keywordEntry.name)) {
if (isTypeOnlyLocation && isTypeKeyword(stringToToken(keywordEntry.name)!) || !entryNames.has(keywordEntry.name)) {
insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// <reference path="../fourslash.ts" />

// @Filename: /node_modules/fp-ts/package.json
//// { "name": "fp-ts", "version": "0.10.4" }

// @Filename: /node_modules/fp-ts/index.d.ts
//// export * as string from "./lib/string";

// @Filename: /node_modules/fp-ts/lib/string.d.ts
//// export declare const fromString: (s: string) => string;
//// export type SafeString = string;

// @Filename: /package.json
//// { "dependencies": { "fp-ts": "^0.10.4" } }

// @Filename: /tsconfig.json
//// { "compilerOptions": { "module": "commonjs" } }

// @Filename: /index.ts
//// type A = { name: string/**/ }

goTo.marker("");
verify.completions({
marker: "",
includes: [{
name: "string",
sortText: completion.SortText.GlobalsOrKeywords,
}, {
name: "string",
sortText: completion.SortText.AutoImportSuggestions,
source: "fp-ts",
sourceDisplay: "fp-ts",
hasAction: true,
}],
preferences: {
includeCompletionsForModuleExports: true,
allowIncompleteCompletions: true,
},
});

0 comments on commit d879880

Please sign in to comment.