Skip to content

Fixed JS completions type spread #45484

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
merged 5 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert "Fix and updated tests"
This reverts commit 33829fa.
  • Loading branch information
armanio123 committed Aug 23, 2021
commit e1a2b9ed19a7170b8fa823b11725431dace8045e
8 changes: 4 additions & 4 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,6 @@ namespace ts.Completions {
}
}

if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) {
return undefined;
}

const entries: CompletionEntry[] = [];

if (isUncheckedFile(sourceFile, compilerOptions)) {
Expand Down Expand Up @@ -447,6 +443,10 @@ namespace ts.Completions {
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, compilerOptions.target!, entries); // TODO: GH#18217
}
else {
if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) {
return undefined;
}

getCompletionEntriesFromSymbols(
symbols,
entries,
Expand Down
13 changes: 12 additions & 1 deletion tests/cases/fourslash/completionInUncheckedJSFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,16 @@

verify.completions({
marker: "0",
exact: undefined
includes: [
{
name: "hello",
sortText: completion.SortText.JavascriptIdentifiers,
isFromUncheckedFile: true
},
{
name: "goodbye",
sortText: completion.SortText.JavascriptIdentifiers,
isFromUncheckedFile: true
}
]
});
2 changes: 1 addition & 1 deletion tests/cases/fourslash/getJavaScriptCompletions12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
verify.completions(
{ marker: "1", includes: { name: "charCodeAt", kind: "method", kindModifiers: "declare" } },
{ marker: ["2", "3", "4"], includes: { name: "toExponential", kind: "method", kindModifiers: "declare" } },
{ marker: "5", exact: undefined },
{ marker: "5", includes: { name: "test1", kind: "warning", sortText: completion.SortText.JavascriptIdentifiers } },
);
2 changes: 1 addition & 1 deletion tests/cases/fourslash/javaScriptPrototype2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ verify.completions({ includes: { name: "toFixed", kind: "method", kindModifiers:
goTo.marker('3');
edit.insert('.');
// Make sure symbols don't leak out into the constructor
verify.completions({ exact: undefined });
verify.completions({ includes: ["qua", "foo", "bar"].map(name => ({ name, kind: "warning", sortText: completion.SortText.JavascriptIdentifiers })) });
10 changes: 9 additions & 1 deletion tests/cases/fourslash/server/jsdocTypedefTag2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
//// my2.yes./*1*/
//// }

//// /**
//// * @param {MyType} my2
//// */
//// function b(my2) {
//// my2.yes./*2*/
//// }

verify.completions(
{ marker: "1", includes: "charAt" }
{ marker: "1", includes: "charAt" },
{ marker: "2", excludes: "charAt" },
);