Skip to content

Commit ac65448

Browse files
remove synchronous calls from some parts of rename
1 parent d35882b commit ac65448

File tree

6 files changed

+42
-42
lines changed

6 files changed

+42
-42
lines changed

src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Extensions/SemanticModelExtensions.vb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
1111

1212
Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
1313
Partial Friend Module SemanticModelExtensions
14-
<Extension()>
14+
<Extension>
1515
Public Function LookupTypeRegardlessOfArity(semanticModel As SemanticModel,
1616
name As SyntaxToken,
1717
cancellationToken As CancellationToken) As IList(Of ITypeSymbol)
@@ -26,7 +26,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
2626
Return SpecializedCollections.EmptyList(Of ITypeSymbol)()
2727
End Function
2828

29-
<Extension()>
29+
<Extension>
3030
Public Function LookupName(semanticModel As SemanticModel, name As SyntaxToken,
3131
namespacesAndTypesOnly As Boolean,
3232
cancellationToken As CancellationToken) As IList(Of ISymbol)
@@ -38,7 +38,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
3838
Return SpecializedCollections.EmptyList(Of ISymbol)()
3939
End Function
4040

41-
<Extension()>
41+
<Extension>
4242
Public Function LookupName(semanticModel As SemanticModel,
4343
expression As ExpressionSyntax,
4444
namespacesAndTypesOnly As Boolean,
@@ -68,17 +68,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
6868
semanticModel.LookupSymbols(expr.SpanStart, container:=symbol, name:=name))
6969
End Function
7070

71-
<Extension()>
72-
Public Function GetSymbolInfo(semanticModel As SemanticModel, token As SyntaxToken) As SymbolInfo
73-
Dim expression = TryCast(token.Parent, ExpressionSyntax)
74-
If expression Is Nothing Then
75-
Return Nothing
76-
End If
77-
78-
Return semanticModel.GetSymbolInfo(expression)
79-
End Function
80-
81-
<Extension()>
71+
<Extension>
8272
Public Function GetImportNamespacesInScope(semanticModel As SemanticModel, location As SyntaxNode) As ISet(Of INamespaceSymbol)
8373
Dim q =
8474
From u In location.GetAncestorOrThis(Of CompilationUnitSyntax).Imports
@@ -92,7 +82,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
9282
Return q.ToSet()
9383
End Function
9484

95-
<Extension()>
85+
<Extension>
9686
Public Function GetAliasInfo(semanticModel As SemanticModel, expression As ExpressionSyntax, cancellationToken As CancellationToken) As IAliasSymbol
9787
Dim nameSyntax = TryCast(expression, IdentifierNameSyntax)
9888
If nameSyntax Is Nothing Then
@@ -102,7 +92,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
10292
End If
10393
End Function
10494

105-
<Extension()>
95+
<Extension>
10696
Public Function DetermineAccessibilityConstraint(semanticModel As SemanticModel,
10797
type As TypeSyntax,
10898
cancellationToken As CancellationToken) As Accessibility

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicTypeInferenceService.TypeInferrer.vb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
1010
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
1111

1212
Namespace Microsoft.CodeAnalysis.VisualBasic
13-
14-
Partial Friend Class VisualBasicTypeInferenceService
15-
Private Class TypeInferrer
13+
Partial Friend NotInheritable Class VisualBasicTypeInferenceService
14+
Private NotInheritable Class TypeInferrer
1615
Inherits AbstractTypeInferrer
1716

1817
Public Sub New(semanticModel As SemanticModel, cancellationToken As CancellationToken)
@@ -26,7 +25,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
2625

