Skip to content

Commit 8c172ff

Browse files
committed
Restrict whitespace collapse between methods to Metadata As Source
1 parent 4e5a229 commit 8c172ff

30 files changed

+432
-136
lines changed

src/EditorFeatures/CSharpTest/Structure/AccessorDeclarationStructureTests.cs

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
using Microsoft.CodeAnalysis.CSharp.Syntax;
88
using Microsoft.CodeAnalysis.Structure;
99
using Microsoft.CodeAnalysis.Test.Utilities;
10-
using Microsoft.CodeAnalysis.Text;
1110
using Xunit;
1211

1312
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
1413
{
15-
public class AccessorDeclarationTests : AbstractCSharpSyntaxNodeStructureTests<AccessorDeclarationSyntax>
14+
public class AccessorDeclarationStructureTests : AbstractCSharpSyntaxNodeStructureTests<AccessorDeclarationSyntax>
1615
{
1716
internal override AbstractSyntaxStructureProvider CreateProvider() => new AccessorDeclarationStructureProvider();
1817

@@ -159,22 +158,16 @@ public string Text
159158
{
160159
$${|hint:get{|textspan:
161160
{
162-
}|}
163-
|}
161+
}|}|}
162+
164163
set
165164
{
166165
}
167166
}
168167
}";
169168

170169
await VerifyBlockSpansAsync(code,
171-
new BlockSpan(
172-
isCollapsible: true,
173-
textSpan: TextSpan.FromBounds(56, 80),
174-
hintSpan: TextSpan.FromBounds(53, 78),
175-
type: BlockTypes.Nonstructural,
176-
bannerText: CSharpStructureHelpers.Ellipsis,
177-
autoCollapse: true));
170+
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
178171
}
179172

180173
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
@@ -189,8 +182,8 @@ public string Text
189182
// Getter|}
190183
$${|hint2:get{|textspan2:
191184
{
192-
}|}
193-
|}
185+
}|}|}
186+
194187
set
195188
{
196189
}
@@ -200,13 +193,7 @@ public string Text
200193

201194
await VerifyBlockSpansAsync(code,
202195
Region("span1", "// My ...", autoCollapse: true),
203-
new BlockSpan(
204-
isCollapsible: true,
205-
textSpan: TextSpan.FromBounds(90, 114),
206-
hintSpan: TextSpan.FromBounds(87, 112),
207-
type: BlockTypes.Nonstructural,
208-
bannerText: CSharpStructureHelpers.Ellipsis,
209-
autoCollapse: true));
196+
Region("textspan2", "hint2", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
210197
}
211198

212199
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
@@ -221,8 +208,8 @@ public string Text
221208
Getter */|}
222209
$${|hint2:get{|textspan2:
223210
{
224-
}|}
225-
|}
211+
}|}|}
212+
226213
set
227214
{
228215
}
@@ -232,13 +219,7 @@ public string Text
232219

233220
await VerifyBlockSpansAsync(code,
234221
Region("span1", "/* My ...", autoCollapse: true),
235-
new BlockSpan(
236-
isCollapsible: true,
237-
textSpan: TextSpan.FromBounds(93, 117),
238-
hintSpan: TextSpan.FromBounds(90, 115),
239-
type: BlockTypes.Nonstructural,
240-
bannerText: CSharpStructureHelpers.Ellipsis,
241-
autoCollapse: true));
222+
Region("textspan2", "hint2", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
242223
}
243224

244225
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]

src/EditorFeatures/CSharpTest/Structure/ConstructorDeclarationStructureTests.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.CodeAnalysis.CSharp.Syntax;
88
using Microsoft.CodeAnalysis.Structure;
99
using Microsoft.CodeAnalysis.Test.Utilities;
10-
using Microsoft.CodeAnalysis.Text;
1110
using Xunit;
1211

1312
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
@@ -162,23 +161,17 @@ public async Task TestConstructor10()
162161
const string code = @"
163162
class C
164163
{
165-
$$public C()
164+
{|hint:$$public C(){|textspan:
166165
{
167-
}
166+
}|}|}
168167
169168
public C(int x)
170169
{
171170
}
172171
}";
173172

