-
Notifications
You must be signed in to change notification settings - Fork 153
Add CompletedTaskAttribute to suppress VSTHRD003 for known completed tasks #1510
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: drewnoakes <[email protected]>
…ation Co-authored-by: drewnoakes <[email protected]>
| If you have a property, method, or field that returns a pre-completed task (such as a cached task with a known value), | ||
| you can suppress this warning by applying the `[CompletedTask]` attribute to the member. | ||
| This attribute is automatically included when you install the `Microsoft.VisualStudio.Threading.Analyzers` package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot what if the attribute could be applied at the assembly level, such that you could also apply this attribute to types you don't control. For example if I was using TplExtensions and it wasn't annotated:
[assembly: CompletedTask(Member = "System.Threading.TplExtensions.TrueTask")]Or something like that. If this isn't feasible, or has major drawbacks, feel free to push back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I've implemented assembly-level attribute support. You can now mark external members like this:
[assembly: CompletedTask(Member = "ExternalLibrary.ExternalClass.CompletedTaskProperty")]The attribute now supports a Member property that accepts fully qualified names in the format Namespace.TypeName.MemberName. The analyzer checks assembly-level attributes and matches them against the symbols being analyzed. Multiple assembly-level attributes are supported for marking different external members.
Committed in d067b66.
Co-authored-by: drewnoakes <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
VSTHRD003 currently requires suppression at every call site when awaiting cached completed tasks. This adds a
[CompletedTask]attribute that marks properties/methods/fields returning pre-completed tasks, eliminating redundant per-consumer suppressions.Changes
Attribute distribution
CompletedTaskAttribute.csas source content inbuildTransitive/AdditionalFiles/.targetsto compile.csfiles from AdditionalFilesAnalyzer enhancement
IsSymbolAlwaysOkToAwaitnow checks forCompletedTaskAttributeon symbolsMemberproperty to mark external typesTask.CompletedTask,Task.FromResult,TplExtensions.*TaskTests
Task<T>scenariosJoinableTaskFactory.RuncontextsUsage
Direct member annotation:
Assembly-level annotation for external types:
Fixes #1438
> [!WARNING]
>
>
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.