2726
Protected Overrides Function GetTypes_DoNotCallDirectly(node As SyntaxNode, objectAsDefault As Boolean) As IEnumerable(Of TypeInferenceInfo)
2827
If node IsNot Nothing Then
29-
Dim info = SemanticModel.GetTypeInfo(node)
28+
Dim info = SemanticModel.GetTypeInfo(node, CancellationToken)
3029
If info.Type IsNot Nothing AndAlso info.Type.TypeKind <> TypeKind.Error Then
3130
Return CreateResult(info.Type)
3231
End If
@@ -106,7 +105,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
106105
Return SpecializedCollections.EmptyEnumerable(Of TypeInferenceInfo)()
107106
End If
108107

109-
Dim typeSymbol = SemanticModel.GetTypeInfo(expressionType).Type
108+
Dim typeSymbol = SemanticModel.GetTypeInfo(expressionType, CancellationToken).Type
110109
If TypeOf typeSymbol IsNot INamedTypeSymbol Then
111110
Return SpecializedCollections.EmptyEnumerable(Of TypeInferenceInfo)()
112111
End If
@@ -247,7 +246,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
247246
Return SpecializedCollections.EmptyEnumerable(Of TypeInferenceInfo)()
248247
End If
249248

250-
Dim info = SemanticModel.GetSymbolInfo(invocation)
249+
Dim info = SemanticModel.GetSymbolInfo(invocation, CancellationToken)
251250
' Check all the methods that have at least enough arguments to support being
252251
' called with argument at this position. Note: if they're calling an extension
253252
' method then it will need one more argument in order for us to call it.
@@ -277,7 +276,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
277276
End If
278277

279278
If targetExpression IsNot Nothing Then
280-
Dim expressionType = SemanticModel.GetTypeInfo(targetExpression)
279+
Dim expressionType = SemanticModel.GetTypeInfo(targetExpression, CancellationToken)
281280
If TypeOf expressionType.Type Is IArrayTypeSymbol Then
282281
Return CreateResult(Compilation.GetSpecialType(SpecialType.System_Int32))
283282
End If
@@ -290,7 +289,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
290289
'
291290
' etc.
292291
Dim creation = TryCast(argumentList.Parent, ObjectCreationExpressionSyntax)
293-
Dim info = SemanticModel.GetSymbolInfo(creation.Type)
292+
Dim info = SemanticModel.GetSymbolInfo(creation.Type, CancellationToken)
294293
Dim namedType = TryCast(info.Symbol, INamedTypeSymbol)
295294
If namedType IsNot Nothing Then
296295
If namedType.TypeKind = TypeKind.Delegate Then
@@ -331,7 +330,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
331330
Return SpecializedCollections.EmptyEnumerable(Of TypeInferenceInfo)()
332331
End If
333332

334-
Dim info = SemanticModel.GetSymbolInfo(attribute)
333+
Dim info = SemanticModel.GetSymbolInfo(attribute, CancellationToken)
335334
Dim symbols = info.GetBestOrAllSymbols()
336335
If symbols.Any() Then
337336
Dim methods = symbols.OfType(Of IMethodSymbol)()
@@ -983,7 +982,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
983982
If node.IsKind(SyntaxKind.IdentifierName) Then
984983
Dim identifier = DirectCast(node, IdentifierNameSyntax)
985984
If CaseInsensitiveComparison.Equals(parameterName, identifier.Identifier.ValueText) AndAlso
986-
SemanticModel.GetSymbolInfo(identifier.Identifier).Symbol?.Kind = SymbolKind.Parameter Then
985+
SemanticModel.GetSymbolInfo(identifier.Identifier, CancellationToken).Symbol?.Kind = SymbolKind.Parameter Then
987986
Return InferTypes(identifier).FirstOrDefault().InferredType
988987
End If
989988
Else
@@ -1001,12 +1000,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
10011000
End Function
10021001

10031002
Private Function InferTypeInNamedFieldInitializer(initializer As NamedFieldInitializerSyntax) As IEnumerable(Of TypeInferenceInfo)
1004-
Dim right = SemanticModel.GetTypeInfo(initializer.Name).Type
1003+
Dim right = SemanticModel.GetTypeInfo(initializer.Name, CancellationToken).Type
10051004
If right IsNot Nothing AndAlso TypeOf right IsNot IErrorTypeSymbol Then
10061005
Return CreateResult(right)
10071006
End If
10081007

