Skip to content

Commit 154c885

Browse files
Merge branch 'main' into removeProjectAnalyzer2
2 parents 162ec68 + ff34293 commit 154c885

File tree

10 files changed

+426
-31
lines changed

10 files changed

+426
-31
lines changed

Ide.slnf

Lines changed: 248 additions & 0 deletions
Large diffs are not rendered by default.

eng/targets/Imports.targets

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,26 @@
401401
<Target Name="Workaround_CopyResolvedFilesToPublishPreserveNewest" BeforeTargets="_CopyResolvedFilesToPublishPreserveNewest" DependsOnTargets="GenerateManifests" />
402402

403403
<Import Project="DoNotGenerateSatelliteAssemblies_Workaround.targets" Condition="'$(GenerateSatelliteAssemblies)' == 'false'" />
404+
405+
<!--
406+
This target uses Inputs/Outputs so when it is skipped because they are up to date, ApplyOptimizations is skipped.
407+
This is a workaround for https://github.com/dotnet/roslyn/issues/77941.
408+
-->
409+
<Target Name="_DisableApplyOptimizations"
410+
BeforeTargets="_InitializeAssemblyOptimizationWithTargetAssembly">
411+
<PropertyGroup>
412+
<EnableNgenOptimization>false</EnableNgenOptimization>
413+
</PropertyGroup>
414+
</Target>
415+
<Target Name="_DetermineIfApplyOptimizationsShouldBeDisabled"
416+
AfterTargets="_DisableApplyOptimizations"
417+
Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)"
418+
Outputs="@(IntermediateAssembly);$(PostCompileBinaryModificationSentinelFile)">
419+
<CallTarget Targets="_EnableApplyOptimizations" />
420+
</Target>
421+
<Target Name="_EnableApplyOptimizations">
422+
<PropertyGroup>
423+
<EnableNgenOptimization>true</EnableNgenOptimization>
424+
</PropertyGroup>
425+
</Target>
404426
</Project>

eng/targets/VisualStudio.FastUpToDateCheckWorkarounds.targets

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,16 @@
1111

1212
<Target Name="CollectVsixUpToDateCheckBuilt">
1313
</Target>
14+
15+
<PropertyGroup>
16+
<CollectUpToDateCheckInputDesignTimeDependsOn>$(CollectUpToDateCheckInputDesignTimeDependsOn);RemoveBuildOutputSourceItems</CollectUpToDateCheckInputDesignTimeDependsOn>
17+
</PropertyGroup>
18+
19+
<!-- Add a workaround for https://github.com/dotnet/project-system/issues/9651 until we decide what we want to do there long term. -->
20+
<Target Name="RemoveBuildOutputSourceItems" DependsOnTargets="AddUpToDateCheckVSIXSourceItems" Condition="'$(CreateVsixContainer)' == 'true'">
21+
<ItemGroup>
22+
<_ItemsInObjDirectory Include="$(IntermediateOutputPath)\**\*" Set="VsixItems" />
23+
<UpToDateCheckInput Remove="@(_ItemsInObjDirectory)" MatchOnMetadata="Set" />
24+
</ItemGroup>
25+
</Target>
1426
</Project>

src/Analyzers/CSharp/Tests/MisplacedUsingDirectives/MisplacedUsingDirectivesTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ namespace TestNamespace
10421042
}
10431043

10441044
[Fact]
1045-
public Task WhenInsidePreferred_UsingsInBoth_UsingsMoved_FileScopedNamespaec()
1045+
public Task WhenInsidePreferred_UsingsInBoth_UsingsMoved_FileScopedNamespace()
10461046
{
10471047
var testCode = """
10481048
[|using Microsoft.CodeAnalysis;|]
@@ -1054,6 +1054,7 @@ namespace TestNamespace;
10541054

10551055
var fixedTestCode = """
10561056
namespace TestNamespace;
1057+
10571058
{|Warning:using Microsoft.CodeAnalysis;|}
10581059
10591060
using System;

src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignatureTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,74 @@ await TestChangeSignatureViaCommandAsync(
6767
expectedUpdatedInvocationDocumentCode: expectedCode);
6868
}
6969

