Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3689c94d
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,发现更多精彩内容 >>
提交
3689c94d
编写于
6月 29, 2018
作者:
J
Julien Couvreur
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Transfer leading trivia in ChangeSignature
上级
99b59878
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
136 addition
and
4 deletion
+136
-4
src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Delegates.cs
...s/CSharpTest/ChangeSignature/ChangeSignature_Delegates.cs
+1
-1
src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Formatting.cs
.../CSharpTest/ChangeSignature/ChangeSignature_Formatting.cs
+88
-0
src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.cs
...ures/CSharpTest/ChangeSignature/ReorderParametersTests.cs
+1
-1
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
.../Portable/ChangeSignature/CSharpChangeSignatureService.cs
+46
-2
未找到文件。
src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Delegates.cs
浏览文件 @
3689c94d
...
...
@@ -535,7 +535,7 @@ void M()
/// <summary>
/// This is <see cref=""MyDelegate""/>, which has these methods:
/// <see cref=""MyDelegate.MyDelegate(object, IntPtr)""/>
/// <see cref=""MyDelegate.Invoke(
bool, string)""/>
/// <see cref=""MyDelegate.Invoke(bool, string)""/>
/// <see cref=""MyDelegate.EndInvoke(IAsyncResult)""/>
/// <see cref=""MyDelegate.BeginInvoke(int, string, bool, AsyncCallback, object)""/>
/// </summary>
...
...
src/EditorFeatures/CSharpTest/ChangeSignature/ChangeSignature_Formatting.cs
浏览文件 @
3689c94d
...
...
@@ -41,6 +41,72 @@ class C
await
TestChangeSignatureViaCommandAsync
(
LanguageNames
.
CSharp
,
markup
,
updatedSignature
:
updatedSignature
,
expectedUpdatedInvocationDocumentCode
:
expectedUpdatedCode
);
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
ChangeSignature
)]
[
WorkItem
(
28156
,
"https://github.com/dotnet/roslyn/issues/28156"
)]
public
async
Task
ChangeSignature_Formatting_KeepTrivia
()
{
var
markup
=
@"
class C
{
void $$Method(
int a, int b, int c,
int d, int e,
int f)
{
Method(
1, 2, 3,
4, 5, 6);
}
}"
;
var
updatedSignature
=
new
[]
{
1
,
2
,
3
,
4
,
5
};
var
expectedUpdatedCode
=
@"
class C
{
void Method(
int b, int c, int d,
int e, int f)
{
Method(
2, 3, 4,
5, 6);
}
}"
;
await
TestChangeSignatureViaCommandAsync
(
LanguageNames
.
CSharp
,
markup
,
updatedSignature
:
updatedSignature
,
expectedUpdatedInvocationDocumentCode
:
expectedUpdatedCode
);
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
ChangeSignature
)]
[
WorkItem
(
28156
,
"https://github.com/dotnet/roslyn/issues/28156"
)]
public
async
Task
ChangeSignature_Formatting_KeepTrivia_WithArgumentNames
()
{
var
markup
=
@"
class C
{
void $$Method(
int a, int b, int c,
int d, int e,
int f)
{
Method(
a: 1, b: 2, c: 3,
d: 4, e: 5, f: 6);
}
}"
;
var
updatedSignature
=
new
[]
{
1
,
2
,
3
,
4
,
5
};
var
expectedUpdatedCode
=
@"
class C
{
void Method(
int b, int c, int d,
int e, int f)
{
Method(
b: 2, c: 3, d: 4,
e: 5, f: 6);
}
}"
;
await
TestChangeSignatureViaCommandAsync
(
LanguageNames
.
CSharp
,
markup
,
updatedSignature
:
updatedSignature
,
expectedUpdatedInvocationDocumentCode
:
expectedUpdatedCode
);
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
ChangeSignature
)]
public
async
Task
ChangeSignature_Formatting_Method
()
{
...
...
@@ -258,6 +324,28 @@ class CustomAttribute : System.Attribute
await
TestChangeSignatureViaCommandAsync
(
LanguageNames
.
CSharp
,
markup
,
updatedSignature
:
updatedSignature
,
expectedUpdatedInvocationDocumentCode
:
expectedUpdatedCode
);
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
ChangeSignature
)]
[
WorkItem
(
28156
,
"https://github.com/dotnet/roslyn/issues/28156"
)]
public
async
Task
ChangeSignature_Formatting_Attribute_KeepTrivia
()
{
var
markup
=
@"
[Custom(
1, 2)]
class CustomAttribute : System.Attribute
{
public $$CustomAttribute(int x, int y) { }
}"
;
var
updatedSignature
=
new
[]
{
1
};
var
expectedUpdatedCode
=
@"
[Custom(
2)]
class CustomAttribute : System.Attribute
{
public CustomAttribute(int y) { }
}"
;
await
TestChangeSignatureViaCommandAsync
(
LanguageNames
.
CSharp
,
markup
,
updatedSignature
:
updatedSignature
,
expectedUpdatedInvocationDocumentCode
:
expectedUpdatedCode
);
}
[
WorkItem
(
946220
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/946220"
)]
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
ChangeSignature
)]
public
async
Task
ChangeSignature_Formatting_LambdaAsArgument
()
...
...
src/EditorFeatures/CSharpTest/ChangeSignature/ReorderParametersTests.cs
浏览文件 @
3689c94d
...
...
@@ -803,7 +803,7 @@ class C
class C
{
/// <summary>
/// See <see cref=""M(
string,
int)""/> and <see cref=""M""/>
/// See <see cref=""M(
string,
int)""/> and <see cref=""M""/>
/// </summary>
void M(string y, int x)
{ }
...
...
src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
浏览文件 @
3689c94d
...
...
@@ -406,17 +406,39 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
var
reorderedParameters
=
updatedSignature
.
UpdatedConfiguration
.
ToListOfParameters
();
var
newParameters
=
new
List
<
T
>();
int
index
=
0
;
foreach
(
var
newParam
in
reorderedParameters
)
{
var
pos
=
originalParameters
.
IndexOf
(
newParam
);
var
param
=
list
[
pos
];
// copy whitespace trivia from original position
param
=
TransferLeadingWhitespaceTrivia
(
param
,
list
[
index
]);
newParameters
.
Add
(
param
);
index
++;
}
var
numSeparatorsToSkip
=
originalParameters
.
Count
-
reorderedParameters
.
Count
;
return
SyntaxFactory
.
SeparatedList
(
newParameters
,
GetSeparators
(
list
,
numSeparatorsToSkip
));
}
private
static
T
TransferLeadingWhitespaceTrivia
<
T
>(
T
newArgument
,
SyntaxNode
oldArgument
)
where
T
:
SyntaxNode
{
var
oldTrivia
=
oldArgument
.
GetLeadingTrivia
();
var
oldOnlyHasWhitespaceTrivia
=
oldTrivia
.
All
(
t
=>
t
.
IsKind
(
SyntaxKind
.
WhitespaceTrivia
));
var
newTrivia
=
newArgument
.
GetLeadingTrivia
();
var
newOnlyHasWhitespaceTrivia
=
newTrivia
.
All
(
t
=>
t
.
IsKind
(
SyntaxKind
.
WhitespaceTrivia
));
if
(
oldOnlyHasWhitespaceTrivia
&&
newOnlyHasWhitespaceTrivia
)
{
return
newArgument
.
WithLeadingTrivia
(
oldTrivia
);
}
return
newArgument
;
}
private
static
SeparatedSyntaxList
<
AttributeArgumentSyntax
>
PermuteAttributeArgumentList
(
Document
document
,
ISymbol
declarationSymbol
,
...
...
@@ -425,7 +447,11 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
{
var
newArguments
=
PermuteArguments
(
document
,
declarationSymbol
,
arguments
.
Select
(
a
=>
UnifiedArgumentSyntax
.
Create
(
a
)).
ToList
(),
updatedSignature
);
var
numSeparatorsToSkip
=
arguments
.
Count
-
newArguments
.
Count
;
return
SyntaxFactory
.
SeparatedList
(
newArguments
.
Select
(
a
=>
(
AttributeArgumentSyntax
)(
UnifiedArgumentSyntax
)
a
),
GetSeparators
(
arguments
,
numSeparatorsToSkip
));
// copy whitespace trivia from original position
var
newArgumentsWithTrivia
=
TransferLeadingWhitespaceTrivia
(
newArguments
.
Select
(
a
=>
(
AttributeArgumentSyntax
)(
UnifiedArgumentSyntax
)
a
),
arguments
);
return
SyntaxFactory
.
SeparatedList
(
newArgumentsWithTrivia
,
GetSeparators
(
arguments
,
numSeparatorsToSkip
));
}
private
static
SeparatedSyntaxList
<
ArgumentSyntax
>
PermuteArgumentList
(
...
...
@@ -436,8 +462,26 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
bool
isReducedExtensionMethod
=
false
)
{
var
newArguments
=
PermuteArguments
(
document
,
declarationSymbol
,
arguments
.
Select
(
a
=>
UnifiedArgumentSyntax
.
Create
(
a
)).
ToList
(),
updatedSignature
,
isReducedExtensionMethod
);
var
newArgumentsWithTrivia
=
TransferLeadingWhitespaceTrivia
(
newArguments
.
Select
(
a
=>
(
ArgumentSyntax
)(
UnifiedArgumentSyntax
)
a
),
arguments
);
// copy whitespace trivia from original position
var
numSeparatorsToSkip
=
arguments
.
Count
-
newArguments
.
Count
;
return
SyntaxFactory
.
SeparatedList
(
newArguments
.
Select
(
a
=>
(
ArgumentSyntax
)(
UnifiedArgumentSyntax
)
a
),
GetSeparators
(
arguments
,
numSeparatorsToSkip
));
return
SyntaxFactory
.
SeparatedList
(
newArgumentsWithTrivia
,
GetSeparators
(
arguments
,
numSeparatorsToSkip
));
}
private
static
List
<
T
>
TransferLeadingWhitespaceTrivia
<
T
,
U
>(
IEnumerable
<
T
>
newArguments
,
SeparatedSyntaxList
<
U
>
oldArguments
)
where
T
:
SyntaxNode
where
U
:
SyntaxNode
{
var
result
=
new
List
<
T
>();
int
index
=
0
;
foreach
(
var
newArgument
in
newArguments
)
{
result
.
Add
(
TransferLeadingWhitespaceTrivia
(
newArgument
,
oldArguments
[
index
]));
index
++;
}
return
result
;
}
private
List
<
SyntaxTrivia
>
UpdateParamTagsInLeadingTrivia
(
CSharpSyntaxNode
node
,
ISymbol
declarationSymbol
,
SignatureChange
updatedSignature
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录