1009-
Return CreateResult(SemanticModel.GetTypeInfo(initializer.Expression).Type)
1008+
Return CreateResult(SemanticModel.GetTypeInfo(initializer.Expression, CancellationToken).Type)
10101009
End Function
10111010

10121011
Public Function InferTypeInCaseStatement(caseStatement As CaseStatementSyntax) As IEnumerable(Of TypeInferenceInfo)

src/Workspaces/VisualBasic/Portable/Classification/SyntaxClassification/IdentifierNameSyntaxClassifier.vb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Classification.Classifiers
1818

1919
Public Overrides ReadOnly Property SyntaxNodeTypes As ImmutableArray(Of Type) = ImmutableArray.Create(GetType(IdentifierNameSyntax))
2020

21-
Public Overrides Sub AddClassifications(syntax As SyntaxNode, textSpan As TextSpan, semanticModel As SemanticModel, options As ClassificationOptions, result As SegmentedList(Of ClassifiedSpan), cancellationToken As CancellationToken)
21+
Public Overrides Sub AddClassifications(
22+
syntax As SyntaxNode,
23+
textSpan As TextSpan,
24+
semanticModel As SemanticModel,
25+
options As ClassificationOptions,
26+
result As SegmentedList(Of ClassifiedSpan),
27+
cancellationToken As CancellationToken)
2228
Dim identifierName = DirectCast(syntax, IdentifierNameSyntax)
2329
Dim identifier = identifierName.Identifier
2430
If CaseInsensitiveComparison.Equals(identifier.ValueText, s_awaitText) Then
25-
Dim symbolInfo = semanticModel.GetSymbolInfo(identifier)
31+
Dim symbolInfo = semanticModel.GetSymbolInfo(identifier, cancellationToken)
2632
If symbolInfo.GetAnySymbol() Is Nothing Then
2733
result.Add(New ClassifiedSpan(ClassificationTypeNames.Keyword, identifier.Span))
2834
Return

src/Workspaces/VisualBasic/Portable/Rename/LocalConflictVisitor.vb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Rename
1111
Inherits VisualBasicSyntaxVisitor
1212

1313
Private ReadOnly _tracker As ConflictingIdentifierTracker
14-
Private ReadOnly _newSolution As Solution
14+
Private ReadOnly _semanticModel As SemanticModel
1515
Private ReadOnly _cancellationToken As CancellationToken
1616

17-
Public Sub New(tokenBeingRenamed As SyntaxToken, newSolution As Solution, cancellationToken As CancellationToken)
17+
Public Sub New(tokenBeingRenamed As SyntaxToken, semanticModel As SemanticModel, cancellationToken As CancellationToken)
1818
_tracker = New ConflictingIdentifierTracker(tokenBeingRenamed, CaseInsensitiveComparison.Comparer)
19-
_newSolution = newSolution
19+
_semanticModel = semanticModel
2020
_cancellationToken = cancellationToken
2121
End Sub
2222

@@ -147,8 +147,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Rename
147147
' it's only legal to have one name in the variable declarator for for and foreach loops.
148148
tokens.Add(DirectCast(controlVariable, VariableDeclaratorSyntax).Names.First().Identifier)
149149
Else
150-
Dim semanticModel = _newSolution.GetDocument(controlVariable.SyntaxTree).GetSemanticModelAsync(_cancellationToken).WaitAndGetResult_CanCallOnBackground(_cancellationToken)
151-
Dim symbol = semanticModel.GetSymbolInfo(controlVariable).Symbol
150+
Dim symbol = _semanticModel.GetSymbolInfo(controlVariable, _cancellationToken).Symbol
152151

