From ae6e9cd93b23dbc610c7e985763bef5fdc513860 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 31 Jan 2025 20:15:11 -0800 Subject: [PATCH 1/6] Keep initializer when converting properties --- ...tyToFullPropertyCodeRefactoringProvider.cs | 6 ++-- .../ConvertAutoPropertyToFullPropertyTests.cs | 30 +++++++++++++++++++ ...tyToFullPropertyCodeRefactoringProvider.cs | 8 ++--- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs index c238e4b2dd533..6472d3dac8a02 100644 --- a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs @@ -168,8 +168,10 @@ protected override async Task ExpandToFieldPropertyAsync( // Update the getter/setter to reference the 'field' expression instead. var (newGetAccessor, newSetAccessor) = GetNewAccessors(info, property, FieldExpression(), cancellationToken); - var finalProperty = CreateFinalProperty(document, property, info, newGetAccessor, newSetAccessor); - var finalRoot = root.ReplaceNode(property, finalProperty); + // The normal helper will strip off the semicolon (as we're normally moving the initializer to a field). + // Don't do that here as we will keep the current initializer on the property if it is there. + var finalProperty = (PropertyDeclarationSyntax)CreateFinalProperty(document, property, info, newGetAccessor, newSetAccessor); + var finalRoot = root.ReplaceNode(property, finalProperty.WithSemicolonToken(property.SemicolonToken)); return document.WithSyntaxRoot(finalRoot); } diff --git a/src/Features/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs b/src/Features/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs index 111cea0267bfa..1884ab2379f76 100644 --- a/src/Features/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs +++ b/src/Features/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs @@ -1444,4 +1444,34 @@ public int Goo """; await TestInRegularAndScriptAsync(text, expected, options: DoNotPreferExpressionBodiedAccessors, index: 1, parseOptions: CSharp14); } + + [Theory] + [InlineData("set"), InlineData("init")] + [WorkItem("https://github.com/dotnet/roslyn/issues/76992")] + public async Task ProduceFieldBackedProperty2(string setter) + { + var text = $$""" + class TestClass + { + public int G[||]oo { get; {{setter}}; } = 0; + } + """; + var expected = $$""" + class TestClass + { + public int Goo + { + get + { + return field; + } + {{setter}} + { + field = value; + } + } = 0; + } + """; + await TestInRegularAndScriptAsync(text, expected, options: DoNotPreferExpressionBodiedAccessors, index: 1, parseOptions: CSharp14); + } } diff --git a/src/Features/Core/Portable/ConvertAutoPropertyToFullProperty/AbstractConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs b/src/Features/Core/Portable/ConvertAutoPropertyToFullProperty/AbstractConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs index 9fdb11ae24361..1275577e9282f 100644 --- a/src/Features/Core/Portable/ConvertAutoPropertyToFullProperty/AbstractConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ConvertAutoPropertyToFullProperty/AbstractConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs @@ -99,9 +99,9 @@ private async Task ExpandToFullPropertyAsync( var fieldName = await GetFieldNameAsync(document, propertySymbol, cancellationToken).ConfigureAwait(false); var (newGetAccessor, newSetAccessor) = GetNewAccessors(info, property, fieldName, cancellationToken); - editor.ReplaceNode( - property, - CreateFinalProperty(document, property, info, newGetAccessor, newSetAccessor)); + var finalProperty = CreateFinalProperty( + document, GetPropertyWithoutInitializer(property), info, newGetAccessor, newSetAccessor); + editor.ReplaceNode(property, finalProperty); // add backing field, plus initializer if it exists var newField = CodeGenerationSymbolFactory.CreateFieldSymbol( @@ -137,7 +137,7 @@ protected SyntaxNode CreateFinalProperty( var fullProperty = generator .WithAccessorDeclarations( - GetPropertyWithoutInitializer(property), + property, newSetAccessor == null ? [newGetAccessor] : [newGetAccessor, newSetAccessor]) From ea802900d3a7f091f23103d33b2e0b4b6c7ac341 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 31 Jan 2025 20:19:39 -0800 Subject: [PATCH 2/6] Simplify syntactic manipulatinos --- ...pertyToFullPropertyCodeRefactoringProvider.cs | 12 ++++-------- .../CodeGeneration/CSharpSyntaxGenerator.cs | 16 +++++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs index 6472d3dac8a02..5cb11e73a8cf6 100644 --- a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs @@ -129,9 +129,7 @@ protected override SyntaxNode ConvertPropertyToExpressionBodyIfDesired( var preference = info.Options.PreferExpressionBodiedProperties.Value; if (preference == ExpressionBodyPreference.Never) - { - return propertyDeclaration.WithSemicolonToken(default); - } + return propertyDeclaration; // if there is a get accessors only, we can move the expression body to the property if (propertyDeclaration.AccessorList?.Accessors.Count == 1 && @@ -146,7 +144,7 @@ protected override SyntaxNode ConvertPropertyToExpressionBodyIfDesired( } } - return propertyDeclaration.WithSemicolonToken(default); + return propertyDeclaration; } protected override SyntaxNode GetTypeBlock(SyntaxNode syntaxNode) @@ -168,10 +166,8 @@ protected override async Task ExpandToFieldPropertyAsync( // Update the getter/setter to reference the 'field' expression instead. var (newGetAccessor, newSetAccessor) = GetNewAccessors(info, property, FieldExpression(), cancellationToken); - // The normal helper will strip off the semicolon (as we're normally moving the initializer to a field). - // Don't do that here as we will keep the current initializer on the property if it is there. - var finalProperty = (PropertyDeclarationSyntax)CreateFinalProperty(document, property, info, newGetAccessor, newSetAccessor); - var finalRoot = root.ReplaceNode(property, finalProperty.WithSemicolonToken(property.SemicolonToken)); + var finalProperty = CreateFinalProperty(document, property, info, newGetAccessor, newSetAccessor); + var finalRoot = root.ReplaceNode(property, finalProperty); return document.WithSyntaxRoot(finalRoot); } diff --git a/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs b/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs index cf2aa2ed0d0e9..2c005f7ad2bd6 100644 --- a/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs +++ b/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs @@ -440,13 +440,15 @@ private static SyntaxNode AccessorDeclaration( public override SyntaxNode WithAccessorDeclarations(SyntaxNode declaration, IEnumerable accessorDeclarations) => declaration switch { - PropertyDeclarationSyntax property => property.WithAccessorList(CreateAccessorList(property.AccessorList, accessorDeclarations)) - .WithExpressionBody(null) - .WithSemicolonToken(default), - - IndexerDeclarationSyntax indexer => indexer.WithAccessorList(CreateAccessorList(indexer.AccessorList, accessorDeclarations)) - .WithExpressionBody(null) - .WithSemicolonToken(default), + PropertyDeclarationSyntax property => + property.WithAccessorList(CreateAccessorList(property.AccessorList, accessorDeclarations)) + .WithExpressionBody(null) + .WithSemicolonToken(property.Initializer is null ? default : property.SemicolonToken), + + IndexerDeclarationSyntax indexer => + indexer.WithAccessorList(CreateAccessorList(indexer.AccessorList, accessorDeclarations)) + .WithExpressionBody(null) + .WithSemicolonToken(default), _ => declaration, }; From 16edb403508228064318cd4ca2ae05facbdd463c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 4 Feb 2025 12:19:36 -0800 Subject: [PATCH 3/6] Remove OldResult value from ProjectAnalysisData --- ...gnosticIncrementalAnalyzer.AnalysisData.cs | 194 ++++++++---------- .../DiagnosticIncrementalAnalyzer.Executor.cs | 2 +- 2 files changed, 89 insertions(+), 107 deletions(-) diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs index 3be6f73e60c14..de338f5d4dbfb 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.AnalysisData.cs @@ -10,139 +10,121 @@ using Microsoft.CodeAnalysis.Workspaces.Diagnostics; using Roslyn.Utilities; -namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2 +namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2; + +internal partial class DiagnosticIncrementalAnalyzer { - internal partial class DiagnosticIncrementalAnalyzer + /// + /// Simple data holder for local diagnostics for an analyzer + /// + private readonly struct DocumentAnalysisData { + public static readonly DocumentAnalysisData Empty = new(VersionStamp.Default, lineCount: 0, []); + /// - /// Simple data holder for local diagnostics for an analyzer + /// Version of the diagnostic data. /// - private readonly struct DocumentAnalysisData - { - public static readonly DocumentAnalysisData Empty = new(VersionStamp.Default, lineCount: 0, []); + public readonly VersionStamp Version; - /// - /// Version of the diagnostic data. - /// - public readonly VersionStamp Version; - - /// - /// Number of lines in the document. - /// - public readonly int LineCount; + /// + /// Number of lines in the document. + /// + public readonly int LineCount; - /// - /// Current data that matches the version. - /// - public readonly ImmutableArray Items; + /// + /// Current data that matches the version. + /// + public readonly ImmutableArray Items; - /// - /// Last set of data we broadcasted to outer world, or . - /// - public readonly ImmutableArray OldItems; + /// + /// Last set of data we broadcasted to outer world, or . + /// + public readonly ImmutableArray OldItems; - public DocumentAnalysisData(VersionStamp version, int lineCount, ImmutableArray items) - { - Debug.Assert(!items.IsDefault); + public DocumentAnalysisData(VersionStamp version, int lineCount, ImmutableArray items) + { + Debug.Assert(!items.IsDefault); - Version = version; - LineCount = lineCount; - Items = items; - OldItems = default; - } + Version = version; + LineCount = lineCount; + Items = items; + OldItems = default; + } - public DocumentAnalysisData(VersionStamp version, int lineCount, ImmutableArray oldItems, ImmutableArray newItems) - : this(version, lineCount, newItems) - { - Debug.Assert(!oldItems.IsDefault); - OldItems = oldItems; - } + public DocumentAnalysisData(VersionStamp version, int lineCount, ImmutableArray oldItems, ImmutableArray newItems) + : this(version, lineCount, newItems) + { + Debug.Assert(!oldItems.IsDefault); + OldItems = oldItems; } + } + /// + /// Data holder for all diagnostics for a project for an analyzer + /// + private readonly struct ProjectAnalysisData + { /// - /// Data holder for all diagnostics for a project for an analyzer + /// ProjectId of this data /// - private readonly struct ProjectAnalysisData - { - /// - /// ProjectId of this data - /// - public readonly ProjectId ProjectId; - - /// - /// Version of the Items - /// - public readonly VersionStamp Version; - - /// - /// Current data that matches the version - /// - public readonly ImmutableDictionary Result; - - /// - /// When present, holds onto last data we broadcasted to outer world. - /// - public readonly ImmutableDictionary? OldResult; - - public ProjectAnalysisData(ProjectId projectId, VersionStamp version, ImmutableDictionary result) - { - ProjectId = projectId; - Version = version; - Result = result; + public readonly ProjectId ProjectId; - OldResult = null; - } + /// + /// Version of the Items + /// + public readonly VersionStamp Version; - public ProjectAnalysisData( - ProjectId projectId, - VersionStamp version, - ImmutableDictionary oldResult, - ImmutableDictionary newResult) - : this(projectId, version, newResult) - { - OldResult = oldResult; - } + /// + /// Current data that matches the version + /// + public readonly ImmutableDictionary Result; + + public ProjectAnalysisData(ProjectId projectId, VersionStamp version, ImmutableDictionary result) + { + ProjectId = projectId; + Version = version; + Result = result; + } + + public DiagnosticAnalysisResult GetResult(DiagnosticAnalyzer analyzer) + => GetResultOrEmpty(Result, analyzer, ProjectId, Version); - public DiagnosticAnalysisResult GetResult(DiagnosticAnalyzer analyzer) - => GetResultOrEmpty(Result, analyzer, ProjectId, Version); + public bool TryGetResult(DiagnosticAnalyzer analyzer, out DiagnosticAnalysisResult result) + => Result.TryGetValue(analyzer, out result); - public bool TryGetResult(DiagnosticAnalyzer analyzer, out DiagnosticAnalysisResult result) - => Result.TryGetValue(analyzer, out result); + public static async Task CreateAsync(Project project, IEnumerable stateSets, bool avoidLoadingData, CancellationToken cancellationToken) + { + VersionStamp? version = null; - public static async Task CreateAsync(Project project, IEnumerable stateSets, bool avoidLoadingData, CancellationToken cancellationToken) + var builder = ImmutableDictionary.CreateBuilder(); + foreach (var stateSet in stateSets) { - VersionStamp? version = null; + var state = stateSet.GetOrCreateProjectState(project.Id); + var result = await state.GetAnalysisDataAsync(project, avoidLoadingData, cancellationToken).ConfigureAwait(false); + Contract.ThrowIfFalse(project.Id == result.ProjectId); - var builder = ImmutableDictionary.CreateBuilder(); - foreach (var stateSet in stateSets) + if (!version.HasValue) { - var state = stateSet.GetOrCreateProjectState(project.Id); - var result = await state.GetAnalysisDataAsync(project, avoidLoadingData, cancellationToken).ConfigureAwait(false); - Contract.ThrowIfFalse(project.Id == result.ProjectId); - - if (!version.HasValue) - { - version = result.Version; - } - else if (version.Value != VersionStamp.Default && version.Value != result.Version) - { - // if not all version is same, set version as default. - // this can happen at the initial data loading or - // when document is closed and we put active file state to project state - version = VersionStamp.Default; - } - - builder.Add(stateSet.Analyzer, result); + version = result.Version; } - - if (!version.HasValue) + else if (version.Value != VersionStamp.Default && version.Value != result.Version) { - // there is no saved data to return. - return new ProjectAnalysisData(project.Id, VersionStamp.Default, ImmutableDictionary.Empty); + // if not all version is same, set version as default. + // this can happen at the initial data loading or + // when document is closed and we put active file state to project state + version = VersionStamp.Default; } - return new ProjectAnalysisData(project.Id, version.Value, builder.ToImmutable()); + builder.Add(stateSet.Analyzer, result); } + + if (!version.HasValue) + { + // there is no saved data to return. + return new ProjectAnalysisData(project.Id, VersionStamp.Default, ImmutableDictionary.Empty); + } + + return new ProjectAnalysisData(project.Id, version.Value, builder.ToImmutable()); } } } diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.Executor.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.Executor.cs index 82f948660ab2d..4977866b130ed 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.Executor.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.Executor.cs @@ -44,7 +44,7 @@ private async Task GetProjectAnalysisDataAsync( // Now we run analyzers but filter out some information. So on such projects, there will be some perf degradation. result = await RemoveCompilerSemanticErrorsIfProjectNotLoadedAsync(result, project, cancellationToken).ConfigureAwait(false); - return new ProjectAnalysisData(project.Id, version, existingData.Result, result); + return new ProjectAnalysisData(project.Id, version, result); } catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken)) { From ce2afa775c5d39f07c1f66622c68d622a112fc21 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 4 Feb 2025 12:31:52 -0800 Subject: [PATCH 4/6] Remove dead code from diagnostics subsystem --- ...gnosticIncrementalAnalyzer.ProjectState.cs | 7 --- ...gnosticIncrementalAnalyzer.StateManager.cs | 16 ----- .../DiagnosticIncrementalAnalyzer.StateSet.cs | 63 ------------------- .../Diagnostics/DiagnosticAnalysisResult.cs | 3 - 4 files changed, 89 deletions(-) diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs index d738aa7ec02de..91ed7122d58d4 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.ProjectState.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.SolutionCrawler; using Microsoft.CodeAnalysis.Workspaces.Diagnostics; using Roslyn.Utilities; @@ -241,12 +240,6 @@ public async ValueTask SaveToInMemoryStorageAsync(Project project, DiagnosticAna AddToInMemoryStorage(serializerVersion, project, document: null, result.ProjectId, NonLocalStateName, result.GetOtherDiagnostics()); } - public void ResetVersion() - { - // reset version of cached data so that we can recalculate new data (ex, OnDocumentReset) - _lastResult = _lastResult.Reset(); - } - public async ValueTask MergeAsync(ActiveFileState state, TextDocument document, IGlobalOptionService globalOptions) { Contract.ThrowIfFalse(state.DocumentId == document.Id); diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs index 78e1d431cdbe2..83e5cfeece232 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateManager.cs @@ -111,22 +111,6 @@ public async Task> GetOrCreateStateSetsAsync(Project pr return null; } - public bool OnProjectRemoved(IEnumerable stateSets, ProjectId projectId) - { - var removed = false; - foreach (var stateSet in stateSets) - { - removed |= stateSet.OnProjectRemoved(projectId); - } - - lock (_projectAnalyzerStateMap) - { - _projectAnalyzerStateMap = _projectAnalyzerStateMap.Remove(projectId); - } - - return removed; - } - private void RaiseProjectAnalyzerReferenceChanged(ProjectAnalyzerReferenceChangedEventArgs args) => ProjectAnalyzerReferenceChanged?.Invoke(this, args); diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs index 3a6afd3e5633a..0dc6627b39282 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs @@ -123,69 +123,6 @@ public async Task OnDocumentOpenedAsync(TextDocument document) return true; } - public async Task OnDocumentClosedAsync(TextDocument document, IGlobalOptionService globalOptions) - { - // can not be cancelled - // remove active file state and put it in project state - if (!_activeFileStates.TryRemove(document.Id, out var activeFileState)) - { - return false; - } - - // active file exist, put it in the project state - var projectState = GetOrCreateProjectState(document.Project.Id); - await projectState.MergeAsync(activeFileState, document, globalOptions).ConfigureAwait(false); - return true; - } - - public bool OnDocumentReset(TextDocument document) - { - var changed = false; - // can not be cancelled - // remove active file state and put it in project state - if (TryGetActiveFileState(document.Id, out var activeFileState)) - { - activeFileState.ResetVersion(); - changed |= true; - } - - if (TryGetProjectState(document.Project.Id, out var projectState)) - { - projectState.ResetVersion(); - changed |= true; - } - - return changed; - } - - public bool OnDocumentRemoved(DocumentId id) - { - // remove active file state for removed document - var removed = false; - if (_activeFileStates.TryRemove(id, out _)) - { - removed = true; - } - // remove state for the file that got removed. - if (_projectStates.TryGetValue(id.ProjectId, out var state)) - { - removed |= state.OnDocumentRemoved(id); - } - - return removed; - } - - public bool OnProjectRemoved(ProjectId id) - { - // remove state for project that got removed. - if (_projectStates.TryRemove(id, out var state)) - { - return state.OnProjectRemoved(id); - } - - return false; - } - public void OnRemoved() { // ths stateset is being removed. diff --git a/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs b/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs index 9cd424ee9c284..7bce9cb0b93ae 100644 --- a/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs +++ b/src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalysisResult.cs @@ -266,9 +266,6 @@ public DiagnosticAnalysisResult ToAggregatedForm() public DiagnosticAnalysisResult UpdateAggregatedResult(VersionStamp version, DocumentId documentId, bool fromBuild) => new(ProjectId, version, DocumentIdsOrEmpty.Add(documentId), isEmpty: false, fromBuild: fromBuild); - public DiagnosticAnalysisResult Reset() - => new(ProjectId, VersionStamp.Default, DocumentIds, IsEmpty, FromBuild); - public DiagnosticAnalysisResult DropExceptSyntax() { // quick bail out From 31af3854b0c9d3b6894d16c4715c83d9d0a5c895 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 4 Feb 2025 13:14:46 -0800 Subject: [PATCH 5/6] remove more dead code --- .../DiagnosticIncrementalAnalyzer.StateSet.cs | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs index 0dc6627b39282..4c6c0fc2cf745 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs @@ -38,51 +38,6 @@ public StateSet(string language, DiagnosticAnalyzer analyzer, bool isHostAnalyze _projectStates = new ConcurrentDictionary(concurrencyLevel: 2, capacity: 1); } - public IEnumerable GetProjectsWithDiagnostics() - { - // quick bail out - if (_activeFileStates.IsEmpty && _projectStates.IsEmpty) - return []; - - if (_activeFileStates.Count == 1 && _projectStates.IsEmpty) - { - // see whether we actually have diagnostics - var (documentId, state) = _activeFileStates.First(); - if (state.IsEmpty) - return []; - - // we do have diagnostics - return [documentId.ProjectId]; - } - - return new HashSet( - _activeFileStates.Where(kv => !kv.Value.IsEmpty) - .Select(kv => kv.Key.ProjectId) - .Concat(_projectStates.Where(kv => !kv.Value.IsEmpty()) - .Select(kv => kv.Key))); - } - - [PerformanceSensitive("https://github.com/dotnet/roslyn/issues/34761", AllowCaptures = false, AllowGenericEnumeration = false)] - public void CollectDocumentsWithDiagnostics(ProjectId projectId, HashSet set) - { - RoslynDebug.Assert(set != null); - - // Collect active documents with diagnostics - - foreach (var (documentId, state) in _activeFileStates) - { - if (documentId.ProjectId == projectId && !state.IsEmpty) - { - set.Add(documentId); - } - } - - if (_projectStates.TryGetValue(projectId, out var projectState) && !projectState.IsEmpty()) - { - set.UnionWith(projectState.GetDocumentsWithDiagnostics()); - } - } - public bool IsActiveFile(DocumentId documentId) => _activeFileStates.ContainsKey(documentId); From 51a72bab4e02b86a1ce007ad4982bc1353d5f737 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 4 Feb 2025 13:42:03 -0800 Subject: [PATCH 6/6] remove delete --- .../DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs index 2f48d82960e42..fea3ed2cee2df 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs @@ -68,8 +68,6 @@ private sealed class LatestDiagnosticsForSpanGetter private readonly bool _incrementalAnalysis; private readonly DiagnosticKind _diagnosticKind; - private delegate Task> DiagnosticsGetterAsync(DiagnosticAnalyzer analyzer, DocumentAnalysisExecutor executor, CancellationToken cancellationToken); - public static async Task CreateAsync( DiagnosticIncrementalAnalyzer owner, TextDocument document,