174173
await VerifyBlockSpansAsync(code,
175-
new BlockSpan(
176-
isCollapsible: true,
177-
textSpan: TextSpan.FromBounds(28, 44),
178-
hintSpan: TextSpan.FromBounds(18, 42),
179-
type: BlockTypes.Nonstructural,
180-
bannerText: CSharpStructureHelpers.Ellipsis,
181-
autoCollapse: true));
174+
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
182175
}
183176

184177
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]

src/EditorFeatures/CSharpTest/Structure/ConversionOperatorDeclarationStructureTests.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.CodeAnalysis.CSharp.Syntax;
88
using Microsoft.CodeAnalysis.Structure;
99
using Microsoft.CodeAnalysis.Test.Utilities;
10-
using Microsoft.CodeAnalysis.Text;
1110
using Xunit;
1211

1312
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
@@ -55,23 +54,17 @@ public async Task TestOperator3()
5554
const string code = @"
5655
class C
5756
{
58-
$$public static explicit operator C(byte i)
57+
{|hint:$$public static explicit operator C(byte i){|textspan:
5958
{
60-
}
59+
}|}|}
6160
6261
public static explicit operator C(short i)
6362
{
6463
}
6564
}";
6665

6766
await VerifyBlockSpansAsync(code,
68-
new BlockSpan(
69-
isCollapsible: true,
70-
textSpan: TextSpan.FromBounds(59, 75),
71-
hintSpan: TextSpan.FromBounds(18, 73),
72-
type: BlockTypes.Nonstructural,
73-
bannerText: CSharpStructureHelpers.Ellipsis,
74-
autoCollapse: true));
67+
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
7568
}
7669

7770
[Fact,

src/EditorFeatures/CSharpTest/Structure/EnumDeclarationStructureTests.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.CodeAnalysis.CSharp.Syntax;
88
using Microsoft.CodeAnalysis.Structure;
99
using Microsoft.CodeAnalysis.Test.Utilities;
10-
using Microsoft.CodeAnalysis.Text;
1110
using Xunit;
1211

1312
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
@@ -55,22 +54,16 @@ await VerifyBlockSpansAsync(code,
5554
public async Task TestEnum3(string typeKind)
5655
{
5756
var code = $@"
58-
$$enum E
57+
{{|hint:$$enum E{{|textspan:
5958
{{
60-
}}
59+
}}|}}|}}
6160
6261
{typeKind} Following
6362
{{
6463
}}";
6564

6665
await VerifyBlockSpansAsync(code,
67-
new BlockSpan(
68-
isCollapsible: true,
69-
textSpan: TextSpan.FromBounds(8, 16),
70-
hintSpan: TextSpan.FromBounds(2, 14),
71-
type: BlockTypes.Nonstructural,
72-
bannerText: CSharpStructureHelpers.Ellipsis,
73-
autoCollapse: false));
66+
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
7467
}
7568

7669
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]

src/EditorFeatures/CSharpTest/Structure/EventDeclarationStructureTests.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.CodeAnalysis.CSharp.Syntax;
88
using Microsoft.CodeAnalysis.Structure;
99
using Microsoft.CodeAnalysis.Test.Utilities;
10-
using Microsoft.CodeAnalysis.Text;
1110
using Xunit;
1211

1312
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
@@ -61,11 +60,11 @@ public async Task TestEvent3()
6160
const string code = @"
6261
class C
6362
{
64-
$$event EventHandler E
63+
{|hint:$$event EventHandler E{|textspan:
6564
{
6665
add { }
6766
remove { }
68-
}
67+
}|}|}
6968
7069
event EventHandler E2
7170
{
@@ -75,13 +74,7 @@ event EventHandler E2
7574
}";
7675

7776
await VerifyBlockSpansAsync(code,
78-
new BlockSpan(
79-
isCollapsible: true,
80-
textSpan: TextSpan.FromBounds(38, 91),
81-
hintSpan: TextSpan.FromBounds(18, 89),
82-
type: BlockTypes.Nonstructural,
83-
bannerText: CSharpStructureHelpers.Ellipsis,
84-
autoCollapse: true));
77+
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
8578
}
8679

8780
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]

src/EditorFeatures/CSharpTest/Structure/IndexerDeclarationStructureTests.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.CodeAnalysis.CSharp.Syntax;
88
using Microsoft.CodeAnalysis.Structure;
99
using Microsoft.CodeAnalysis.Test.Utilities;
10-
using Microsoft.CodeAnalysis.Text;
1110
using Xunit;
1211