153152
' if it is a field we don't care
154153
If symbol IsNot Nothing AndAlso symbol.IsKind(SymbolKind.Local) Then
@@ -189,11 +188,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Rename
189188
Public Overrides Sub VisitCatchBlock(node As CatchBlockSyntax)
190189
Dim tokens As New List(Of SyntaxToken)
191190

192-
Dim semanticModel = _newSolution.GetDocument(node.SyntaxTree).GetSemanticModelAsync(_cancellationToken).WaitAndGetResult_CanCallOnBackground(_cancellationToken)
193191
Dim identifierToken = node.CatchStatement.IdentifierName?.Identifier
194192

195193
If identifierToken.HasValue Then
196-
Dim symbol = semanticModel.GetSymbolInfo(identifierToken.Value).Symbol
194+
Dim symbol = _semanticModel.GetSymbolInfo(identifierToken.Value, _cancellationToken).Symbol
197195

198196
' if it is a field we don't care
199197
If symbol IsNot Nothing AndAlso symbol.IsKind(SymbolKind.Local) Then

src/Workspaces/VisualBasic/Portable/Rename/VisualBasicRenameRewriterLanguageService.vb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Rename
679679
Return False
680680
End Function
681681

682-
Public Overrides Function ComputeDeclarationConflictsAsync(
682+
Public Overrides Async Function ComputeDeclarationConflictsAsync(
683683
replacementText As String,
684684
renamedSymbol As ISymbol,
685685
renameSymbol As ISymbol,
@@ -703,7 +703,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Rename
703703
Dim methodBase = token.Parent.AncestorsAndSelf.Where(Function(s) TypeOf s Is MethodBlockBaseSyntax OrElse TypeOf s Is VariableDeclaratorSyntax) _
704704
.LastOrDefault()
705705

706-
Dim visitor As New LocalConflictVisitor(token, newSolution, cancellationToken)
706+
Dim semanticModel = Await newSolution.
707+
GetRequiredDocument(methodBase.SyntaxTree).
708+
GetSemanticModelAsync(cancellationToken).ConfigureAwait(False)
709+
Dim visitor As New LocalConflictVisitor(token, semanticModel, cancellationToken)
707710
visitor.Visit(methodBase)
708711

709712
conflicts.AddRange(visitor.ConflictingTokens.Select(Function(t) t.GetLocation()) _
@@ -719,7 +722,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Rename
719722

720723
token = matchingParameterSymbol.Locations.Single().FindToken(cancellationToken)
721724
methodBase = token.GetAncestor(Of MethodBlockSyntax)
722-
visitor = New LocalConflictVisitor(token, newSolution, cancellationToken)
725+
726+
semanticModel = Await newSolution.
727+
GetRequiredDocument(methodBase.SyntaxTree).
728+
GetSemanticModelAsync(cancellationToken).ConfigureAwait(False)
729+
visitor = New LocalConflictVisitor(token, semanticModel, cancellationToken)
723730
visitor.Visit(methodBase)
724731

725732
conflicts.AddRange(visitor.ConflictingTokens.Select(Function(t) t.GetLocation()) _
@@ -792,7 +799,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Rename
792799
Next
793800
End If
794801

795-
Return Task.FromResult(conflicts.ToImmutableAndFree())
802+
Return conflicts.ToImmutableAndFree()
796803
End Function
797804

798805
Public Overrides Async Function ComputeImplicitReferenceConflictsAsync(

src/Workspaces/VisualBasic/Portable/Simplification/VisualBasicSimplificationService.Expander.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification
562562
End If
563563
End If
564564

565-
Dim symbol = _semanticModel.GetSymbolInfo(originalSimpleName.Identifier).Symbol
565+
Dim symbol = _semanticModel.GetSymbolInfo(originalSimpleName.Identifier, _cancellationToken).Symbol
566566
If symbol Is Nothing Then
567567
Return newNode
568568
End If

0 commit comments

Comments
 (0)