Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1295,5 +1295,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return node
End If
End Function

Friend Function GetAccessorList(declaration As SyntaxNode) As SyntaxList(Of AccessorBlockSyntax)
Select Case declaration.Kind
Case SyntaxKind.PropertyBlock
Return DirectCast(declaration, PropertyBlockSyntax).Accessors
Case SyntaxKind.EventBlock
Return DirectCast(declaration, EventBlockSyntax).Accessors
Case Else
Return Nothing
End Select
End Function
End Module
End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<Compile Include="$(MSBuildThisFileDirectory)LanguageServices\CSharpReplaceDiscardDeclarationsWithAssignmentsService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LanguageServices\InitializeParameter\InitializeParameterHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\NullableSyntaxAnnotationEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SemanticModelReuse\CSharpSemanticModelReuseLanguageService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\NameSyntaxIterator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\CSharpSimplificationHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\NullableHelpers\NullableExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;

#if WORKSPACE
using Microsoft.CodeAnalysis.Internal.Log;
#endif

namespace Microsoft.CodeAnalysis.SemanticModelReuse;

internal abstract class AbstractSemanticModelReuseLanguageService<
Expand All @@ -20,7 +23,9 @@ internal abstract class AbstractSemanticModelReuseLanguageService<
where TBasePropertyDeclarationSyntax : TMemberDeclarationSyntax
where TAccessorDeclarationSyntax : SyntaxNode
{
#if WORKSPACE
private readonly CountLogAggregator<bool> _logAggregator = new();
#endif

protected abstract ISyntaxFacts SyntaxFacts { get; }

Expand All @@ -32,11 +37,13 @@ internal abstract class AbstractSemanticModelReuseLanguageService<

public void Dispose()
{
#if WORKSPACE
Logger.Log(FunctionId.SemanticModelReuseLanguageService_TryGetSpeculativeSemanticModelAsync_Equivalent, KeyValueLogMessage.Create(static (m, _logAggregator) =>
{
foreach (var kv in _logAggregator)
m[kv.Key.ToString()] = kv.Value.GetCount();
}, _logAggregator));
#endif
}

public async Task<SemanticModel?> TryGetSpeculativeSemanticModelAsync(SemanticModel previousSemanticModel, SyntaxNode currentBodyNode, CancellationToken cancellationToken)
Expand All @@ -48,7 +55,10 @@ public void Dispose()
// then something very bad happened as we did that document.Project.GetDependentSemanticVersionAsync was
// still the same. Log information so we can be alerted if this isn't being as successful as we expect.
var isEquivalentTo = previousSyntaxTree.IsEquivalentTo(currentSyntaxTree, topLevel: true);

#if WORKSPACE
_logAggregator.IncreaseCount(isEquivalentTo);
#endif

if (!isEquivalentTo)
return null;
Expand All @@ -71,13 +81,13 @@ public void Dispose()
// Given that the common use case for us is continuously editing/typing inside a method body, we believe we can be conservative
// in creating speculative model with those kind of trivia change, by requiring the method body block not to shift position,
// w/o sacrificing performance in those common scenarios.
if (previousBodyNode.SpanStart != currentBodyNode.SpanStart)
if (previousBodyNode?.SpanStart != currentBodyNode.SpanStart)
return null;

return TryGetSpeculativeSemanticModelWorker(previousSemanticModel, previousBodyNode, currentBodyNode);
}

protected SyntaxNode GetPreviousBodyNode(SyntaxNode previousRoot, SyntaxNode currentRoot, SyntaxNode currentBodyNode)
protected SyntaxNode? GetPreviousBodyNode(SyntaxNode previousRoot, SyntaxNode currentRoot, SyntaxNode currentBodyNode)
{
if (currentBodyNode is TAccessorDeclarationSyntax currentAccessor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ private sealed class SemanticModelReuseWorkspaceService : ISemanticModelReuseWor
public SemanticModelReuseWorkspaceService(Workspace workspace)
{
_workspace = workspace;

#pragma warning disable RS0030 // Do not use banned APIs
#if WORKSPACE
_workspace.RegisterWorkspaceChangedHandler((e) =>
#else
_workspace.WorkspaceChanged += (sender, e) =>
#endif
{
// if our map points at documents not in the current solution, then we want to clear things out.
// this way we don't hold onto semantic models past, say, the c#/vb solutions closing.
Expand All @@ -78,7 +84,13 @@ public SemanticModelReuseWorkspaceService(Workspace workspace)
return;
}
}
});
}
#if WORKSPACE
);
#else
;
#endif
#pragma warning restore RS0030 // Do not use banned APIs
}