1312
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
@@ -55,22 +54,16 @@ public async Task TestIndexer3()
5554
const string code = @"
5655
class C
5756
{
58-
$$public string this[int index]
57+
{|hint:$$public string this[int index]{|textspan:
5958
{
6059
get { }
61-
}
60+
}|}|}
6261
6362
int Value => 0;
6463
}";
6564

6665
await VerifyBlockSpansAsync(code,
67-
new BlockSpan(
68-
isCollapsible: true,
69-
textSpan: TextSpan.FromBounds(47, 80),
70-
hintSpan: TextSpan.FromBounds(18, 78),
71-
type: BlockTypes.Nonstructural,
72-
bannerText: CSharpStructureHelpers.Ellipsis,
73-
autoCollapse: true));
66+
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
7467
}
7568

7669
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis.CSharp.Structure;
7+
using Microsoft.CodeAnalysis.CSharp.Syntax;
8+
using Microsoft.CodeAnalysis.Structure;
9+
using Microsoft.CodeAnalysis.Test.Utilities;
10+
using Microsoft.CodeAnalysis.Text;
11+
using Xunit;
12+
13+
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure.MetadataAsSource
14+
{
15+
public class AccessorDeclarationStructureTests : AbstractCSharpSyntaxNodeStructureTests<AccessorDeclarationSyntax>
16+
{
17+
protected override string WorkspaceKind => CodeAnalysis.WorkspaceKind.MetadataAsSource;
18+
internal override AbstractSyntaxStructureProvider CreateProvider() => new AccessorDeclarationStructureProvider();
19+
20+
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
21+
public async Task TestPropertyGetter3()
22+
{
23+
const string code = @"
24+
class C
25+
{
26+
public string Text
27+
{
28+
$${|hint:get{|textspan:
29+
{
30+
}|}
31+
|}
32+
set
33+
{
34+
}
35+
}
36+
}";
37+
38+
await VerifyBlockSpansAsync(code,
39+
new BlockSpan(
40+
isCollapsible: true,
41+
textSpan: TextSpan.FromBounds(56, 80),
42+
hintSpan: TextSpan.FromBounds(53, 78),
43+
type: BlockTypes.Nonstructural,
44+
bannerText: CSharpStructureHelpers.Ellipsis,
45+
autoCollapse: true));
46+
}
47+
48+
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
49+
public async Task TestPropertyGetterWithSingleLineComments3()
50+
{
51+
const string code = @"
52+
class C
53+
{
54+
public string Text
55+
{
56+
{|span1:// My
57+
// Getter|}
58+
$${|hint2:get{|textspan2:
59+
{
60+
}|}
61+
|}
62+
set
63+
{
64+
}
65+
}
66+
}
67+
";
68+
69+
await VerifyBlockSpansAsync(code,
70+
Region("span1", "// My ...", autoCollapse: true),
71+
new BlockSpan(
72+
isCollapsible: true,
73+
textSpan: TextSpan.FromBounds(90, 114),
74+
hintSpan: TextSpan.FromBounds(87, 112),
75+
type: BlockTypes.Nonstructural,
76+
bannerText: CSharpStructureHelpers.Ellipsis,
77+
autoCollapse: true));
78+
}
79+
80+
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
81+
public async Task TestPropertyGetterWithMultiLineComments3()
82+
{
83+
const string code = @"
84+
class C
85+
{
86+
public string Text
87+
{
88+
{|span1:/* My
89+
Getter */|}
90+
$${|hint2:get{|textspan2:
91+
{
92+
}|}
93+
|}
94+
set
95+
{
96+
}
97+
}
98+
}
99+
";
100+
101+
await VerifyBlockSpansAsync(code,
102+
Region("span1", "/* My ...", autoCollapse: true),
103+
new BlockSpan(
104+
isCollapsible: true,
105+
textSpan: TextSpan.FromBounds(93, 117),
106+
hintSpan: TextSpan.FromBounds(90, 115),
107+
type: BlockTypes.Nonstructural,
108+
bannerText: CSharpStructureHelpers.Ellipsis,
109+
autoCollapse: true));
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)