70+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75676")]
71+
public async Task TestForPrimaryConstructor_ViaCommand()
72+
{
73+
var markup = """
74+
public class Base {
75+
public $$Base(string Item2, string Item1)
76+
{
77+
}
78+
}
79+
80+
public class Derived() : Base("Item2", "Item1")
81+
{
82+
}
83+
""";
84+
var expectedCode = """
85+
public class Base {
86+
public Base(string Item1, string Item2)
87+
{
88+
}
89+
}
90+
91+
public class Derived() : Base("Item1", "Item2")
92+
{
93+
}
94+
""";
95+
96+
await TestChangeSignatureViaCommandAsync(
97+
LanguageNames.CSharp,
98+
markup: markup,
99+
updatedSignature: [1, 0],
100+
expectedUpdatedInvocationDocumentCode: expectedCode);
101+
}
102+
103+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75676")]
104+
public async Task TestForPrimaryConstructorParamsArray_ViaCommand()
105+
{
106+
var markup = """
107+
public class Base {
108+
public $$Base(string Item2, string Item1, params object[] items)
109+
{
110+
Console.WriteLine(items.Length);
111+
}
112+
}
113+
114+
public class Derived() : Base("Item2", "Item1", 1, "test", true)
115+
{
116+
}
117+
""";
118+
var expectedCode = """
119+
public class Base {
120+
public Base(string Item1, string Item2, params object[] items)
121+
{
122+
Console.WriteLine(items.Length);
123+
}
124+
}
125+
126+
public class Derived() : Base("Item1", "Item2", 1, "test", true)
127+
{
128+
}
129+
""";
130+
131+
await TestChangeSignatureViaCommandAsync(
132+
LanguageNames.CSharp,
133+
markup: markup,
134+
updatedSignature: [1, 0, 2],
135+
expectedUpdatedInvocationDocumentCode: expectedCode);
136+
}
137+
70138
[Fact]
71139
public async Task TestOnLambdaWithTwoDiscardParameters_ViaCommand()
72140
{

src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ internal sealed class CSharpChangeSignatureService : AbstractChangeSignatureServ
8080
SyntaxKind.SimpleLambdaExpression,
8181
SyntaxKind.ParenthesizedLambdaExpression,
8282
SyntaxKind.NameMemberCref,
83+
SyntaxKind.PrimaryConstructorBaseType,
8384
];
8485

8586
private static readonly ImmutableArray<SyntaxKind> _updatableNodeKinds =
@@ -104,6 +105,7 @@ internal sealed class CSharpChangeSignatureService : AbstractChangeSignatureServ
104105
SyntaxKind.RecordDeclaration,
105106
SyntaxKind.StructDeclaration,
106107
SyntaxKind.ClassDeclaration,
108+
SyntaxKind.PrimaryConstructorBaseType,
107109
];
108110

109111
[ImportingConstructor]
@@ -272,6 +274,7 @@ private static bool InSymbolHeader(SyntaxNode matchingNode, int position)
272274
case SyntaxKind.ObjectCreationExpression:
273275
return ((ObjectCreationExpressionSyntax)matchingNode).Type;
274276

277+
case SyntaxKind.PrimaryConstructorBaseType:
275278
case SyntaxKind.ConstructorDeclaration:
276279
case SyntaxKind.IndexerDeclaration:
277280
case SyntaxKind.ThisConstructorInitializer:
@@ -507,6 +510,22 @@ or SyntaxKind.StructDeclaration
507510
cancellationToken));
508511
}
509512