public async ValueTask<SemanticModel> ReuseExistingSpeculativeModelAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,14 @@
<Compile Include="$(MSBuildThisFileDirectory)Utilities\SemanticDocument.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\SyntacticDocument.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\TextReaderWithLength.cs" />
<Compile Include="$(MSBuildThisFileDirectory)WorkspaceServices\SemanticModelReuse\ISemanticModelReuseWorkspaceService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)WorkspaceServices\SemanticModelReuse\SemanticModelReuseWorkspaceServiceFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SemanticModelReuse\AbstractSemanticModelReuseLanguageService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SemanticModelReuse\ISemanticModelReuseLanguageService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SemanticModelReuse\ISemanticModelReuseWorkspaceService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SemanticModelReuse\SemanticModelReuseWorkspaceServiceFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CodeFixes\SyntaxEditorBasedCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LanguageServices\SyntaxFactsService\ISyntaxFactsService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\NameGenerator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SemanticModelReuse\SemanticModelWorkspaceServiceFactory.SemanticModelWorkspaceService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Workspace\Host\SupportedChangesServiceExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Workspace\Mef\CodeChangeProviderMetadata.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Workspace\Mef\FileExtensionsMetadata.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SemanticModelReuse
Protected Overrides Function GetAccessors(member As DeclarationStatementSyntax) As SyntaxList(Of AccessorBlockSyntax)
Contract.ThrowIfFalse(TypeOf member Is PropertyBlockSyntax OrElse
TypeOf member Is EventBlockSyntax)
Return VisualBasicSyntaxGenerator.GetAccessorList(member)
Return GetAccessorList(member)
End Function

Public Overrides Function TryGetContainingMethodBodyForSpeculation(node As SyntaxNode) As SyntaxNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Compile Include="$(MSBuildThisFileDirectory)LanguageServices\VisualBasicSyntaxKindsServiceFactory.vb" />
<Compile Include="$(MSBuildThisFileDirectory)LanguageServices\VisualBasicTypeInferenceService.TypeInferrer.vb" />
<Compile Include="$(MSBuildThisFileDirectory)LanguageServices\VisualBasicTypeInferenceService.vb" />
<Compile Include="$(MSBuildThisFileDirectory)SemanticModelReuse\VisualBasicSemanticModelReuseLanguageService.vb" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\VisualBasicSimplificationHelpers.vb" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\ModifierCollectionFacts.vb" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\NameSyntaxIterator.vb" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
End Function

Public Overrides Function InsertAccessors(declaration As SyntaxNode, index As Integer, accessors As IEnumerable(Of SyntaxNode)) As SyntaxNode

Dim currentList = GetAccessorList(declaration)
Dim newList = AsAccessorList(accessors, declaration.Kind)

Expand All @@ -3041,17 +3040,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
End If
End Function

Friend Shared Function GetAccessorList(declaration As SyntaxNode) As SyntaxList(Of AccessorBlockSyntax)
Select Case declaration.Kind
Case SyntaxKind.PropertyBlock
Return DirectCast(declaration, PropertyBlockSyntax).Accessors
Case SyntaxKind.EventBlock
Return DirectCast(declaration, EventBlockSyntax).Accessors
Case Else
Return Nothing
End Select
End Function

Private Shared Function WithAccessorList(declaration As SyntaxNode, accessorList As SyntaxList(Of AccessorBlockSyntax)) As SyntaxNode
Select Case declaration.Kind
Case SyntaxKind.PropertyBlock
Expand Down
Loading