From c3a67a01eb70c1debad0f967ee6c9d5caaaa4837 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 19 Apr 2021 19:21:48 +0200 Subject: [PATCH 1/8] Handle records in documentation comments in IDE side --- .../DocumentationCommentTests.cs | 64 +++++++++++++++++++ .../DocumentationCommentSnippetService.cs | 1 + .../MemberDeclarationSyntaxExtensions.cs | 26 -------- .../CSharp/Extensions/SyntaxNodeExtensions.cs | 3 +- 4 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/DocumentationComments/DocumentationCommentTests.cs b/src/EditorFeatures/CSharpTest/DocumentationComments/DocumentationCommentTests.cs index 4af6c89fe02ca..326a0fc2cdb94 100644 --- a/src/EditorFeatures/CSharpTest/DocumentationComments/DocumentationCommentTests.cs +++ b/src/EditorFeatures/CSharpTest/DocumentationComments/DocumentationCommentTests.cs @@ -38,6 +38,40 @@ class C VerifyTypingCharacter(code, expected); } + [WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)] + public void TypingCharacter_Record() + { + var code = +@"//$$ +record R;"; + + var expected = +@"/// +/// $$ +/// +record R;"; + + VerifyTypingCharacter(code, expected); + } + + [WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)] + public void TypingCharacter_RecordWithPositionalParameters() + { + var code = +@"//$$ +record R(string S, int I);"; + + var expected = +@"/// +/// $$ +/// +/// +/// +record R(string S, int I);"; + + VerifyTypingCharacter(code, expected); + } + [WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)] public void TypingCharacter_Class_NewLine() { @@ -1467,6 +1501,36 @@ class C VerifyInsertCommentCommand(code, expected); } + [WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)] + public void Command_Record() + { + var code = "record R$$;"; + + var expected = +@"/// +/// $$ +/// +record R;"; + + VerifyInsertCommentCommand(code, expected); + } + + [WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)] + public void Command_RecordWithPositionalParameters() + { + var code = "record R$$(string S, int I);"; + + var expected = +@"/// +/// $$ +/// +/// +/// +record R(string S, int I);"; + + VerifyInsertCommentCommand(code, expected); + } + [WorkItem(4817, "https://github.com/dotnet/roslyn/issues/4817")] [WpfFact, Trait(Traits.Feature, Traits.Features.DocumentationComments)] public void Command_Class_AutoGenerateXmlDocCommentsOff() diff --git a/src/Features/CSharp/Portable/DocumentationComments/DocumentationCommentSnippetService.cs b/src/Features/CSharp/Portable/DocumentationComments/DocumentationCommentSnippetService.cs index 079e46c889145..53dcae7f19d17 100644 --- a/src/Features/CSharp/Portable/DocumentationComments/DocumentationCommentSnippetService.cs +++ b/src/Features/CSharp/Portable/DocumentationComments/DocumentationCommentSnippetService.cs @@ -39,6 +39,7 @@ protected override bool SupportsDocumentationComments(MemberDeclarationSyntax me switch (member.Kind()) { case SyntaxKind.ClassDeclaration: + case SyntaxKind.RecordDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.StructDeclaration: case SyntaxKind.DelegateDeclaration: diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/MemberDeclarationSyntaxExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/MemberDeclarationSyntaxExtensions.cs index f2ef822ad2493..1e03341fec4e1 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/MemberDeclarationSyntaxExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/MemberDeclarationSyntaxExtensions.cs @@ -114,32 +114,6 @@ public static TypeParameterListSyntax GetTypeParameterList(this MemberDeclaratio return null; } - public static BaseParameterListSyntax GetParameterList(this MemberDeclarationSyntax member) - { - if (member != null) - { - switch (member.Kind()) - { - case SyntaxKind.DelegateDeclaration: - return ((DelegateDeclarationSyntax)member).ParameterList; - case SyntaxKind.MethodDeclaration: - return ((MethodDeclarationSyntax)member).ParameterList; - case SyntaxKind.ConstructorDeclaration: - return ((ConstructorDeclarationSyntax)member).ParameterList; - case SyntaxKind.DestructorDeclaration: - return ((DestructorDeclarationSyntax)member).ParameterList; - case SyntaxKind.IndexerDeclaration: - return ((IndexerDeclarationSyntax)member).ParameterList; - case SyntaxKind.OperatorDeclaration: - return ((OperatorDeclarationSyntax)member).ParameterList; - case SyntaxKind.ConversionOperatorDeclaration: - return ((ConversionOperatorDeclarationSyntax)member).ParameterList; - } - } - - return null; - } - public static MemberDeclarationSyntax WithParameterList( this MemberDeclarationSyntax member, BaseParameterListSyntax parameterList) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs index 9c1c265e461d7..2770240b8e87e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs @@ -258,7 +258,7 @@ node is UsingStatementSyntax || }; public static BaseParameterListSyntax? GetParameterList(this SyntaxNode declaration) - => declaration.Kind() switch + => declaration?.Kind() switch { SyntaxKind.DelegateDeclaration => ((DelegateDeclarationSyntax)declaration).ParameterList, SyntaxKind.MethodDeclaration => ((MethodDeclarationSyntax)declaration).ParameterList, @@ -270,6 +270,7 @@ node is UsingStatementSyntax || SyntaxKind.ParenthesizedLambdaExpression => ((ParenthesizedLambdaExpressionSyntax)declaration).ParameterList, SyntaxKind.LocalFunctionStatement => ((LocalFunctionStatementSyntax)declaration).ParameterList, SyntaxKind.AnonymousMethodExpression => ((AnonymousMethodExpressionSyntax)declaration).ParameterList, + SyntaxKind.RecordDeclaration => ((RecordDeclarationSyntax)declaration).ParameterList, _ => null, }; From a837654f76937caccafa9b1d2a97d8e75386c617 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 19 Apr 2021 19:40:08 +0200 Subject: [PATCH 2/8] Fix --- .../Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs index 2770240b8e87e..3f0cd950cc660 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs @@ -257,7 +257,7 @@ node is UsingStatementSyntax || _ => null, }; - public static BaseParameterListSyntax? GetParameterList(this SyntaxNode declaration) + public static BaseParameterListSyntax? GetParameterList(this SyntaxNode? declaration) => declaration?.Kind() switch { SyntaxKind.DelegateDeclaration => ((DelegateDeclarationSyntax)declaration).ParameterList, From eafa7aba5f61c107b81727159e5a8d72ce01de13 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sun, 2 May 2021 16:32:48 +0200 Subject: [PATCH 3/8] Obsolete importing constructor --- .../LanguageServices/CSharpRemoveUnnecessaryImportsService.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs index 95638f77b5652..2a0c055bec68b 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpRemoveUnnecessaryImportsService.cs @@ -26,10 +26,8 @@ namespace Microsoft.CodeAnalysis.CSharp.RemoveUnnecessaryImports internal partial class CSharpRemoveUnnecessaryImportsService : AbstractRemoveUnnecessaryImportsService { - public static readonly CSharpRemoveUnnecessaryImportsService Instance = new(); - [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Incorrectly used in production code: https://github.com/dotnet/roslyn/issues/42839")] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public CSharpRemoveUnnecessaryImportsService() { } From 424faffa9c4d008c5f70936d7c64811f74107879 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sun, 2 May 2021 16:37:48 +0200 Subject: [PATCH 4/8] Obsolete importing constructor --- .../Portable/Indentation/VisualBasicIndentationService.vb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb b/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb index 1ab6a292dae38..70fc7b223c7ac 100644 --- a/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb +++ b/src/Workspaces/VisualBasic/Portable/Indentation/VisualBasicIndentationService.vb @@ -17,13 +17,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Indentation Partial Friend NotInheritable Class VisualBasicIndentationService Inherits AbstractIndentationService(Of CompilationUnitSyntax) - Public Shared ReadOnly DefaultInstance As New VisualBasicIndentationService() Public Shared ReadOnly WithoutParameterAlignmentInstance As New VisualBasicIndentationService(NoOpFormattingRule.Instance) Private ReadOnly _specializedIndentationRule As AbstractFormattingRule - + Public Sub New() Me.New(Nothing) End Sub From 0c2f0118a32f0ec024d27e1f353bf474833eadf0 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sun, 2 May 2021 17:43:50 +0200 Subject: [PATCH 5/8] Don't instantiate workspace service directly --- .../LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs index 7db0a8f527a14..18e31f305fcdc 100644 --- a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs +++ b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs @@ -85,7 +85,7 @@ private async Task MergeLinkedDocumentGroupAsync( // Automatically merge non-conflicting diffs while collecting the conflicting diffs - var textDifferencingService = _oldSolution.Workspace.Services.GetService() ?? new DefaultDocumentTextDifferencingService(); + var textDifferencingService = _oldSolution.Workspace.Services.GetRequiredService(); var appliedChanges = await textDifferencingService.GetTextChangesAsync(_oldSolution.GetDocument(linkedDocumentGroup.First()), _newSolution.GetDocument(linkedDocumentGroup.First()), cancellationToken).ConfigureAwait(false); var unmergedChanges = new List(); From ab2aead113a73dc05b37ea2789717786c4777967 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sun, 2 May 2021 17:45:04 +0200 Subject: [PATCH 6/8] Obsolete service importing constructor --- .../DefaultDocumentTextDifferencingService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs index b499fa50fc95e..6b26149c703bf 100644 --- a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs +++ b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis internal class DefaultDocumentTextDifferencingService : IDocumentTextDifferencingService { [ImportingConstructor] - [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Incorrectly used in production code: https://github.com/dotnet/roslyn/issues/42839")] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public DefaultDocumentTextDifferencingService() { } From 13a2eb2ae7b2bb6f7fed3c6b78331b2dc8362e3b Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sun, 2 May 2021 17:57:12 +0200 Subject: [PATCH 7/8] Update DefaultDocumentTextDifferencingService.cs --- .../DefaultDocumentTextDifferencingService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs index 6b26149c703bf..941a4c1ecffd1 100644 --- a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs +++ b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - +using System; using System.Collections.Immutable; using System.Composition; using System.Diagnostics.CodeAnalysis; From ce7d119639519b2ba1fc9bb089e63aee4e473f55 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Mon, 3 May 2021 13:31:34 +0000 Subject: [PATCH 8/8] Update dependencies from https://github.com/dotnet/roslyn build 20210503.8 (#53108) [main] Update dependencies from dotnet/roslyn --- eng/Version.Details.xml | 4 ++-- eng/Versions.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index ec7389aa47b53..e21f50d218c4c 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -7,9 +7,9 @@ https://github.com/dotnet/arcade 0ca849f0b71866b007fedaaa938cee63f8d056a6 - + https://github.com/dotnet/roslyn - 9b40ab852a3b59ce9cef33b3e97c17af13c8e694 + 5b972bceb846f5d15f991a479e285067a75103e4 https://github.com/dotnet/arcade diff --git a/eng/Versions.props b/eng/Versions.props index 8ff0f8aa1aff9..e83865d958f7c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -23,7 +23,7 @@ - 3.10.0-3.21223.23 + 4.0.0-2.21253.8