71bec5b698
* Start prototyping addMissingAwait codefix * Filter by diagnostics that have missing-await related info * Start writing tests and checking precedence * Implement codeFixAll, add test for binary expressions * Add test for iterables * Add test for passing argument * Add test for call/construct signatures * Add test for awaiting initializer * Improve assertion error * Replace specific property access error with general one and add await related info * Add test for property access * Require code to be inside a function body to offer await * Accept suggestion Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> * Add explicit test for code fix being not available unless something is a Promise * Skip looking for function body if already in AwaitContext flags * Inline getCodeActions function for symmetry
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
/// <reference path="fourslash.ts" />
|
|
////async function fn(a: Promise<string[]>) {
|
|
//// [...a];
|
|
//// for (const c of a) { c; }
|
|
//// for await (const c of a) { c; }
|
|
////}
|
|
|
|
verify.codeFix({
|
|
description: ts.Diagnostics.Add_await.message,
|
|
index: 0,
|
|
newFileContent:
|
|
`async function fn(a: Promise<string[]>) {
|
|
[...await a];
|
|
for (const c of a) { c; }
|
|
for await (const c of a) { c; }
|
|
}`
|
|
});
|
|
|
|
verify.codeFix({
|
|
description: ts.Diagnostics.Add_await.message,
|
|
index: 1,
|
|
newFileContent:
|
|
`async function fn(a: Promise<string[]>) {
|
|
[...a];
|
|
for (const c of await a) { c; }
|
|
for await (const c of a) { c; }
|
|
}`
|
|
});
|
|
|
|
verify.codeFix({
|
|
description: ts.Diagnostics.Add_await.message,
|
|
index: 2,
|
|
newFileContent:
|
|
`async function fn(a: Promise<string[]>) {
|
|
[...a];
|
|
for (const c of a) { c; }
|
|
for await (const c of await a) { c; }
|
|
}`
|
|
});
|
|
|
|
verify.codeFixAll({
|
|
fixAllDescription: ts.Diagnostics.Fix_all_expressions_possibly_missing_await.message,
|
|
fixId: "addMissingAwait",
|
|
newFileContent:
|
|
`async function fn(a: Promise<string[]>) {
|
|
[...await a];
|
|
for (const c of await a) { c; }
|
|
for await (const c of await a) { c; }
|
|
}`
|
|
});
|