Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3abc79b0
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3abc79b0
编写于
5月 15, 2020
作者:
C
CyrusNajmabadi
提交者:
GitHub
5月 15, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #44296 from CyrusNajmabadi/renameNRT
NRT much of the rename core.
上级
dcc0f24f
d09a960e
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
157 addition
and
103 deletion
+157
-103
src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.cs
...ore.Wpf/InlineRename/AbstractEditorInlineRenameService.cs
+1
-1
src/EditorFeatures/Test2/Rename/RenameEngineResult.vb
src/EditorFeatures/Test2/Rename/RenameEngineResult.vb
+1
-1
src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs
...rp/Portable/Rename/CSharpRenameRewriterLanguageService.cs
+1
-1
src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.cs
...s/Core/Portable/Rename/ConflictEngine/ConflictResolver.cs
+37
-26
src/Workspaces/Core/Portable/Rename/ConflictResolution.cs
src/Workspaces/Core/Portable/Rename/ConflictResolution.cs
+3
-1
src/Workspaces/Core/Portable/Rename/IRemoteRenamer.cs
src/Workspaces/Core/Portable/Rename/IRemoteRenamer.cs
+48
-36
src/Workspaces/Core/Portable/Rename/IRenameRewriterLanguageService.cs
...es/Core/Portable/Rename/IRenameRewriterLanguageService.cs
+2
-0
src/Workspaces/Core/Portable/Rename/RenameLocation.ReferenceProcessing.cs
...ore/Portable/Rename/RenameLocation.ReferenceProcessing.cs
+28
-17
src/Workspaces/Core/Portable/Rename/RenameLocation.cs
src/Workspaces/Core/Portable/Rename/RenameLocation.cs
+3
-1
src/Workspaces/Core/Portable/Rename/RenameLocations.SearchResult.cs
...aces/Core/Portable/Rename/RenameLocations.SearchResult.cs
+4
-0
src/Workspaces/Core/Portable/Rename/RenameLocations.cs
src/Workspaces/Core/Portable/Rename/RenameLocations.cs
+5
-3
src/Workspaces/Core/Portable/Rename/Renamer.cs
src/Workspaces/Core/Portable/Rename/Renamer.cs
+10
-8
src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_Renamer.cs
...Remote/ServiceHub/Services/CodeAnalysisService_Renamer.cs
+14
-8
未找到文件。
src/EditorFeatures/Core.Wpf/InlineRename/AbstractEditorInlineRenameService.cs
浏览文件 @
3abc79b0
...
...
@@ -91,7 +91,7 @@ public async Task<IInlineRenameInfo> GetRenameInfoAsync(Document document, int p
}
}
var
symbol
=
await
RenameLocations
.
ReferenceProcessing
.
GetRenamableSymbolAsync
(
document
,
triggerToken
.
SpanStart
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
var
symbol
=
await
RenameLocations
.
ReferenceProcessing
.
Try
GetRenamableSymbolAsync
(
document
,
triggerToken
.
SpanStart
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
if
(
symbol
==
null
)
{
return
new
FailureInlineRenameInfo
(
EditorFeaturesResources
.
You_cannot_rename_this_element
);
...
...
src/EditorFeatures/Test2/Rename/RenameEngineResult.vb
浏览文件 @
3abc79b0
...
...
@@ -69,7 +69,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename
Dim
document
=
workspace
.
CurrentSolution
.
GetDocument
(
cursorDocument
.
Id
)
Dim
symbol
=
RenameLocations
.
ReferenceProcessing
.
GetRenamableSymbolAsync
(
document
,
cursorPosition
,
CancellationToken
.
None
).
Result
Dim
symbol
=
RenameLocations
.
ReferenceProcessing
.
Try
GetRenamableSymbolAsync
(
document
,
cursorPosition
,
CancellationToken
.
None
).
Result
If
symbol
Is
Nothing
Then
AssertEx
.
Fail
(
"The symbol touching the $$ could not be found."
)
End
If
...
...
src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs
浏览文件 @
3abc79b0
...
...
@@ -816,7 +816,7 @@ private SyntaxToken RenameWithinToken(SyntaxToken oldToken, SyntaxToken newToken
var
properties
=
new
List
<
ISymbol
>();
foreach
(
var
referencedSymbol
in
referencedSymbols
)
{
var
property
=
await
RenameLocations
.
ReferenceProcessing
.
GetPropertyFromAccessorOrAnOverrideAsync
(
var
property
=
await
RenameLocations
.
ReferenceProcessing
.
Try
GetPropertyFromAccessorOrAnOverrideAsync
(
referencedSymbol
,
baseSolution
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
property
!=
null
)
{
...
...
src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.cs
浏览文件 @
3abc79b0
...
...
@@ -2,6 +2,8 @@
// 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
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
...
...
@@ -39,7 +41,7 @@ internal static partial class ConflictResolver
internal
static
async
Task
<
ConflictResolution
>
ResolveConflictsAsync
(
RenameLocations
renameLocationSet
,
string
replacementText
,
ImmutableHashSet
<
ISymbol
>
nonConflictSymbols
,
ImmutableHashSet
<
ISymbol
>
?
nonConflictSymbols
,
CancellationToken
cancellationToken
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
...
...
@@ -50,11 +52,11 @@ internal static partial class ConflictResolver
var
client
=
await
RemoteHostClient
.
TryGetClientAsync
(
solution
.
Workspace
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
client
!=
null
)
{
var
result
=
await
client
.
TryRunRemoteAsync
<
SerializableConflictResolution
>(
var
result
=
await
client
.
TryRunRemoteAsync
<
SerializableConflictResolution
?
>(
WellKnownServiceHubServices
.
CodeAnalysisService
,
nameof
(
IRemoteRenamer
.
ResolveConflictsAsync
),
solution
,
new
object
[]
new
object
?
[]
{
renameLocationSet
.
Dehydrate
(
solution
,
cancellationToken
),
replacementText
,
...
...
@@ -63,10 +65,8 @@ internal static partial class ConflictResolver
callbackTarget
:
null
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
result
.
HasValue
)
{
if
(
result
.
HasValue
&&
result
.
Value
!=
null
)
return
await
result
.
Value
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
}
...
...
@@ -77,7 +77,7 @@ internal static partial class ConflictResolver
private
static
async
Task
<
ConflictResolution
>
ResolveConflictsInCurrentProcessAsync
(
RenameLocations
renameLocationSet
,
string
replacementText
,
ImmutableHashSet
<
ISymbol
>
nonConflictSymbols
,
ImmutableHashSet
<
ISymbol
>
?
nonConflictSymbols
,
CancellationToken
cancellationToken
)
{
var
resolution
=
await
ResolveMutableConflictsAsync
(
...
...
@@ -88,7 +88,7 @@ internal static partial class ConflictResolver
private
static
Task
<
MutableConflictResolution
>
ResolveMutableConflictsAsync
(
RenameLocations
renameLocationSet
,
string
replacementText
,
ImmutableHashSet
<
ISymbol
>
nonConflictSymbols
,
ImmutableHashSet
<
ISymbol
>
?
nonConflictSymbols
,
CancellationToken
cancellationToken
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
...
...
@@ -120,25 +120,25 @@ private static ImmutableArray<ISymbol> SymbolsForEnclosingInvocationExpressionWo
private
static
SyntaxNode
GetExpansionTargetForLocationPerLanguage
(
SyntaxToken
tokenOrNode
,
Document
document
)
{
var
renameRewriterService
=
document
.
GetLanguageService
<
IRenameRewriterLanguageService
>();
var
renameRewriterService
=
document
.
Get
Required
LanguageService
<
IRenameRewriterLanguageService
>();
var
complexifiedTarget
=
renameRewriterService
.
GetExpansionTargetForLocation
(
tokenOrNode
);
return
complexifiedTarget
;
}
private
static
bool
LocalVariableConflictPerLanguage
(
SyntaxToken
tokenOrNode
,
Document
document
,
ImmutableArray
<
ISymbol
>
newReferencedSymbols
)
{
var
renameRewriterService
=
document
.
GetLanguageService
<
IRenameRewriterLanguageService
>();
var
renameRewriterService
=
document
.
Get
Required
LanguageService
<
IRenameRewriterLanguageService
>();
var
isConflict
=
renameRewriterService
.
LocalVariableConflict
(
tokenOrNode
,
newReferencedSymbols
);
return
isConflict
;
}
private
static
bool
IsIdentifierValid_Worker
(
Solution
solution
,
string
replacementText
,
IEnumerable
<
ProjectId
>
projectIds
)
{
foreach
(
var
language
in
projectIds
.
Select
(
p
=>
solution
.
GetProject
(
p
).
Language
).
Distinct
())
foreach
(
var
language
in
projectIds
.
Select
(
p
=>
solution
.
Get
Required
Project
(
p
).
Language
).
Distinct
())
{
var
languageServices
=
solution
.
Workspace
.
Services
.
GetLanguageServices
(
language
);
var
renameRewriterLanguageService
=
languageServices
.
GetService
<
IRenameRewriterLanguageService
>();
var
syntaxFactsLanguageService
=
languageServices
.
GetService
<
ISyntaxFactsService
>();
var
renameRewriterLanguageService
=
languageServices
.
Get
Required
Service
<
IRenameRewriterLanguageService
>();
var
syntaxFactsLanguageService
=
languageServices
.
Get
Required
Service
<
ISyntaxFactsService
>();
if
(!
renameRewriterLanguageService
.
IsIdentifierValid
(
replacementText
,
syntaxFactsLanguageService
))
{
return
false
;
...
...
@@ -166,11 +166,15 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
CancellationToken
cancellationToken
)
{
{
var
renameRewriterService
=
conflictResolution
.
CurrentSolution
.
Workspace
.
Services
.
GetLanguageServices
(
renamedSymbol
.
Language
).
GetService
<
IRenameRewriterLanguageService
>();
var
renameRewriterService
=
conflictResolution
.
CurrentSolution
.
Workspace
.
Services
.
GetLanguageServices
(
renamedSymbol
.
Language
)
.
GetRequiredService
<
IRenameRewriterLanguageService
>();
var
implicitUsageConflicts
=
renameRewriterService
.
ComputePossibleImplicitUsageConflicts
(
renamedSymbol
,
semanticModel
,
originalDeclarationLocation
,
newDeclarationLocationStartingPosition
,
cancellationToken
);
foreach
(
var
implicitUsageConflict
in
implicitUsageConflicts
)
{
conflictResolution
.
AddOrReplaceRelatedLocation
(
new
RelatedLocation
(
implicitUsageConflict
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetDocument
(
implicitUsageConflict
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
Contract
.
ThrowIfNull
(
implicitUsageConflict
.
SourceTree
);
conflictResolution
.
AddOrReplaceRelatedLocation
(
new
RelatedLocation
(
implicitUsageConflict
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetRequiredDocument
(
implicitUsageConflict
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
}
}
...
...
@@ -183,7 +187,7 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
{
// the location of the implicit reference defines the language rules to check.
// E.g. foreach in C# using a MoveNext in VB that is renamed to MOVENEXT (within VB)
var
renameRewriterService
=
implicitReferenceLocationsPerLanguage
.
First
().
Document
.
Project
.
LanguageServices
.
GetService
<
IRenameRewriterLanguageService
>();
var
renameRewriterService
=
implicitReferenceLocationsPerLanguage
.
First
().
Document
.
Project
.
LanguageServices
.
Get
Required
Service
<
IRenameRewriterLanguageService
>();
var
implicitConflicts
=
await
renameRewriterService
.
ComputeImplicitReferenceConflictsAsync
(
originalSymbol
,
renamedSymbol
,
...
...
@@ -192,7 +196,9 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
foreach
(
var
implicitConflict
in
implicitConflicts
)
{
conflictResolution
.
AddRelatedLocation
(
new
RelatedLocation
(
implicitConflict
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetDocument
(
implicitConflict
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
Contract
.
ThrowIfNull
(
implicitConflict
.
SourceTree
);
conflictResolution
.
AddRelatedLocation
(
new
RelatedLocation
(
implicitConflict
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetRequiredDocument
(
implicitConflict
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
}
}
}
...
...
@@ -213,10 +219,10 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
{
try
{
var
project
=
conflictResolution
.
CurrentSolution
.
GetProject
(
renamedSymbol
.
ContainingAssembly
,
cancellationToken
);
var
projectOpt
=
conflictResolution
.
CurrentSolution
.
GetProject
(
renamedSymbol
.
ContainingAssembly
,
cancellationToken
);
if
(
renamedSymbol
.
ContainingSymbol
.
IsKind
(
SymbolKind
.
NamedType
))
{
Contract
.
ThrowIfNull
(
projectOpt
);
var
otherThingsNamedTheSame
=
renamedSymbol
.
ContainingType
.
GetMembers
(
renamedSymbol
.
Name
)
.
Where
(
s
=>
!
s
.
Equals
(
renamedSymbol
)
&&
string
.
Equals
(
s
.
MetadataName
,
renamedSymbol
.
MetadataName
,
StringComparison
.
Ordinal
));
...
...
@@ -224,7 +230,7 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
IEnumerable
<
ISymbol
>
otherThingsNamedTheSameExcludeMethodAndParameterizedProperty
;
// Possibly overloaded symbols are excluded here and handled elsewhere
var
semanticFactsService
=
project
.
LanguageServices
.
Get
Service
<
ISemanticFactsService
>();
var
semanticFactsService
=
project
Opt
.
LanguageServices
.
GetRequired
Service
<
ISemanticFactsService
>();
if
(
semanticFactsService
.
SupportsParameterizedProperties
)
{
otherThingsNamedTheSameExcludeMethodAndParameterizedProperty
=
otherThingsNamedTheSame
...
...
@@ -240,7 +246,6 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
AddConflictingSymbolLocations
(
otherThingsNamedTheSameExcludeMethodAndParameterizedProperty
,
conflictResolution
,
reverseMappedLocations
);
}
if
(
renamedSymbol
.
IsKind
(
SymbolKind
.
Namespace
)
&&
renamedSymbol
.
ContainingSymbol
.
IsKind
(
SymbolKind
.
Namespace
))
{
var
otherThingsNamedTheSame
=
((
INamespaceSymbol
)
renamedSymbol
.
ContainingSymbol
).
GetMembers
(
renamedSymbol
.
Name
)
...
...
@@ -269,8 +274,9 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
// Some types of symbols (namespaces, cref stuff, etc) might not have ContainingAssemblies
if
(
renamedSymbol
.
ContainingAssembly
!=
null
)
{
Contract
.
ThrowIfNull
(
projectOpt
);
// There also might be language specific rules we need to include
var
languageRenameService
=
project
.
LanguageServices
.
Get
Service
<
IRenameRewriterLanguageService
>();
var
languageRenameService
=
project
Opt
.
LanguageServices
.
GetRequired
Service
<
IRenameRewriterLanguageService
>();
var
languageConflicts
=
await
languageRenameService
.
ComputeDeclarationConflictsAsync
(
conflictResolution
.
ReplacementText
,
renamedSymbol
,
...
...
@@ -283,7 +289,9 @@ private static bool IsRenameValid(MutableConflictResolution conflictResolution,
foreach
(
var
languageConflict
in
languageConflicts
)
{
conflictResolution
.
AddOrReplaceRelatedLocation
(
new
RelatedLocation
(
languageConflict
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetDocument
(
languageConflict
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
Contract
.
ThrowIfNull
(
languageConflict
.
SourceTree
);
conflictResolution
.
AddOrReplaceRelatedLocation
(
new
RelatedLocation
(
languageConflict
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetRequiredDocument
(
languageConflict
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
}
}
}
...
...
@@ -308,7 +316,9 @@ private static void AddConflictingSymbolLocations(IEnumerable<ISymbol> conflicti
{
if
(
reverseMappedLocations
.
TryGetValue
(
newLocation
,
out
var
oldLocation
))
{
conflictResolution
.
AddOrReplaceRelatedLocation
(
new
RelatedLocation
(
oldLocation
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetDocument
(
oldLocation
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
Contract
.
ThrowIfNull
(
oldLocation
.
SourceTree
);
conflictResolution
.
AddOrReplaceRelatedLocation
(
new
RelatedLocation
(
oldLocation
.
SourceSpan
,
conflictResolution
.
OldSolution
.
GetRequiredDocument
(
oldLocation
.
SourceTree
).
Id
,
RelatedLocationType
.
UnresolvableConflict
));
}
}
}
...
...
@@ -382,7 +392,8 @@ private static async Task<Location> GetSymbolLocationAsync(Solution solution, IS
locations
=
originalsourcesymbol
.
Locations
;
}
var
orderedLocations
=
locations
.
OrderBy
(
l
=>
l
.
IsInSource
?
solution
.
GetDocumentId
(
l
.
SourceTree
).
Id
:
Guid
.
Empty
)
var
orderedLocations
=
locations
.
OrderBy
(
l
=>
l
.
IsInSource
?
solution
.
GetDocumentId
(
l
.
SourceTree
)!.
Id
:
Guid
.
Empty
)
.
ThenBy
(
l
=>
l
.
IsInSource
?
l
.
SourceSpan
.
Start
:
int
.
MaxValue
);
return
orderedLocations
.
FirstOrDefault
();
...
...
@@ -405,7 +416,7 @@ private static async Task<Location> GetSymbolLocationAsync(Solution solution, IS
// Every loop updates the newMetadataName to resemble the oldMetadataName
while
(
index
!=
-
1
&&
index
<
oldMetadataName
.
Length
)
{
// This check is to se
s
if the part of string before the string match, matches
// This check is to se
e
if the part of string before the string match, matches
if
(!
IsSubStringEqual
(
oldMetadataName
,
newMetadataName
,
index
))
{
return
false
;
...
...
src/Workspaces/Core/Portable/Rename/ConflictResolution.cs
浏览文件 @
3abc79b0
...
...
@@ -2,6 +2,8 @@
// 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.Rename.ConflictEngine
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
...
...
@@ -12,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Rename
{
internal
readonly
partial
struct
ConflictResolution
{
public
readonly
string
ErrorMessage
;
public
readonly
string
?
ErrorMessage
;
private
readonly
Solution
_newSolutionWithoutRenamedDocument
;
private
readonly
(
DocumentId
documentId
,
string
newName
)
_renamedDocument
;
...
...
src/Workspaces/Core/Portable/Rename/IRemoteRenamer.cs
浏览文件 @
3abc79b0
...
...
@@ -2,7 +2,10 @@
// 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
System.Diagnostics.CodeAnalysis
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
...
...
@@ -10,6 +13,7 @@
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Remote
;
using
Microsoft.CodeAnalysis.Rename.ConflictEngine
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
...
...
@@ -22,7 +26,7 @@ internal interface IRemoteRenamer
/// forth marshaling) when the intermediary results of rename are not needed. To get the individual parts of
/// rename remoted use <see cref="FindRenameLocationsAsync"/> and <see cref="ResolveConflictsAsync"/>.
/// </summary>
Task
<
SerializableConflictResolution
>
RenameSymbolAsync
(
Task
<
SerializableConflictResolution
?
>
RenameSymbolAsync
(
PinnedSolutionInfo
solutionInfo
,
SerializableSymbolAndProjectId
symbolAndProjectId
,
string
replacementText
,
...
...
@@ -30,13 +34,13 @@ internal interface IRemoteRenamer
SerializableSymbolAndProjectId
[]
nonConflictSymbolIds
,
CancellationToken
cancellationToken
);
Task
<
SerializableRenameLocations
>
FindRenameLocationsAsync
(
Task
<
SerializableRenameLocations
?
>
FindRenameLocationsAsync
(
PinnedSolutionInfo
solutionInfo
,
SerializableSymbolAndProjectId
symbolAndProjectId
,
SerializableRenameOptionSet
options
,
CancellationToken
cancellationToken
);
Task
<
SerializableConflictResolution
>
ResolveConflictsAsync
(
Task
<
SerializableConflictResolution
?
>
ResolveConflictsAsync
(
PinnedSolutionInfo
solutionInfo
,
SerializableRenameLocations
renameLocationSet
,
string
replacementText
,
...
...
@@ -68,36 +72,35 @@ internal class SerializableSearchResult
{
// We use arrays so we can represent default immutable arrays.
public
SerializableRenameLocation
[]
Locations
;
public
SerializableReferenceLocation
[]
ImplicitLocations
;
public
SerializableSymbolAndProjectId
[]
ReferencedSymbols
;
public
SerializableRenameLocation
[]
?
Locations
;
public
SerializableReferenceLocation
[]
?
ImplicitLocations
;
public
SerializableSymbolAndProjectId
[]
?
ReferencedSymbols
;
public
static
SerializableSearchResult
Dehydrate
(
Solution
solution
,
RenameLocations
.
SearchResult
result
,
CancellationToken
cancellationToken
)
[
return
:
NotNullIfNotNull
(
"result"
)]
public
static
SerializableSearchResult
?
Dehydrate
(
Solution
solution
,
RenameLocations
.
SearchResult
?
result
,
CancellationToken
cancellationToken
)
=>
result
==
null
?
null
:
new
SerializableSearchResult
{
Locations
=
result
.
Locations
?
.
Select
(
loc
=>
SerializableRenameLocation
.
Dehydrate
(
loc
)).
ToArray
(),
Locations
=
result
.
Locations
.
Select
(
loc
=>
SerializableRenameLocation
.
Dehydrate
(
loc
)).
ToArray
(),
ImplicitLocations
=
result
.
ImplicitLocations
.
IsDefault
?
null
:
result
.
ImplicitLocations
.
Select
(
loc
=>
SerializableReferenceLocation
.
Dehydrate
(
loc
,
cancellationToken
)).
ToArray
(),
ReferencedSymbols
=
result
.
ReferencedSymbols
.
IsDefault
?
null
:
result
.
ReferencedSymbols
.
Select
(
s
=>
SerializableSymbolAndProjectId
.
Dehydrate
(
solution
,
s
,
cancellationToken
)).
ToArray
(),
};
public
async
Task
<
RenameLocations
.
SearchResult
>
RehydrateAsync
(
Solution
solution
,
CancellationToken
cancellationToken
)
{
ImmutableHashSet
<
RenameLocation
>
locations
=
null
;
ImmutableArray
<
ReferenceLocation
>
implicitLocations
=
default
;
ImmutableArray
<
ISymbol
>
referencedSymbols
=
default
;
if
(
Locations
!=
null
)
{
using
var
_
=
ArrayBuilder
<
RenameLocation
>.
GetInstance
(
Locations
.
Length
,
out
var
builder
);
foreach
(
var
loc
in
Locations
)
builder
.
Add
(
await
loc
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
));
Contract
.
ThrowIfNull
(
Locations
);
locations
=
builder
.
ToImmutableHashSet
();
}
using
var
_1
=
ArrayBuilder
<
RenameLocation
>.
GetInstance
(
Locations
.
Length
,
out
var
locBuilder
);
foreach
(
var
loc
in
Locations
)
locBuilder
.
Add
(
await
loc
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
));
var
locations
=
locBuilder
.
ToImmutableHashSet
();
if
(
ImplicitLocations
!=
null
)
{
using
var
_
=
ArrayBuilder
<
ReferenceLocation
>.
GetInstance
(
ImplicitLocations
.
Length
,
out
var
builder
);
using
var
_
2
=
ArrayBuilder
<
ReferenceLocation
>.
GetInstance
(
ImplicitLocations
.
Length
,
out
var
builder
);
foreach
(
var
loc
in
ImplicitLocations
)
builder
.
Add
(
await
loc
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
));
...
...
@@ -106,7 +109,7 @@ public async Task<RenameLocations.SearchResult> RehydrateAsync(Solution solution
if
(
ReferencedSymbols
!=
null
)
{
using
var
_
=
ArrayBuilder
<
ISymbol
>.
GetInstance
(
ReferencedSymbols
.
Length
,
out
var
builder
);
using
var
_
3
=
ArrayBuilder
<
ISymbol
>.
GetInstance
(
ReferencedSymbols
.
Length
,
out
var
builder
);
foreach
(
var
symbol
in
ReferencedSymbols
)
builder
.
AddIfNotNull
(
await
symbol
.
TryRehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
));
...
...
@@ -141,8 +144,8 @@ public static SerializableRenameLocation Dehydrate(RenameLocation location)
public
async
Task
<
RenameLocation
>
RehydrateAsync
(
Solution
solution
,
CancellationToken
cancellation
)
{
var
document
=
solution
.
GetDocument
(
DocumentId
);
var
tree
=
await
document
.
GetSyntaxTreeAsync
(
cancellation
).
ConfigureAwait
(
false
);
var
document
=
solution
.
Get
Required
Document
(
DocumentId
);
var
tree
=
await
document
.
Get
Required
SyntaxTreeAsync
(
cancellation
).
ConfigureAwait
(
false
);
return
new
RenameLocation
(
CodeAnalysis
.
Location
.
Create
(
tree
,
Location
),
...
...
@@ -169,11 +172,14 @@ public SerializableRenameLocations Dehydrate(Solution solution, CancellationToke
CommentsResult
=
_commentsResult
.
IsDefault
?
null
:
_commentsResult
.
Select
(
r
=>
SerializableRenameLocation
.
Dehydrate
(
r
)).
ToArray
(),
};
internal
static
async
Task
<
RenameLocations
>
RehydrateAsync
(
Solution
solution
,
SerializableRenameLocations
locations
,
CancellationToken
cancellationToken
)
internal
static
async
Task
<
RenameLocations
?>
Try
RehydrateAsync
(
Solution
solution
,
SerializableRenameLocations
locations
,
CancellationToken
cancellationToken
)
{
if
(
locations
==
null
)
return
null
;
if
(
locations
.
Symbol
==
null
)
return
null
;
var
symbol
=
await
locations
.
Symbol
.
TryRehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
symbol
==
null
)
return
null
;
...
...
@@ -209,11 +215,17 @@ internal static async Task<RenameLocations> RehydrateAsync(Solution solution, Se
commentsResult
=
builder
.
ToImmutable
();
}
var
originalSymbolResult
=
locations
.
OriginalSymbolResult
==
null
?
null
:
await
locations
.
OriginalSymbolResult
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
Contract
.
ThrowIfNull
(
locations
.
MergedResult
);
return
new
RenameLocations
(
symbol
,
solution
,
locations
.
Options
.
Rehydrate
(),
await
locations
.
OriginalSymbolResult
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
)
,
originalSymbolResult
,
await
locations
.
MergedResult
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
),
overloadsResult
,
stringsResult
,
...
...
@@ -223,15 +235,15 @@ internal static async Task<RenameLocations> RehydrateAsync(Solution solution, Se
internal
class
SerializableRenameLocations
{
public
SerializableSymbolAndProjectId
Symbol
;
public
SerializableSymbolAndProjectId
?
Symbol
;
public
SerializableRenameOptionSet
Options
;
public
SerializableSearchResult
OriginalSymbolResult
;
public
SerializableSearchResult
MergedResult
;
public
SerializableSearchResult
?
OriginalSymbolResult
;
public
SerializableSearchResult
?
MergedResult
;
// We use arrays so we can represent default immutable arrays.
public
SerializableSearchResult
[]
OverloadsResult
;
public
SerializableRenameLocation
[]
StringsResult
;
public
SerializableRenameLocation
[]
CommentsResult
;
public
SerializableSearchResult
[]
?
OverloadsResult
;
public
SerializableRenameLocation
[]
?
StringsResult
;
public
SerializableRenameLocation
[]
?
CommentsResult
;
}
internal
class
SerializableComplexifiedSpan
...
...
@@ -257,7 +269,7 @@ internal class SerializableRelatedLocation
public
TextSpan
ConflictCheckSpan
;
public
RelatedLocationType
Type
;
public
bool
IsReference
;
public
DocumentId
DocumentId
;
public
DocumentId
?
DocumentId
;
public
TextSpan
ComplexifiedTargetSpan
;
public
RelatedLocation
Rehydrate
()
...
...
@@ -276,7 +288,7 @@ public static SerializableRelatedLocation Dehydrate(RelatedLocation location)
internal
class
SerializableConflictResolution
{
public
string
ErrorMessage
;
public
string
?
ErrorMessage
;
public
bool
ReplacementTextValid
;
...
...
@@ -286,12 +298,12 @@ internal class SerializableConflictResolution
//
// We also flatten dictionaries into key/value tuples because jsonrpc only supports dictionaries with string keys.
public
DocumentId
[]
DocumentIds
;
public
SerializableRelatedLocation
[]
RelatedLocations
;
public
(
DocumentId
,
TextChange
[])[]
DocumentTextChanges
;
public
(
DocumentId
,
ImmutableArray
<(
TextSpan
oldSpan
,
TextSpan
newSpan
)>)[]
DocumentToModifiedSpansMap
;
public
(
DocumentId
,
ImmutableArray
<
SerializableComplexifiedSpan
>)[]
DocumentToComplexifiedSpansMap
;
public
(
DocumentId
,
ImmutableArray
<
SerializableRelatedLocation
>)[]
DocumentToRelatedLocationsMap
;
public
DocumentId
[]
?
DocumentIds
;
public
SerializableRelatedLocation
[]
?
RelatedLocations
;
public
(
DocumentId
,
TextChange
[])[]
?
DocumentTextChanges
;
public
(
DocumentId
,
ImmutableArray
<(
TextSpan
oldSpan
,
TextSpan
newSpan
)>)[]
?
DocumentToModifiedSpansMap
;
public
(
DocumentId
,
ImmutableArray
<
SerializableComplexifiedSpan
>)[]
?
DocumentToComplexifiedSpansMap
;
public
(
DocumentId
,
ImmutableArray
<
SerializableRelatedLocation
>)[]
?
DocumentToRelatedLocationsMap
;
public
async
Task
<
ConflictResolution
>
RehydrateAsync
(
Solution
oldSolution
,
CancellationToken
cancellationToken
)
{
...
...
src/Workspaces/Core/Portable/Rename/IRenameRewriterLanguageService.cs
浏览文件 @
3abc79b0
...
...
@@ -2,6 +2,8 @@
// 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
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
...
...
src/Workspaces/Core/Portable/Rename/RenameLocation.ReferenceProcessing.cs
浏览文件 @
3abc79b0
...
...
@@ -2,6 +2,8 @@
// 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
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
...
...
@@ -31,14 +33,12 @@ internal static class ReferenceProcessing
/// Given a symbol in a document, returns the "right" symbol that should be renamed in
/// the case the name binds to things like aliases _and_ the underlying type at once.
/// </summary>
public
static
async
Task
<
ISymbol
>
GetRenamableSymbolAsync
(
public
static
async
Task
<
ISymbol
?>
Try
GetRenamableSymbolAsync
(
Document
document
,
int
position
,
CancellationToken
cancellationToken
)
{
var
symbol
=
await
SymbolFinder
.
FindSymbolAtPositionAsync
(
document
,
position
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
if
(
symbol
==
null
)
{
return
null
;
}
var
definitionSymbol
=
await
FindDefinitionSymbolAsync
(
symbol
,
document
.
Project
.
Solution
,
cancellationToken
).
ConfigureAwait
(
false
);
Contract
.
ThrowIfNull
(
definitionSymbol
);
...
...
@@ -115,7 +115,7 @@ internal static class ReferenceProcessing
}
// in case this is e.g. an overridden property accessor, we'll treat the property itself as the definition symbol
var
property
=
await
GetPropertyFromAccessorOrAnOverrideAsync
(
bestSymbol
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
var
property
=
await
Try
GetPropertyFromAccessorOrAnOverrideAsync
(
bestSymbol
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
return
property
??
bestSymbol
;
}
...
...
@@ -214,7 +214,7 @@ static bool IsConstructorForType(ISymbol possibleConstructor, ISymbol possibleTy
}
}
internal
static
async
Task
<
ISymbol
>
GetPropertyFromAccessorOrAnOverrideAsync
(
internal
static
async
Task
<
ISymbol
?>
Try
GetPropertyFromAccessorOrAnOverrideAsync
(
ISymbol
symbol
,
Solution
solution
,
CancellationToken
cancellationToken
)
{
if
(
symbol
.
IsPropertyAccessor
())
...
...
@@ -229,7 +229,7 @@ static bool IsConstructorForType(ISymbol possibleConstructor, ISymbol possibleTy
if
(
originalSourceSymbol
!=
null
)
{
return
await
GetPropertyFromAccessorOrAnOverrideAsync
(
originalSourceSymbol
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
return
await
Try
GetPropertyFromAccessorOrAnOverrideAsync
(
originalSourceSymbol
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
...
...
@@ -241,7 +241,7 @@ static bool IsConstructorForType(ISymbol possibleConstructor, ISymbol possibleTy
foreach
(
var
methodImplementor
in
methodImplementors
)
{
var
propertyAccessorOrAnOverride
=
await
GetPropertyFromAccessorOrAnOverrideAsync
(
methodImplementor
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
var
propertyAccessorOrAnOverride
=
await
Try
GetPropertyFromAccessorOrAnOverrideAsync
(
methodImplementor
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
propertyAccessorOrAnOverride
!=
null
)
{
return
propertyAccessorOrAnOverride
;
...
...
@@ -255,7 +255,7 @@ static bool IsConstructorForType(ISymbol possibleConstructor, ISymbol possibleTy
private
static
async
Task
<
bool
>
IsPropertyAccessorOrAnOverrideAsync
(
ISymbol
symbol
,
Solution
solution
,
CancellationToken
cancellationToken
)
{
var
result
=
await
GetPropertyFromAccessorOrAnOverrideAsync
(
var
result
=
await
Try
GetPropertyFromAccessorOrAnOverrideAsync
(
symbol
,
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
return
result
!=
null
;
}
...
...
@@ -300,7 +300,8 @@ private static string TrimNameToAfterLastDot(string name)
if
(
originalSymbol
.
Kind
==
SymbolKind
.
Alias
)
{
var
location
=
originalSymbol
.
Locations
.
Single
();
results
.
Add
(
new
RenameLocation
(
location
,
solution
.
GetDocument
(
location
.
SourceTree
).
Id
));
Contract
.
ThrowIfNull
(
location
.
SourceTree
);
results
.
Add
(
new
RenameLocation
(
location
,
solution
.
GetRequiredDocument
(
location
.
SourceTree
).
Id
));
return
results
.
ToImmutableAndFree
();
}
...
...
@@ -309,9 +310,10 @@ private static string TrimNameToAfterLastDot(string name)
{
if
(
location
.
IsInSource
)
{
Contract
.
ThrowIfNull
(
location
.
SourceTree
);
results
.
Add
(
new
RenameLocation
(
location
,
solution
.
GetDocument
(
location
.
SourceTree
).
Id
,
solution
.
Get
Required
Document
(
location
.
SourceTree
).
Id
,
isRenamableAccessor
:
isRenamableAccessor
));
}
}
...
...
@@ -320,7 +322,10 @@ private static string TrimNameToAfterLastDot(string name)
// destructors declarations that match the name
if
(
referencedSymbol
.
Kind
==
SymbolKind
.
NamedType
&&
referencedSymbol
.
Locations
.
All
(
l
=>
l
.
IsInSource
))
{
var
syntaxFacts
=
solution
.
GetDocument
(
referencedSymbol
.
Locations
[
0
].
SourceTree
).
GetLanguageService
<
ISyntaxFactsService
>();
var
firstLocation
=
referencedSymbol
.
Locations
[
0
];
Contract
.
ThrowIfNull
(
firstLocation
.
SourceTree
);
var
syntaxFacts
=
solution
.
GetRequiredDocument
(
firstLocation
.
SourceTree
)
.
GetRequiredLanguageService
<
ISyntaxFactsService
>();
var
namedType
=
(
INamedTypeSymbol
)
referencedSymbol
;
foreach
(
var
method
in
namedType
.
GetMembers
().
OfType
<
IMethodSymbol
>())
...
...
@@ -337,7 +342,8 @@ private static string TrimNameToAfterLastDot(string name)
if
(!
syntaxFacts
.
IsReservedOrContextualKeyword
(
token
)
&&
token
.
ValueText
==
referencedSymbol
.
Name
)
{
results
.
Add
(
new
RenameLocation
(
location
,
solution
.
GetDocument
(
location
.
SourceTree
).
Id
));
Contract
.
ThrowIfNull
(
location
.
SourceTree
);
results
.
Add
(
new
RenameLocation
(
location
,
solution
.
GetRequiredDocument
(
location
.
SourceTree
).
Id
));
}
}
}
...
...
@@ -376,7 +382,8 @@ internal static async Task<IEnumerable<RenameLocation>> GetRenamableReferenceLoc
// We also need to add the location of the alias
// itself
var
aliasLocation
=
location
.
Alias
.
Locations
.
Single
();
results
.
Add
(
new
RenameLocation
(
aliasLocation
,
solution
.
GetDocument
(
aliasLocation
.
SourceTree
).
Id
));
Contract
.
ThrowIfNull
(
aliasLocation
.
SourceTree
);
results
.
Add
(
new
RenameLocation
(
aliasLocation
,
solution
.
GetRequiredDocument
(
aliasLocation
.
SourceTree
).
Id
));
}
}
else
...
...
@@ -394,7 +401,8 @@ internal static async Task<IEnumerable<RenameLocation>> GetRenamableReferenceLoc
// We also need to add the location of the alias itself
var
aliasLocation
=
location
.
Alias
.
Locations
.
Single
();
results
.
Add
(
new
RenameLocation
(
aliasLocation
,
solution
.
GetDocument
(
aliasLocation
.
SourceTree
).
Id
));
Contract
.
ThrowIfNull
(
aliasLocation
.
SourceTree
);
results
.
Add
(
new
RenameLocation
(
aliasLocation
,
solution
.
GetRequiredDocument
(
aliasLocation
.
SourceTree
).
Id
));
}
}
else
...
...
@@ -459,7 +467,7 @@ internal static async Task<IEnumerable<RenameLocation>> GetRenamableReferenceLoc
Document
document
,
string
renameText
,
ISyntaxFactsService
syntaxFactsService
,
ArrayBuilder
<
RenameLocation
>
renameLocations
,
CancellationToken
cancellationToken
)
{
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
await
document
.
Get
Required
SyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
renameTextLength
=
renameText
.
Length
;
var
renameStringsAndPositions
=
root
...
...
@@ -477,7 +485,7 @@ internal static async Task<IEnumerable<RenameLocation>> GetRenamableReferenceLoc
private
static
async
Task
AddLocationsToRenameInCommentsAsync
(
Document
document
,
string
renameText
,
ArrayBuilder
<
RenameLocation
>
renameLocations
,
CancellationToken
cancellationToken
)
{
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
await
document
.
Get
Required
SyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
renameTextLength
=
renameText
.
Length
;
var
renameStringsAndPositions
=
root
...
...
@@ -508,8 +516,11 @@ internal static async Task<IEnumerable<RenameLocation>> GetRenamableReferenceLoc
var
matches
=
regex
.
Matches
(
renameString
);
foreach
(
Match
match
in
matches
)
foreach
(
Match
?
match
in
matches
)
{
if
(
match
==
null
)
continue
;
var
start
=
renameStringPosition
+
match
.
Index
;
Debug
.
Assert
(
renameText
.
Length
==
match
.
Length
);
var
matchTextSpan
=
new
TextSpan
(
start
,
renameText
.
Length
);
...
...
src/Workspaces/Core/Portable/Rename/RenameLocation.cs
浏览文件 @
3abc79b0
...
...
@@ -2,6 +2,8 @@
// 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
;
using
Microsoft.CodeAnalysis.FindSymbols
;
using
Microsoft.CodeAnalysis.Text
;
...
...
@@ -48,7 +50,7 @@ public RenameLocation(ReferenceLocation referenceLocation, DocumentId documentId
public
bool
Equals
(
RenameLocation
other
)
=>
Location
==
other
.
Location
;
public
override
bool
Equals
(
object
obj
)
public
override
bool
Equals
(
object
?
obj
)
{
return
obj
is
RenameLocation
loc
&&
Equals
(
loc
);
...
...
src/Workspaces/Core/Portable/Rename/RenameLocations.SearchResult.cs
浏览文件 @
3abc79b0
...
...
@@ -2,8 +2,11 @@
// 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.FindSymbols
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Rename
{
...
...
@@ -20,6 +23,7 @@ public class SearchResult
ImmutableArray
<
ReferenceLocation
>
implicitLocations
,
ImmutableArray
<
ISymbol
>
referencedSymbols
)
{
Contract
.
ThrowIfNull
(
locations
);
this
.
Locations
=
locations
;
this
.
ImplicitLocations
=
implicitLocations
;
this
.
ReferencedSymbols
=
referencedSymbols
;
...
...
src/Workspaces/Core/Portable/Rename/RenameLocations.cs
浏览文件 @
3abc79b0
...
...
@@ -136,7 +136,7 @@ internal sealed partial class RenameLocations
var
client
=
await
RemoteHostClient
.
TryGetClientAsync
(
solution
.
Workspace
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
client
!=
null
)
{
var
result
=
await
client
.
TryRunRemoteAsync
<
SerializableRenameLocations
>(
var
result
=
await
client
.
TryRunRemoteAsync
<
SerializableRenameLocations
?
>(
WellKnownServiceHubServices
.
CodeAnalysisService
,
nameof
(
IRemoteRenamer
.
FindRenameLocationsAsync
),
solution
,
...
...
@@ -148,10 +148,12 @@ internal sealed partial class RenameLocations
callbackTarget
:
null
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
result
.
HasValue
)
if
(
result
.
HasValue
&&
result
.
Value
!=
null
)
{
return
await
RenameLocations
.
RehydrateAsync
(
var
rehydrated
=
await
RenameLocations
.
Try
RehydrateAsync
(
solution
,
result
.
Value
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
rehydrated
!=
null
)
return
rehydrated
;
}
}
}
...
...
src/Workspaces/Core/Portable/Rename/Renamer.cs
浏览文件 @
3abc79b0
...
...
@@ -2,6 +2,8 @@
// 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
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
...
...
@@ -35,7 +37,7 @@ public static partial class Renamer
RenameOptionSet
.
From
(
solution
,
optionSet
),
nonConflictSymbols
:
null
,
cancellationToken
).
ConfigureAwait
(
false
);
// This is a public entrypoint. So if rename failed to resolve conflicts, we report that back to caller as
// This is a public entry
-
point. So if rename failed to resolve conflicts, we report that back to caller as
// an exception.
if
(
resolution
.
ErrorMessage
!=
null
)
throw
new
ArgumentException
(
resolution
.
ErrorMessage
);
...
...
@@ -66,8 +68,8 @@ public static partial class Renamer
public
static
async
Task
<
RenameDocumentActionSet
>
RenameDocumentAsync
(
Document
document
,
string
newDocumentName
,
IReadOnlyList
<
string
>
newDocumentFolders
=
null
,
OptionSet
optionSet
=
null
,
IReadOnlyList
<
string
>
?
newDocumentFolders
=
null
,
OptionSet
?
optionSet
=
null
,
CancellationToken
cancellationToken
=
default
)
{
if
(
document
is
null
)
...
...
@@ -109,7 +111,7 @@ internal static Task<RenameLocations> FindRenameLocationsAsync(Solution solution
ISymbol
symbol
,
string
newName
,
RenameOptionSet
optionSet
,
ImmutableHashSet
<
ISymbol
>
nonConflictSymbols
,
ImmutableHashSet
<
ISymbol
>
?
nonConflictSymbols
,
CancellationToken
cancellationToken
)
{
Contract
.
ThrowIfNull
(
solution
);
...
...
@@ -126,11 +128,11 @@ internal static Task<RenameLocations> FindRenameLocationsAsync(Solution solution
var
client
=
await
RemoteHostClient
.
TryGetClientAsync
(
solution
.
Workspace
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
client
!=
null
)
{
var
result
=
await
client
.
TryRunRemoteAsync
<
SerializableConflictResolution
>(
var
result
=
await
client
.
TryRunRemoteAsync
<
SerializableConflictResolution
?
>(
WellKnownServiceHubServices
.
CodeAnalysisService
,
nameof
(
IRemoteRenamer
.
RenameSymbolAsync
),
solution
,
new
object
[]
new
object
?
[]
{
SerializableSymbolAndProjectId
.
Create
(
symbol
,
project
,
cancellationToken
),
newName
,
...
...
@@ -140,7 +142,7 @@ internal static Task<RenameLocations> FindRenameLocationsAsync(Solution solution
callbackTarget
:
null
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
result
.
HasValue
)
if
(
result
.
HasValue
&&
result
.
Value
!=
null
)
return
await
result
.
Value
.
RehydrateAsync
(
solution
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
...
...
@@ -156,7 +158,7 @@ internal static Task<RenameLocations> FindRenameLocationsAsync(Solution solution
ISymbol
symbol
,
string
newName
,
RenameOptionSet
optionSet
,
ImmutableHashSet
<
ISymbol
>
nonConflictSymbols
,
ImmutableHashSet
<
ISymbol
>
?
nonConflictSymbols
,
CancellationToken
cancellationToken
)
{
Contract
.
ThrowIfNull
(
solution
);
...
...
src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_Renamer.cs
浏览文件 @
3abc79b0
...
...
@@ -2,6 +2,8 @@
// 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
System.Threading
;
using
System.Threading.Tasks
;
...
...
@@ -13,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Remote
// root level service for all Roslyn services
internal
partial
class
CodeAnalysisService
:
IRemoteRenamer
{
public
Task
<
SerializableConflictResolution
>
RenameSymbolAsync
(
public
Task
<
SerializableConflictResolution
?
>
RenameSymbolAsync
(
PinnedSolutionInfo
solutionInfo
,
SerializableSymbolAndProjectId
symbolAndProjectId
,
string
newName
,
...
...
@@ -21,7 +23,7 @@ internal partial class CodeAnalysisService : IRemoteRenamer
SerializableSymbolAndProjectId
[]
nonConflictSymbolIds
,
CancellationToken
cancellationToken
)
{
return
RunServiceAsync
<
SerializableConflictResolution
>(
async
()
=>
return
RunServiceAsync
<
SerializableConflictResolution
?
>(
async
()
=>
{
using
(
UserOperationBooster
.
Boost
())
{
...
...
@@ -43,13 +45,13 @@ internal partial class CodeAnalysisService : IRemoteRenamer
},
cancellationToken
);
}
public
Task
<
SerializableRenameLocations
>
FindRenameLocationsAsync
(
public
Task
<
SerializableRenameLocations
?
>
FindRenameLocationsAsync
(
PinnedSolutionInfo
solutionInfo
,
SerializableSymbolAndProjectId
symbolAndProjectId
,
SerializableRenameOptionSet
options
,
CancellationToken
cancellationToken
)
{
return
RunServiceAsync
<
SerializableRenameLocations
>(
async
()
=>
return
RunServiceAsync
<
SerializableRenameLocations
?
>(
async
()
=>
{
using
(
UserOperationBooster
.
Boost
())
{
...
...
@@ -68,22 +70,26 @@ internal partial class CodeAnalysisService : IRemoteRenamer
},
cancellationToken
);
}
public
Task
<
SerializableConflictResolution
>
ResolveConflictsAsync
(
public
Task
<
SerializableConflictResolution
?
>
ResolveConflictsAsync
(
PinnedSolutionInfo
solutionInfo
,
SerializableRenameLocations
renameLocationSet
,
string
replacementText
,
SerializableSymbolAndProjectId
[]
nonConflictSymbolIds
,
CancellationToken
cancellationToken
)
{
return
RunServiceAsync
<
SerializableConflictResolution
>(
async
()
=>
return
RunServiceAsync
<
SerializableConflictResolution
?
>(
async
()
=>
{
using
(
UserOperationBooster
.
Boost
())
{
var
solution
=
await
GetSolutionAsync
(
solutionInfo
,
cancellationToken
).
ConfigureAwait
(
false
);
var
nonConflictSymbols
=
await
GetNonConflictSymbolsAsync
(
solution
,
nonConflictSymbolIds
,
cancellationToken
).
ConfigureAwait
(
false
);
var
rehydratedSet
=
await
RenameLocations
.
TryRehydrateAsync
(
solution
,
renameLocationSet
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
rehydratedSet
==
null
)
return
null
;
var
result
=
await
ConflictResolver
.
ResolveConflictsAsync
(
await
RenameLocations
.
RehydrateAsync
(
solution
,
renameLocationSet
,
cancellationToken
).
ConfigureAwait
(
false
)
,
rehydratedSet
,
replacementText
,
nonConflictSymbols
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -92,7 +98,7 @@ internal partial class CodeAnalysisService : IRemoteRenamer
},
cancellationToken
);
}
private
async
Task
<
ImmutableHashSet
<
ISymbol
>>
GetNonConflictSymbolsAsync
(
Solution
solution
,
SerializableSymbolAndProjectId
[]
nonConflictSymbolIds
,
CancellationToken
cancellationToken
)
private
async
Task
<
ImmutableHashSet
<
ISymbol
>
?
>
GetNonConflictSymbolsAsync
(
Solution
solution
,
SerializableSymbolAndProjectId
[]
nonConflictSymbolIds
,
CancellationToken
cancellationToken
)
{
if
(
nonConflictSymbolIds
==
null
)
return
null
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录