diff --git a/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests.cs b/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests.cs
index a49651b28354..aa751e329ccd 100644
--- a/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests.cs
+++ b/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests.cs
@@ -2125,7 +2125,6 @@ public override void AbstractMethod()
throw new System.NotImplementedException();
}
}
-
""", parseOptions: TestOptions.RegularPreview);
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48742")]
diff --git a/src/Analyzers/CSharp/Tests/ImplementInterface/ImplementInterfaceCodeFixTests.cs b/src/Analyzers/CSharp/Tests/ImplementInterface/ImplementInterfaceCodeFixTests.cs
index 3f833873d5bb..28bfb6f5a67c 100644
--- a/src/Analyzers/CSharp/Tests/ImplementInterface/ImplementInterfaceCodeFixTests.cs
+++ b/src/Analyzers/CSharp/Tests/ImplementInterface/ImplementInterfaceCodeFixTests.cs
@@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.CSharp.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.NamingStyles;
+using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.ImplementType;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Testing;
@@ -578,7 +579,6 @@ public void Method1()
throw new System.NotImplementedException();
}
}
-
""");
[Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/26323")]
@@ -2087,7 +2087,6 @@ public object GetService(Type serviceType)
throw new NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540318")]
@@ -3107,8 +3106,7 @@ abstract class Goo : IGoo
{
public event EventHandler E;
}
- """,
- index: 0);
+ """);
[Fact]
public Task TestImplementEventAbstractly()
@@ -5687,7 +5685,6 @@ public void Goo<@class>()
throw new System.NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545922")]
@@ -5775,7 +5772,6 @@ public object GetService(Type serviceType)
throw new NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529920")]
@@ -5821,7 +5817,6 @@ public object GetService(Type serviceType)
throw new NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529947")]
@@ -5863,8 +5858,7 @@ public void Dispose()
throw new NotImplementedException();
}
}
-
- """, index: 0);
+ """);
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/958699")]
[WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/994456")]
@@ -5882,7 +5876,6 @@ class C : IDisposable
{{DisposePattern("protected virtual ", "C", "public void ")}}
}
-
""", index: 1);
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/958699")]
@@ -5902,7 +5895,6 @@ void IDisposable.Dispose()
throw new NotImplementedException();
}
}
-
""", index: 2);
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/941469")]
@@ -5946,7 +5938,6 @@ abstract class C : IDisposable
{
public abstract void Dispose();
}
-
""", index: 2);
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/958699")]
@@ -5985,7 +5976,6 @@ class C : System.IDisposable
{{DisposePattern("protected virtual ", "C", "void System.IDisposable.", gcPrefix: "System.")}}
}
-
""",
CodeActionIndex = 3,
@@ -6024,7 +6014,7 @@ public void F()
throw new NotImplementedException();
}
}
- """, index: 0);
+ """);
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/951968")]
public Task TestImplementIDisposableViaBaseInterface()
@@ -6138,7 +6128,6 @@ public void Dispose()
throw new NotImplementedException();
}
}
-
""");
[Fact]
@@ -6157,7 +6146,6 @@ void IDisposable.Dispose()
throw new NotImplementedException();
}
}
-
""", index: 1);
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545924")]
@@ -6230,7 +6218,6 @@ public object GetService(Type serviceType)
throw new NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545939")]
@@ -6250,7 +6237,6 @@ public object GetService(Type serviceType)
throw new NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545939")]
@@ -6270,7 +6256,6 @@ public object GetService(Type serviceType)
throw new NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545939")]
@@ -6290,7 +6275,6 @@ public object GetService(Type serviceType)
throw new NotImplementedException();
}
}
-
""");
[Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545940")]
@@ -7030,7 +7014,7 @@ public void Dispose()
throw new NotImplementedException();
}
}
- """, index: 0);
+ """);
[Fact]
public Task TestImplementInterfaceForIDisposableNonApplicable2()
@@ -7059,7 +7043,7 @@ public void Dispose()
throw new NotImplementedException();
}
}
- """, index: 0);
+ """);
[Fact]
public Task TestImplementInterfaceForExplicitIDisposableWithSealedClass()
@@ -10054,7 +10038,6 @@ public void M1()
throw new System.NotImplementedException();
}
}
-
""",
}.RunAsync();
@@ -10085,7 +10068,6 @@ public void M1()
throw new System.NotImplementedException();
}
}
-
""",
}.RunAsync();
@@ -10116,7 +10098,6 @@ public void M1()
throw new System.NotImplementedException();
}
}
-
""",
}.RunAsync();
@@ -10185,7 +10166,6 @@ public void M1()
throw new System.NotImplementedException();
}
}
-
""",
}.RunAsync();
@@ -11900,4 +11880,27 @@ class C1 : I1
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
LanguageVersion = LanguageVersionExtensions.CSharpNext,
}.RunAsync();
+
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79584")]
+ public Task TestImplementIDisposable_DisposePattern_LF_EndOfLine()
+ => new VerifyCS.Test
+ {
+ TestCode = """
+ using System;
+ class C : {|CS0535:IDisposable|}{|CS1513:|}{|CS1514:|}
+ """.Replace("\r\n", "\n"),
+ FixedCode = $$"""
+ using System;
+ class C : IDisposable
+ {
+ private bool disposedValue;
+
+ {{DisposePattern("protected virtual ", "C", "public void ")}}
+ }
+ """.Replace("\r\n", "\n"),
+ CodeActionIndex = 1,
+ ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
+ LanguageVersion = LanguageVersionExtensions.CSharpNext,
+ Options = { { FormattingOptions2.NewLine, "\n" } },
+ }.RunAsync();
}
diff --git a/src/Analyzers/CSharp/Tests/PopulateSwitch/PopulateSwitchStatementTests_FixAllTests.cs b/src/Analyzers/CSharp/Tests/PopulateSwitch/PopulateSwitchStatementTests_FixAllTests.cs
index e433e37ceedc..d06c8156b0c1 100644
--- a/src/Analyzers/CSharp/Tests/PopulateSwitch/PopulateSwitchStatementTests_FixAllTests.cs
+++ b/src/Analyzers/CSharp/Tests/PopulateSwitch/PopulateSwitchStatementTests_FixAllTests.cs
@@ -2,8 +2,6 @@
// 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.Threading.Tasks;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
@@ -271,7 +269,7 @@ void Method()
}
}
}
-
+
namespace ConsoleApplication1
{
@@ -292,7 +290,7 @@ void Method()
}
}
}
-
+
@@ -425,7 +423,7 @@ void Method()
}
}
}
-
+
namespace ConsoleApplication1
{
@@ -450,7 +448,7 @@ void Method()
}
}
}
-
+
@@ -477,7 +475,7 @@ void Method()
}
}
}
-
+
""");
diff --git a/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs
index d895d7cd27e5..9db8378b51b0 100644
--- a/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs
+++ b/src/EditorFeatures/CSharpTest/CodeActions/GenerateType/GenerateTypeTests.cs
@@ -5068,7 +5068,6 @@ X void X
+
using System;
@@ -649,7 +647,7 @@ public interface IBase
{
bool TestMethod();
}
-
+
using System;
@@ -700,7 +698,7 @@ public interface IBase
{
Uri TestMethod();
}
-
+
using System;
@@ -750,7 +748,7 @@ public interface IBase
{
bool TestMethod(Uri endpoint);
}
-
+
using System;
@@ -807,7 +805,7 @@ public interface IBase
{
event EventHandler TestEvent;
}
-
+
using System;
@@ -859,14 +857,14 @@ public class Base
{
public Uri Endpoint { get; set; }
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -899,14 +897,14 @@ public class Base
{
public Uri Endpoint { get; set; }
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -943,14 +941,14 @@ public class Base
{
public Uri Endpoint { get; set; }
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -1000,14 +998,14 @@ public bool TestProperty
}
}
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -1047,14 +1045,14 @@ public class Base
return Enumerable.Range(0, 5).Sum();
}
}
-
+
using System.Linq;
public class Derived : Base
{
}
-
+
""");
@@ -1121,7 +1119,7 @@ public class Base
public class Derived : Base
{
}
-
+
""");
@@ -1184,7 +1182,7 @@ public class Base
public class Derived : Base
{
}
-
+
""");
@@ -1239,7 +1237,7 @@ public int TestMethod()
public class Derived : Base
{
}
-
+
""");
@@ -1282,14 +1280,14 @@ public int TestMethod()
return 5;
}
}
-
+
using System.Linq;
public class Derived : Base
{
}
-
+
""");
@@ -1329,14 +1327,14 @@ public class Base
{
public Uri Endpoint { get; set; }
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -1376,14 +1374,14 @@ public class Base
{
public Uri Endpoint { get; set; }
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -1429,7 +1427,7 @@ public int TestMethod()
Count((uri) => uri != null);
}
}
-
+
using System;
using System.Linq;
@@ -1437,7 +1435,7 @@ public int TestMethod()
public class Derived : Base
{
}
-
+
""");
@@ -1492,7 +1490,7 @@ public int TestMethod()
public class Derived : Base
{
}
-
+
""");
@@ -1888,7 +1886,7 @@ public void TestMethod()
public class Derived : Base
{
}
-
+
""");
@@ -1941,7 +1939,7 @@ public void TestMethod()
public class Derived : Base
{
}
-
+
""");
@@ -2170,7 +2168,7 @@ class Base
{
public Other GetOther() => null;
}
-
+
namespace X.Y;
class Derived : A.B.Base
@@ -2523,14 +2521,14 @@ public Uri Endpoint()
return new Uri("http://localhost");
}
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -2572,14 +2570,14 @@ public bool TestMethod(Uri endpoint)
return endpoint.Equals(localhost);
}
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -2623,14 +2621,14 @@ public bool TestMethod()
return endpoint1.Equals(endpoint2);
}
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -2684,14 +2682,14 @@ public event EventHandler Test[||]Event
}
}
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -2725,14 +2723,14 @@ public class Base
{
public var endpoint = new Uri("http://localhost");
}
-
+
using System;
public class Derived : Base
{
}
-
+
""");
@@ -2766,14 +2764,14 @@ public class Base
{
public var range = Enumerable.Range(0, 5);
}
-
+
using System.Linq;
public class Derived : Base
{
}
-
+
""");
@@ -3957,11 +3955,11 @@ public class Derived : BaseClass
internal Task TestWithPullMemberDialogAsync(
string initialMarkUp,
string expectedResult,
- IEnumerable<(string name, bool makeAbstract)> selection = null,
- string destinationName = null,
+ IEnumerable<(string name, bool makeAbstract)>? selection = null,
+ string? destinationName = null,
int index = 0,
- TestParameters parameters = null,
- OptionsCollection options = null)
+ TestParameters? parameters = null,
+ OptionsCollection? options = null)
{
var service = new TestPullMemberUpService(selection, destinationName);
diff --git a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb
index 0c8f0d0ce0ea..a0581c4e2a0f 100644
--- a/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb
+++ b/src/EditorFeatures/VisualBasicTest/ExtractMethod/ExtractMethodTests.LanguageInteraction.vb
@@ -2709,7 +2709,7 @@ End Class
Private Shared Function NewMethod() As Integer
Return 100
End Function
-End Class
+End Class
Await TestExtractMethodAsync(code, expected)
End Function
diff --git a/src/Features/CSharpTest/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorTests.cs b/src/Features/CSharpTest/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorTests.cs
index b8507cedb432..a6fb2b018ec7 100644
--- a/src/Features/CSharpTest/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorTests.cs
+++ b/src/Features/CSharpTest/ConvertPrimaryToRegularConstructor/ConvertPrimaryToRegularConstructorTests.cs
@@ -2575,7 +2575,6 @@ public Class1()
{
}
}
-
""",
LanguageVersion = LanguageVersion.CSharp12,
}.RunAsync();
diff --git a/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs b/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs
index e4159d978041..39fed7b737fe 100644
--- a/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs
+++ b/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs
@@ -229,7 +229,6 @@ void M()
{
}
}
-
""";
await new Test
@@ -312,7 +311,6 @@ internal record MyBase
{
public string S { get; set; }
}
-
""";
await new Test
diff --git a/src/Features/CSharpTest/GenerateOverrides/GenerateOverridesTests.cs b/src/Features/CSharpTest/GenerateOverrides/GenerateOverridesTests.cs
index 6e6d09d34693..6e3f2bfe078c 100644
--- a/src/Features/CSharpTest/GenerateOverrides/GenerateOverridesTests.cs
+++ b/src/Features/CSharpTest/GenerateOverrides/GenerateOverridesTests.cs
@@ -74,7 +74,6 @@ public override string ToString()
return base.ToString();
}
}
-
""", ["Equals", "GetHashCode", "ToString"]);
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateOverrides)]
@@ -95,7 +94,6 @@ public override string ToString()
return base.ToString();
}
}
-
""", ["GetHashCode", "ToString"]);
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateOverrides)]
diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingExtensions.cs
index 6e2e935413c3..4c8cdde6c199 100644
--- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingExtensions.cs
+++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingExtensions.cs
@@ -281,31 +281,34 @@ static IEnumerable EnumerateAnnotatedSpans(SyntaxNode node, SyntaxAnno
var (firstToken, lastToken) = nodeOrToken.AsNode(out var childNode)
? (childNode.GetFirstToken(includeZeroWidth: true), childNode.GetLastToken(includeZeroWidth: true))
: (nodeOrToken.AsToken(), nodeOrToken.AsToken());
- yield return GetSpan(firstToken, lastToken);
+ yield return GetSpanIncludingPreviousAndNextTokens(firstToken, lastToken);
}
}
}
- internal static TextSpan GetSpan(SyntaxToken firstToken, SyntaxToken lastToken)
+ ///
+ /// Attempt to get a span that encompassed these tokens, but is expanded to go from the normal start of the
+ /// token that precedes them to the normal end of the token that follows. If there is no token that precedes
+ /// or follows, then we expand to consume at least the full span of the and
+ /// so that we at least will try to format any trivia on them.
+ ///
+ internal static TextSpan GetSpanIncludingPreviousAndNextTokens(SyntaxToken firstToken, SyntaxToken lastToken)
{
var previousToken = firstToken.GetPreviousToken();
- var nextToken = lastToken.GetNextToken();
-
- if (previousToken.RawKind != 0)
- {
- firstToken = previousToken;
- }
+ var start = previousToken.RawKind != 0
+ ? previousToken.SpanStart
+ : firstToken.FullSpan.Start;
- if (nextToken.RawKind != 0)
- {
- lastToken = nextToken;
- }
+ var nextToken = lastToken.GetNextToken();
+ var end = nextToken.RawKind != 0
+ ? nextToken.Span.End
+ : lastToken.FullSpan.End;
- return TextSpan.FromBounds(firstToken.SpanStart, lastToken.Span.End);
+ return TextSpan.FromBounds(start, end);
}
internal static TextSpan GetElasticSpan(SyntaxToken token)
- => GetSpan(token, token);
+ => GetSpanIncludingPreviousAndNextTokens(token, token);
private static IEnumerable AggregateSpans(IEnumerable spans)
{