-
Notifications
You must be signed in to change notification settings - Fork 152
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
Draft
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/add-support-for-vsthrd003
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91a1e36
Initial plan
Copilot b9f60ec
Add CompletedTaskAttribute support for VSTHRD003
Copilot a864039
Fix CompletedTaskAttribute preprocessor directive and update document…
Copilot d067b66
Add assembly-level CompletedTaskAttribute support for external types
Copilot a593dc1
Add validation for CompletedTaskAttribute on non-readonly fields and …
Copilot 9e2bda8
Add diagnostic for invalid CompletedTaskAttribute usage and support f…
Copilot 83bcc44
Localize error messages for CompletedTaskAttribute validation
Copilot 1b80964
Clarify translator comment for init accessor validation message
Copilot 37e1e3d
Add CompletedTaskAttribute to TplExtensions and remove special-case code
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...o.Threading.Analyzers.CodeFixes/buildTransitive/AdditionalFiles/CompletedTaskAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| #if !COMPLETEDTASKATTRIBUTE_INCLUDED | ||
| #define COMPLETEDTASKATTRIBUTE_INCLUDED | ||
|
|
||
| namespace Microsoft.VisualStudio.Threading; | ||
|
|
||
| /// <summary> | ||
| /// Indicates that a property, method, or field returns a task that is already completed. | ||
| /// This suppresses VSTHRD003 warnings when awaiting the returned task. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Apply this attribute to properties, methods, or fields that return cached, pre-completed tasks | ||
| /// such as singleton instances with well-known immutable values. | ||
| /// The VSTHRD003 analyzer will not report warnings when these members are awaited, | ||
| /// as awaiting an already-completed task does not pose a risk of deadlock. | ||
| /// </para> | ||
| /// <para> | ||
| /// This attribute can also be applied at the assembly level to mark members in external types | ||
| /// that you don't control: | ||
| /// <code> | ||
| /// [assembly: CompletedTask(Member = "System.Threading.Tasks.TplExtensions.TrueTask")] | ||
| /// </code> | ||
| /// </para> | ||
| /// </remarks> | ||
| [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Method | System.AttributeTargets.Field | System.AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)] | ||
| #pragma warning disable SA1649 // File name should match first type name | ||
| internal sealed class CompletedTaskAttribute : System.Attribute | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="CompletedTaskAttribute"/> class. | ||
| /// </summary> | ||
| public CompletedTaskAttribute() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the fully qualified name of the member that returns a completed task. | ||
| /// This is only used when the attribute is applied at the assembly level. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The format should be: "Namespace.TypeName.MemberName". | ||
| /// For example: "System.Threading.Tasks.TplExtensions.TrueTask". | ||
| /// </remarks> | ||
| public string? Member { get; set; } | ||
| } | ||
| #pragma warning restore SA1649 // File name should match first type name | ||
|
|
||
| #endif |
5 changes: 4 additions & 1 deletion
5
...ng.Analyzers.CodeFixes/buildTransitive/Microsoft.VisualStudio.Threading.Analyzers.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup> | ||
| <AdditionalFiles Include="$(MSBuildThisFileDirectory)AdditionalFiles\**"> | ||
| <AdditionalFiles Include="$(MSBuildThisFileDirectory)AdditionalFiles\*.txt"> | ||
| <Visible>false</Visible> | ||
| </AdditionalFiles> | ||
| <Compile Include="$(MSBuildThisFileDirectory)AdditionalFiles\*.cs" Link="%(Filename)%(Extension)"> | ||
| <Visible>false</Visible> | ||
| </Compile> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.