513+
if (updatedNode is PrimaryConstructorBaseTypeSyntax primaryConstructor)
514+
{
515+
var symbolInfo = semanticModel.GetSymbolInfo((PrimaryConstructorBaseTypeSyntax)originalNode, cancellationToken);
516+
517+
return primaryConstructor.WithArgumentList(
518+
UpdateArgumentList(
519+
document,
520+
declarationSymbol,
521+
signaturePermutation,
522+
primaryConstructor.ArgumentList,
523+
isReducedExtensionMethod: false,
524+
IsParamsArrayExpanded(semanticModel, primaryConstructor, symbolInfo, cancellationToken),
525+
originalNode.SpanStart,
526+
cancellationToken));
527+
}
528+
510529
Debug.Assert(false, "Unknown reference location");
511530
return null;
512531
}
@@ -618,6 +637,7 @@ private static bool IsParamsArrayExpanded(SemanticModel semanticModel, SyntaxNod
618637
BaseObjectCreationExpressionSyntax objectCreation => objectCreation.ArgumentList,
619638
ConstructorInitializerSyntax constructorInitializer => constructorInitializer.ArgumentList,
620639
ElementAccessExpressionSyntax elementAccess => elementAccess.ArgumentList,
640+
PrimaryConstructorBaseTypeSyntax primaryConstructor => primaryConstructor.ArgumentList,
621641
_ => throw ExceptionUtilities.UnexpectedValue(node.Kind())
622642
};
623643

src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ class Program : MyBase
12691269
// this is my real document header
12701270
12711271
namespace ConsoleApp185;
1272+
12721273
using System;
12731274
using System.Collections.Generic;
12741275

