Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into inlineHintDuplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Dec 20, 2024
2 parents 1e21020 + a9cafab commit 37d3667
Show file tree
Hide file tree
Showing 170 changed files with 2,612 additions and 2,466 deletions.
4 changes: 2 additions & 2 deletions azure-pipelines-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ extends:
displayName: Build and Test

jobs:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/release/dev17.12') }}:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/release/dev17.13') }}:
- template: /eng/common/templates-official/job/onelocbuild.yml@self
parameters:
MirrorRepo: roslyn
MirrorBranch: release/dev17.12
MirrorBranch: release/dev17.13
LclSource: lclFilesfromPackage
LclPackageId: 'LCL-JUNO-PROD-ROSLYN'

Expand Down
9 changes: 9 additions & 0 deletions docs/features/incremental-generators.cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ public class FileTransformGenerator : IIncrementalGenerator
}
```

Items need to be included in your csproj files by using the `AdditionalFiles` ItemGroup:

```xml
<ItemGroup>
<AdditionalFiles Include="file1.xml" />
<AdditionalFiles Include="file2.xml" />
<ItemGroup>
```

### Augment user code

**User scenario:** As a generator author I want to be able to inspect and augment a user's code with new functionality.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.CodeAnalysis.CodeQuality;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.LanguageService;
Expand All @@ -27,10 +26,9 @@ internal abstract class AbstractRemoveUnusedMembersDiagnosticAnalyzer<
TIdentifierNameSyntax,
TTypeDeclarationSyntax,
TMemberDeclarationSyntax>()
: AbstractCodeQualityDiagnosticAnalyzer(
: AbstractBuiltInUnnecessaryCodeStyleDiagnosticAnalyzer(
[s_removeUnusedMembersRule, s_removeUnreadMembersRule],
// We want to analyze references in generated code, but not report unused members in generated code.
GeneratedCodeAnalysisFlags.Analyze)
FadingOptions.FadeOutUnusedMembers)
where TDocumentationCommentTriviaSyntax : SyntaxNode
where TIdentifierNameSyntax : SyntaxNode
where TTypeDeclarationSyntax : TMemberDeclarationSyntax
Expand All @@ -44,35 +42,43 @@ internal abstract class AbstractRemoveUnusedMembersDiagnosticAnalyzer<
memberOptions: SymbolDisplayMemberOptions.IncludeContainingType);

// IDE0051: "Remove unused members" (Symbol is declared but never referenced)
private static readonly DiagnosticDescriptor s_removeUnusedMembersRule = CreateDescriptor(
private static readonly DiagnosticDescriptor s_removeUnusedMembersRule = CreateDescriptorWithId(
IDEDiagnosticIds.RemoveUnusedMembersDiagnosticId,
EnforceOnBuildValues.RemoveUnusedMembers,
hasAnyCodeStyleOption: false,
new LocalizableResourceString(nameof(AnalyzersResources.Remove_unused_private_members), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
new LocalizableResourceString(nameof(AnalyzersResources.Private_member_0_is_unused), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
hasAnyCodeStyleOption: false, isUnnecessary: true);
isUnnecessary: true);

// IDE0052: "Remove unread members" (Value is written and/or symbol is referenced, but the assigned value is never read)
// Internal for testing
internal static readonly DiagnosticDescriptor s_removeUnreadMembersRule = CreateDescriptor(
internal static readonly DiagnosticDescriptor s_removeUnreadMembersRule = CreateDescriptorWithId(
IDEDiagnosticIds.RemoveUnreadMembersDiagnosticId,
EnforceOnBuildValues.RemoveUnreadMembers,
hasAnyCodeStyleOption: false,
new LocalizableResourceString(nameof(AnalyzersResources.Remove_unread_private_members), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
new LocalizableResourceString(nameof(AnalyzersResources.Private_member_0_can_be_removed_as_the_value_assigned_to_it_is_never_read), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
hasAnyCodeStyleOption: false, isUnnecessary: true);
isUnnecessary: true);

protected abstract ISemanticFacts SemanticFacts { get; }

protected abstract IEnumerable<TTypeDeclarationSyntax> GetTypeDeclarations(INamedTypeSymbol namedType, CancellationToken cancellationToken);
protected abstract SyntaxList<TMemberDeclarationSyntax> GetMembers(TTypeDeclarationSyntax typeDeclaration);
protected abstract SyntaxNode GetParentIfSoleDeclarator(SyntaxNode declaration);

// We need to analyze the whole document even for edits within a method body,
// because we might add or remove references to members in executable code.
// For example, if we had an unused field with no references, then editing any single method body
// to reference this field should clear the unused field diagnostic.
// Hence, we need to re-analyze the declarations in the whole file for any edits within the document.
/// <summary>
/// We need to analyze the whole document even for edits within a method body, because we might add or remove
/// references to members in executable code. For example, if we had an unused field with no references, then
/// editing any single method body to reference this field should clear the unused field diagnostic. Hence, we need
/// to re-analyze the declarations in the whole file for any edits within the document.
/// </summary>
public override DiagnosticAnalyzerCategory GetAnalyzerCategory() => DiagnosticAnalyzerCategory.SemanticDocumentAnalysis;

/// <summary>
/// We want to analyze references in generated code, but not report unused members in generated code.
/// </summary>
protected override GeneratedCodeAnalysisFlags GeneratedCodeAnalysisFlags => GeneratedCodeAnalysisFlags.Analyze;

protected sealed override void InitializeWorker(AnalysisContext context)
=> context.RegisterCompilationStartAction(compilationStartContext
=> CompilationAnalyzer.CreateAndRegisterActions(compilationStartContext, this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ parseOptions:=Nothing,
compilationOptions:=Nothing,
options:=Nothing,
"IDE0051",
DiagnosticSeverity.Info,
DiagnosticSeverity.Hidden,
diagnosticMessage:=String.Format(AnalyzersResources.Private_member_0_is_unused, "C.New"))
End Function
End Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,21 @@
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Implementation.EndConstructGeneration;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.CSharp.EndConstructGeneration;

[ExportLanguageService(typeof(IEndConstructGenerationService), LanguageNames.CSharp), Shared]
[ExcludeFromCodeCoverage]
internal class CSharpEndConstructGenerationService : IEndConstructGenerationService
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class CSharpEndConstructGenerationService() : IEndConstructGenerationService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpEndConstructGenerationService()
{
}

public bool TryDo(
ITextView textView,
ITextBuffer subjectBuffer,
char typedChar,
CancellationToken cancellationToken)
{
return false;
}
public Task<bool> TryDoAsync(ITextView textView, ITextBuffer subjectBuffer, char typedChar, CancellationToken cancellationToken)
=> SpecializedTasks.False;
}
Loading

0 comments on commit 37d3667

Please sign in to comment.