Skip to content

Fix duplicate completions bugs #23632

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

Merged
1 commit merged into from
May 1, 2018
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
3 changes: 1 addition & 2 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,7 @@ namespace FourSlash {
const actualByName = ts.createMap<ts.CompletionEntry>();
for (const entry of actualCompletions.entries) {
if (actualByName.has(entry.name)) {
// TODO: GH#23587
if (entry.name !== "undefined" && entry.name !== "require") this.raiseError(`Duplicate completions for ${entry.name}`);
this.raiseError(`Duplicate completions for ${entry.name}`);
}
else {
actualByName.set(entry.name, entry);
Expand Down
7 changes: 4 additions & 3 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2059,16 +2059,17 @@ namespace ts.Completions {
const kind = stringToToken(entry.name);
switch (keywordFilter) {
case KeywordCompletionFilters.None:
// "undefined" is a global variable, so don't need a keyword completion for it.
return kind !== SyntaxKind.UndefinedKeyword;
// TODO: GH#23631 Includes type keywords because `Array<numb/**/` is treaded as a value location currently.
Copy link
Member

Choose a reason for hiding this comment

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

isPossiblyTypeArgumentPosition we have this function to check for type argument location

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, added a note to #23631

return !isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind) || kind === SyntaxKind.DeclareKeyword || kind === SyntaxKind.ModuleKeyword
|| isTypeKeyword(kind) && kind !== SyntaxKind.UndefinedKeyword;
case KeywordCompletionFilters.ClassElementKeywords:
return isClassMemberCompletionKeyword(kind);
case KeywordCompletionFilters.InterfaceElementKeywords:
return isInterfaceOrTypeLiteralCompletionKeyword(kind);
case KeywordCompletionFilters.ConstructorParameterKeywords:
return isParameterPropertyModifier(kind);
case KeywordCompletionFilters.FunctionLikeBodyKeywords:
return !isClassMemberCompletionKeyword(kind);
return !isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
case KeywordCompletionFilters.TypeKeywords:
return isTypeKeyword(kind);
default:
Expand Down
8 changes: 0 additions & 8 deletions tests/cases/fourslash/completionEntryForPrimitive.ts

This file was deleted.

84 changes: 39 additions & 45 deletions tests/cases/fourslash/completionListKeywords.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
/// <reference path="fourslash.ts"/>

/////**/
////

goTo.marker();
verify.completionListContains("break");
verify.completionListContains("case");
verify.completionListContains("catch");
verify.completionListContains("class");
verify.completionListContains("constructor");
verify.completionListContains("continue");
verify.completionListContains("debugger");
verify.completionListContains("declare");
verify.completionListContains("default");
verify.completionListContains("delete");
verify.completionListContains("do");
verify.completionListContains("else");
verify.completionListContains("enum");
verify.completionListContains("export");
verify.completionListContains("extends");
verify.completionListContains("false");
verify.completionListContains("finally");
verify.completionListContains("for");
verify.completionListContains("function");
verify.completionListContains("get");
verify.completionListContains("if");
verify.completionListContains("implements");
verify.completionListContains("import");
verify.completionListContains("in");
verify.completionListContains("instanceof");
verify.completionListContains("interface");
verify.completionListContains("module");
verify.completionListContains("new");
verify.completionListContains("private");
verify.completionListContains("public");
verify.completionListContains("return");
verify.completionListContains("set");
verify.completionListContains("static");
verify.completionListContains("super");
verify.completionListContains("switch");
verify.completionListContains("this");
verify.completionListContains("throw");
verify.completionListContains("true");
verify.completionListContains("try");
verify.completionListContains("typeof");
verify.completionListContains("var");
verify.completionListContains("while");
verify.completionListContains("with");
verify.completions({
includes: [
"break",
"case",
"catch",
"class",
"continue",
"debugger",
"declare",
"default",
"delete",
"do",
"else",
"enum",
"export",
"extends",
"false",
"finally",
"for",
"function",
"if",
"instanceof",
"interface",
"module",
"new",
"return",
"super",
"switch",
"this",
"throw",
"true",
"try",
"typeof",
"var",
"while",
"with",
],
});
5 changes: 0 additions & 5 deletions tests/cases/fourslash/completionListPrimitives.ts

This file was deleted.