src/Workspaces/CSharpTest/Formatting/FormattingTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12087,6 +12087,25 @@ class C { }
1208712087
""");
1208812088
}
1208912089

12090+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/67400")]
12091+
public async Task FileScopedNamespaceNewline()
12092+
{
12093+
await AssertFormatAsync(
12094+
expected: """
12095+
namespace Some.Namespace;
12096+
12097+
public class MyClass
12098+
{
12099+
}
12100+
""",
12101+
code: """
12102+
namespace Some.Namespace;
12103+
public class MyClass
12104+
{
12105+
}
12106+
""");
12107+
}
12108+
1209012109
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/56498")]
1209112110
public async Task NewInImplicitObjectCreation()
1209212111
{

src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Collections.Concurrent;
67
using System.Collections.Generic;
78
using System.Collections.Immutable;
89
using System.Diagnostics;
@@ -58,7 +59,8 @@ internal sealed partial class SolutionState
5859
// holds on data calculated based on the AnalyzerReferences list
5960
private readonly Lazy<HostDiagnosticAnalyzers> _lazyAnalyzers;
6061

61-
private ImmutableDictionary<string, ImmutableArray<DocumentId>> _lazyFilePathToRelatedDocumentIds = ImmutableDictionary<string, ImmutableArray<DocumentId>>.Empty.WithComparers(FilePathComparer);
62+
// Mapping from file path to the set of documents that are related to it.
63+
private readonly ConcurrentDictionary<string, ImmutableArray<DocumentId>> _lazyFilePathToRelatedDocumentIds = new ConcurrentDictionary<string, ImmutableArray<DocumentId>>(FilePathComparer);
6264

6365
private SolutionState(
6466
string? workspaceKind,
@@ -1169,16 +1171,12 @@ public ImmutableArray<DocumentId> GetDocumentIdsWithFilePath(string? filePath)
11691171
if (string.IsNullOrEmpty(filePath))
11701172
return [];
11711173

1172-
return ImmutableInterlocked.GetOrAdd(
1173-
ref _lazyFilePathToRelatedDocumentIds,
1174-
filePath,
1175-
static (filePath, @this) => ComputeDocumentIdsWithFilePath(@this, filePath),
1176-
this);
1174+
return _lazyFilePathToRelatedDocumentIds.GetOrAdd(filePath, ComputeDocumentIdsWithFilePath, this);
11771175

1178-
static ImmutableArray<DocumentId> ComputeDocumentIdsWithFilePath(SolutionState @this, string filePath)
1176+
static ImmutableArray<DocumentId> ComputeDocumentIdsWithFilePath(string filePath, SolutionState @this)
11791177
{
11801178
using var result = TemporaryArray<DocumentId>.Empty;
1181-
foreach (var (projectId, projectState) in @this.ProjectStates)
1179+
foreach (var (_, projectState) in @this.ProjectStates)
11821180
projectState.AddDocumentIdsWithFilePath(ref result.AsRef(), filePath);
11831181

11841182
return result.ToImmutableAndClear();

src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Rules/TokenBasedFormattingRule.cs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public override AbstractFormattingRule WithOptions(SyntaxFormattingOptions optio
190190
return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
191191
}
192192

193-
// ; * or ; * for using directive
193+
// ; * or ; * for using directive and file scoped namespace
194194
if (previousToken.Kind() == SyntaxKind.SemicolonToken)
195195
{
196196
return AdjustNewLinesAfterSemicolonToken(previousToken, currentToken);
@@ -225,31 +225,37 @@ MemberDeclarationSyntax or
225225
private AdjustNewLinesOperation AdjustNewLinesAfterSemicolonToken(
226226
SyntaxToken previousToken, SyntaxToken currentToken)
227227
{
228-
// between anything that isn't a using directive, we don't touch newlines after a semicolon
229-
if (previousToken.Parent is not UsingDirectiveSyntax previousUsing)
230-
return CreateAdjustNewLinesOperation(0, AdjustNewLinesOption.PreserveLines);
231-
232-
// if the user is separating using-groups, and we're between two usings, and these
233-
// usings *should* be separated, then do so (if the usings were already properly
234-
// sorted).
235-
if (_options.SeparateImportDirectiveGroups &&
236-
currentToken.Parent is UsingDirectiveSyntax currentUsing &&
237-
UsingsAndExternAliasesOrganizer.NeedsGrouping(previousUsing, currentUsing))
238-
{
239-
RoslynDebug.AssertNotNull(currentUsing.Parent);
240-
241-
var usings = GetUsings(currentUsing.Parent);
242-
if (usings.IsSorted(UsingsAndExternAliasesDirectiveComparer.SystemFirstInstance) ||
243-
usings.IsSorted(UsingsAndExternAliasesDirectiveComparer.NormalInstance))
228+
if (previousToken.Parent is UsingDirectiveSyntax previousUsing)
229+
{
230+
// if the user is separating using-groups, and we're between two usings, and these
231+
// usings *should* be separated, then do so (if the usings were already properly
232+
// sorted).
233+
if (_options.SeparateImportDirectiveGroups &&
234+
currentToken.Parent is UsingDirectiveSyntax currentUsing &&
235+
UsingsAndExternAliasesOrganizer.NeedsGrouping(previousUsing, currentUsing))
244236
{
245-
// Force at least one blank line here.
246-
return CreateAdjustNewLinesOperation(2, AdjustNewLinesOption.PreserveLines);
237+
RoslynDebug.AssertNotNull(currentUsing.Parent);
238+
239+
var usings = GetUsings(currentUsing.Parent);
240+
if (usings.IsSorted(UsingsAndExternAliasesDirectiveComparer.SystemFirstInstance) ||
241+
usings.IsSorted(UsingsAndExternAliasesDirectiveComparer.NormalInstance))
242+
{
243+
// Force at least one blank line here.
244+
return CreateAdjustNewLinesOperation(2, AdjustNewLinesOption.PreserveLines);
245+
}
247246
}
247+
248+
// For all other cases where we have a using-directive, just make sure it's followed by
249+
// a new-line.
250+
return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
248251
}
249252

250-
// For all other cases where we have a using-directive, just make sure it's followed by
251-
// a new-line.
252-
return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
253+
// ensure that there is a newline after a file scoped namespace declaration
254+
if (previousToken.Parent is FileScopedNamespaceDeclarationSyntax)
255+
return CreateAdjustNewLinesOperation(2, AdjustNewLinesOption.PreserveLines);
256+
257+
// between anything that isn't a using directive or file scoped namespace declaration, we don't touch newlines after a semicolon
258+
return CreateAdjustNewLinesOperation(0, AdjustNewLinesOption.PreserveLines);
253259
}
254260

255261
private static SyntaxList<UsingDirectiveSyntax> GetUsings(SyntaxNode node)

0 commit comments

Comments
 (0)