Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
7333c9a6
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,发现更多精彩内容 >>
提交
7333c9a6
编写于
11月 25, 2019
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle linked files in MoveToNamespace refactoring
上级
b33ec5a2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
1 deletion
+66
-1
src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs
...atures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs
+59
-0
src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs
...ortable/MoveToNamespace/AbstractMoveToNamespaceService.cs
+7
-1
未找到文件。
src/EditorFeatures/CSharpTest/MoveToNamespace/MoveToNamespaceTests.cs
浏览文件 @
7333c9a6
...
...
@@ -7,6 +7,7 @@
using
Microsoft.CodeAnalysis.Editor.UnitTests
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.MoveToNamespace
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Microsoft.CodeAnalysis.Test.Utilities.MoveToNamespace
;
using
Microsoft.VisualStudio.Composition
;
...
...
@@ -1226,5 +1227,63 @@ partial class MyClass
{
}"
,
expectedSuccess
:
false
);
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MoveToNamespace
)]
[
WorkItem
(
39234
,
"https://github.com/dotnet/roslyn/issues/39234"
)]
public
async
Task
TestMultiTargetingProject
()
{
// Create two projects with same project file path and single linked document to simulate a multi-targeting project.
var
input
=
@"<Workspace>
<Project Language=""C#"" CommonReferences=""true"" AssemblyName=""Proj1"" FilePath=""SharedProj.csproj"">
<Document FilePath=""CurrentDocument.cs"">
namespace A
{
public class Class1
{
}
public class Class2[||]
{
}
}
</Document>
</Project>
<Project Language=""C#"" CommonReferences=""true"" AssemblyName=""Proj2"" FilePath=""SharedProj.csproj"">
<Document IsLinkFile=""true"" LinkAssemblyName=""Proj1"" LinkFilePath=""CurrentDocument.cs""/>
</Project>
</Workspace>"
;
var
expected
=
@"namespace A
{
public class Class1
{
}
}
namespace B
{
public class Class2
{
}
}"
;
using
var
workspace
=
TestWorkspace
.
Create
(
System
.
Xml
.
Linq
.
XElement
.
Parse
(
input
),
exportProvider
:
ExportProviderFactory
.
CreateExportProvider
());
// Set the target namespace to "B"
var
testDocument
=
workspace
.
Projects
.
Single
(
p
=>
p
.
Name
==
"Proj1"
).
Documents
.
Single
();
var
document
=
workspace
.
CurrentSolution
.
GetDocument
(
testDocument
.
Id
);
var
movenamespaceService
=
document
.
GetLanguageService
<
IMoveToNamespaceService
>();
var
moveToNamespaceOptions
=
new
MoveToNamespaceOptionsResult
(
"B"
);
((
TestMoveToNamespaceOptionsService
)
movenamespaceService
.
OptionsService
).
SetOptions
(
moveToNamespaceOptions
);
var
(
_
,
action
)
=
await
GetCodeActionsAsync
(
workspace
,
default
);
var
operations
=
await
VerifyActionAndGetOperationsAsync
(
workspace
,
action
,
default
);
var
result
=
ApplyOperationsAndGetSolution
(
workspace
,
operations
);
var
changedDocument
=
result
.
Item2
.
GetDocument
(
testDocument
.
Id
);
var
changedRoot
=
await
changedDocument
.
GetSyntaxRootAsync
();
var
actualText
=
changedRoot
.
ToFullString
();
Assert
.
Equal
(
expected
,
actualText
);
}
}
}
src/Features/Core/Portable/MoveToNamespace/AbstractMoveToNamespaceService.cs
浏览文件 @
7333c9a6
...
...
@@ -253,7 +253,13 @@ private static async Task<ImmutableArray<ISymbol>> GetMemberSymbolsAsync(Documen
MoveTypeOperationKind
.
MoveTypeNamespaceScope
,
cancellationToken
).
ConfigureAwait
(
false
);
var
modifiedDocument
=
modifiedSolution
.
GetDocument
(
document
.
Id
);
// Since MoveTypeService doesn't handle linked files, we need to merge the diff ourselves,
// otherwise, we will end up with multiple linked documents with different content.
var
diffMergingSession
=
new
LinkedFileDiffMergingSession
(
document
.
Project
.
Solution
,
modifiedSolution
,
modifiedSolution
.
GetChanges
(
document
.
Project
.
Solution
),
logSessionInfo
:
false
);
var
mergeResult
=
await
diffMergingSession
.
MergeDiffsAsync
(
mergeConflictHandler
:
null
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
var
mergedSolution
=
mergeResult
.
MergedSolution
;
var
modifiedDocument
=
mergedSolution
.
GetDocument
(
document
.
Id
);
var
syntaxRoot
=
await
modifiedDocument
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
syntaxNode
=
syntaxRoot
.
GetAnnotatedNodes
(
AbstractMoveTypeService
.
NamespaceScopeMovedAnnotation
).
SingleOrDefault
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录