Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master-vs-deps' into LSPFindAl…
Browse files Browse the repository at this point in the history
…lReferencesIcons
  • Loading branch information
davidwengier committed Sep 25, 2020
2 parents b206219 + 9192560 commit 9f10b94
Show file tree
Hide file tree
Showing 259 changed files with 6,262 additions and 1,855 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ If you want to get started using Roslyn's APIs to analyzer your code take a look

**The latest pre-release builds** are available from the following public NuGet feeds:
- [Compiler](https://dev.azure.com/dnceng/public/_packaging?_a=feed&feed=dotnet-tools): `https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json`
- [IDE Services](https://devdiv.visualstudio.com/DevDiv/_packaging?_a=feed&feed=vssdk): `https://devdiv.pkgs.visualstudio.com/_packaging/vssdk/nuget/v3/index.json`
- [IDE Services](https://dev.azure.com/azure-public/vside/_packaging?_a=feed&feed=vssdk): `https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json`
- [.NET SDK](https://dev.azure.com/dnceng/public/_packaging?_a=feed&feed=dotnet5): `https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json`

[//]: # (Begin current test results)
Expand Down
665 changes: 665 additions & 0 deletions Roslyn.sln

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
-->
<PropertyGroup>
<MajorVersion>3</MajorVersion>
<MinorVersion>8</MinorVersion>
<MinorVersion>9</MinorVersion>
<PatchVersion>0</PatchVersion>
<PreReleaseVersionLabel>4</PreReleaseVersionLabel>
<PreReleaseVersionLabel>1</PreReleaseVersionLabel>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<!--
By default the assembly version in official builds is "$(MajorVersion).$(MinorVersion).0.0".
Expand Down
4 changes: 2 additions & 2 deletions eng/config/PublishData.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
"version": "3.8.*",
"packageFeeds": "default",
"vsix": [ "https://dotnet.myget.org/F/roslyn/vsix/upload" ],
"channels": [ "dev16.8p3" ],
"channels": [ "dev16.8p4" ],
"vsBranch": "rel/d16.8",
"vsMajorVersion": 16
},
Expand All @@ -207,7 +207,7 @@
"version": "3.8.*",
"packageFeeds": "default",
"vsix": [ "https://dotnet.myget.org/F/roslyn/vsix/upload" ],
"channels": [ "dev16.8", "dev16.8p4" ],
"channels": [ "dev16.9", "dev16.9p1" ],
"vsBranch": "main",
"vsMajorVersion": 16
},
Expand Down
13 changes: 13 additions & 0 deletions eng/config/test/Core/InstallTraceListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <auto-generated/>

using System.Runtime.CompilerServices;
using Roslyn.Test.Utilities;

internal sealed class InitializeTestModule
{
[ModuleInitializer]
internal static void Initializer()
{
RuntimeHelpers.RunModuleConstructor(typeof(TestBase).Module.ModuleHandle);
}
}
1 change: 1 addition & 0 deletions src/Analyzers/CSharp/Analyzers/CSharpAnalyzers.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="$(MSBuildThisFileDirectory)RemoveUnusedMembers\CSharpRemoveUnusedMembersDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RemoveUnusedParametersAndValues\CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UseCollectionInitializer\CSharpUseCollectionInitializerDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UseImplicitObjectCreation\CSharpUseImplicitObjectCreationDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UseImplicitOrExplicitType\CSharpTypeStyleDiagnosticAnalyzerBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UseImplicitOrExplicitType\CSharpUseExplicitTypeDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UseImplicitOrExplicitType\CSharpUseImplicitTypeDiagnosticAnalyzer.cs" />
Expand Down
7 changes: 7 additions & 0 deletions src/Analyzers/CSharp/Analyzers/CSharpAnalyzersResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,11 @@
<data name="typeof_can_be_converted_ to_nameof" xml:space="preserve">
<value>'typeof' can be converted to 'nameof'</value>
</data>
<data name="Use_new" xml:space="preserve">
<value>Use 'new(...)'</value>
<comment>{Locked="new(...)"} This is a C# construct and should not be localized.</comment>
</data>
<data name="new_expression_can_be_simplified" xml:space="preserve">
<value>'new' expression can be simplified</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Utilities;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.CSharp.UseImplicitObjectCreation
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpUseImplicitObjectCreationDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public CSharpUseImplicitObjectCreationDiagnosticAnalyzer()
: base(IDEDiagnosticIds.UseImplicitObjectCreationDiagnosticId,
CSharpCodeStyleOptions.ImplicitObjectCreationWhenTypeIsApparent,
LanguageNames.CSharp,
new LocalizableResourceString(nameof(CSharpAnalyzersResources.Use_new), CSharpAnalyzersResources.ResourceManager, typeof(CSharpAnalyzersResources)),
new LocalizableResourceString(nameof(CSharpAnalyzersResources.new_expression_can_be_simplified), CSharpAnalyzersResources.ResourceManager, typeof(CSharpAnalyzersResources)))
{
}

public override DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SemanticSpanAnalysis;

protected override void InitializeWorker(AnalysisContext context)
=> context.RegisterSyntaxNodeAction(AnalyzeSyntax, SyntaxKind.ObjectCreationExpression);

private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
{
var options = context.Options;
var syntaxTree = context.Node.SyntaxTree;
var semanticModel = context.SemanticModel;
var cancellationToken = context.CancellationToken;

// Not available prior to C# 9.
if (((CSharpParseOptions)syntaxTree.Options).LanguageVersion < LanguageVersion.CSharp9)
return;

var optionSet = options.GetAnalyzerOptionSet(syntaxTree, cancellationToken);
var styleOption = options.GetOption(CSharpCodeStyleOptions.ImplicitObjectCreationWhenTypeIsApparent, syntaxTree, cancellationToken);
if (!styleOption.Value)
{
// Bail immediately if the user has disabled this feature.
return;
}

// type is apparent if we the object creation location is closely tied (spatially) to the explicit type. Specifically:
//
// 1. Variable declarations. i.e. `List<int> list = new ...`. Note: we will suppress ourselves if this
// is a field and the 'var' preferences would lead to preferring this as `var list = ...`
// 2. Expression-bodied constructs with an explicit return type. i.e. `List<int> Prop => new ...` or
// `List<int> GetValue(...) => ...` The latter doesn't necessarily have the object creation spatially next to
// the type. However, the type is always in a very easy to ascertain location in C#, so it is treated as
// apparent.

var objectCreation = (ObjectCreationExpressionSyntax)context.Node;

TypeSyntax? typeNode;

if (objectCreation.Parent.IsKind(SyntaxKind.EqualsValueClause) &&
objectCreation.Parent.Parent.IsKind(SyntaxKind.VariableDeclarator) &&
objectCreation.Parent.Parent.Parent is VariableDeclarationSyntax variableDeclaration &&
!variableDeclaration.Type.IsVar)
{
typeNode = variableDeclaration.Type;

var helper = CSharpUseImplicitTypeHelper.Instance;
if (helper.ShouldAnalyzeVariableDeclaration(variableDeclaration, cancellationToken) &&
helper.AnalyzeTypeName(typeNode, semanticModel, optionSet, cancellationToken).IsStylePreferred)
{
// this is a case where the user would prefer 'var'. don't offer to use an implicit object here.
return;
}
}
else if (objectCreation.Parent.IsKind(SyntaxKind.ArrowExpressionClause))
{
typeNode = objectCreation.Parent.Parent switch
{
LocalFunctionStatementSyntax localFunction => localFunction.ReturnType,
MethodDeclarationSyntax method => method.ReturnType,
ConversionOperatorDeclarationSyntax conversion => conversion.Type,
OperatorDeclarationSyntax op => op.ReturnType,
BasePropertyDeclarationSyntax property => property.Type,
AccessorDeclarationSyntax { RawKind: (int)SyntaxKind.GetAccessorDeclaration, Parent: AccessorListSyntax { Parent: BasePropertyDeclarationSyntax baseProperty } } accessor => baseProperty.Type,
_ => null,
};
}
else
{
// more cases can be added here if we discover more cases we think the type is readily apparent from context.
return;
}

if (typeNode == null)
return;

// Only offer if the type being constructed is the exact same as the type being assigned into. We don't
// want to change semantics by trying to instantiate something else.
var leftType = semanticModel.GetTypeInfo(typeNode, cancellationToken).Type;
var rightType = semanticModel.GetTypeInfo(objectCreation, cancellationToken).Type;

if (leftType is null || rightType is null)
return;

if (leftType.IsErrorType() || rightType.IsErrorType())
return;

if (!leftType.Equals(rightType, SymbolEqualityComparer.Default))
return;

context.ReportDiagnostic(DiagnosticHelper.Create(
Descriptor,
objectCreation.Type.GetLocation(),
styleOption.Notification.Severity,
ImmutableArray.Create(objectCreation.GetLocation()),
properties: null));
}
}
}
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">Použít lokální funkci</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">Použít porovnávání vzorů</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">Příkaz if lze zjednodušit.</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="translated">typeof se dá převést na nameof.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">Lokale Funktion verwenden</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">Musterabgleich verwenden</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">Die If-Anweisung kann vereinfacht werden.</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="new">'typeof' can be converted to 'nameof'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">Usar función local</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">Usar coincidencia de patrones</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">La instrucción "if" se puede simplificar</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="new">'typeof' can be converted to 'nameof'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">Utiliser une fonction locale</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">Utiliser les critères spéciaux</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">L'instruction 'if' peut être simplifiée</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="new">'typeof' can be converted to 'nameof'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">Usa la funzione locale</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">Usa i criteri di ricerca</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">L'istruzione 'If' può essere semplificata</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="new">'typeof' can be converted to 'nameof'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">ローカル関数を使用します</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">パターン マッチングを使用します</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">'if' ステートメントは簡素化できます</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="new">'typeof' can be converted to 'nameof'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">로컬 함수 사용</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">패턴 일치 사용</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">'if' 문을 간단하게 줄일 수 있습니다.</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="new">'typeof' can be converted to 'nameof'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analyzers/xlf/CSharpAnalyzersResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
<target state="translated">Użyj funkcji lokalnej</target>
<note />
</trans-unit>
<trans-unit id="Use_new">
<source>Use 'new(...)'</source>
<target state="new">Use 'new(...)'</target>
<note>{Locked="new(...)"} This is a C# construct and should not be localized.</note>
</trans-unit>
<trans-unit id="Use_pattern_matching">
<source>Use pattern matching</source>
<target state="translated">Użyj dopasowywania wzorców</target>
Expand Down Expand Up @@ -262,6 +267,11 @@
<target state="translated">Instrukcja „if” może zostać uproszczona</target>
<note />
</trans-unit>
<trans-unit id="new_expression_can_be_simplified">
<source>'new' expression can be simplified</source>
<target state="new">'new' expression can be simplified</target>
<note />
</trans-unit>
<trans-unit id="typeof_can_be_converted_ to_nameof">
<source>'typeof' can be converted to 'nameof'</source>
<target state="new">'typeof' can be converted to 'nameof'</target>
Expand Down
Loading

0 comments on commit 9f10b94

Please sign in to comment.