Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t let other completions shadow type keywords in type locations #48939

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 oof, who even uses Last?

}

const enum GlobalsSearch { Continue, Success, Fail }
Expand Down Expand Up @@ -552,7 +552,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,
},
});