Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
971aa63f
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,发现更多精彩内容 >>
提交
971aa63f
编写于
4月 19, 2017
作者:
I
Ivan Basov
提交者:
GitHub
4月 19, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
workaround for Microsoft.CodeAnalysis.Differencing.Match makes not optimal matches (#18802)
上级
4f7b313c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
6 deletion
+66
-6
src/EditorFeatures/CSharpTest/EditAndContinue/RudeEditStatementTests.cs
...ures/CSharpTest/EditAndContinue/RudeEditStatementTests.cs
+56
-0
src/Workspaces/Core/Portable/Differencing/Match.cs
src/Workspaces/Core/Portable/Differencing/Match.cs
+10
-6
未找到文件。
src/EditorFeatures/CSharpTest/EditAndContinue/RudeEditStatementTests.cs
浏览文件 @
971aa63f
...
...
@@ -960,6 +960,36 @@ public void InterpolationFormatClause_update()
edits
.
VerifyEdits
(
"Update [x = $\"Hello{123:N1}\"]@8 -> [x = $\"Hello{123:N2}\"]@8"
);
}
[
Fact
]
public
void
MatchCasePattern_UpdateDelete
()
{
var
src1
=
@"
switch(shape)
{
case Point p: return 0;
case Circle c: return 1;
}
"
;
var
src2
=
@"
switch(shape)
{
case Circle circle: return 1;
}
"
;
var
match
=
GetMethodMatches
(
src1
,
src2
,
kind
:
MethodKind
.
Regular
);
var
actual
=
ToMatchingPairs
(
match
);
var
expected
=
new
MatchingPairs
{
{
"switch(shape) { case Point p: return 0; case Circle c: return 1; }"
,
"switch(shape) { case Circle circle: return 1; }"
},
{
"case Circle c: return 1;"
,
"case Circle circle: return 1;"
},
{
"return 1;"
,
"return 1;"
}
};
expected
.
AssertEqual
(
actual
);
}
#
endregion
#
region
Variable
Declaration
...
...
@@ -1035,6 +1065,32 @@ public void Switch_Case_Update()
"Update [case 1: f(); break;]@18 -> [case 2: f(); break;]@18"
);
}
[
Fact
]
public
void
CasePatternLabel_UpdateDelete
()
{
var
src1
=
@"
switch(shape)
{
case Point p: return 0;
case Circle c: return 1;
}
"
;
var
src2
=
@"
switch(shape)
{
case Circle circle: return 1;
}
"
;
var
edits
=
GetMethodEdits
(
src1
,
src2
);
edits
.
VerifyEdits
(
"Update [case Circle c: return 1;]@55 -> [case Circle circle: return 1;]@26"
,
"Delete [case Point p: return 0;]@26"
,
"Delete [return 0;]@40"
);
}
#
endregion
#
region
Try
Catch
Finally
...
...
src/Workspaces/Core/Portable/Differencing/Match.cs
浏览文件 @
971aa63f
...
...
@@ -12,10 +12,9 @@ public sealed partial class Match<TNode>
{
private
const
double
ExactMatchDistance
=
0.0
;
private
const
double
EpsilonDistance
=
0.00001
;
private
const
double
MatchingDistance1
=
0.5
;
private
const
double
MatchingDistance2
=
1.0
;
private
const
double
MatchingDistance3
=
1.5
;
private
const
double
MaxDistance
=
2.0
;
private
const
double
MatchingDistance1
=
0.25
;
private
const
double
MatchingDistance2
=
0.5
;
private
const
double
MaxDistance
=
1.0
;
private
readonly
TreeComparer
<
TNode
>
_comparer
;
private
readonly
TNode
_root1
;
...
...
@@ -154,7 +153,6 @@ private void ComputeMatchForLabel(int label, List<TNode> s1, List<TNode> s2)
ComputeMatchForLabel
(
s1
,
s2
,
tiedToAncestor
,
EpsilonDistance
);
// almost exact match
ComputeMatchForLabel
(
s1
,
s2
,
tiedToAncestor
,
MatchingDistance1
);
// ok match
ComputeMatchForLabel
(
s1
,
s2
,
tiedToAncestor
,
MatchingDistance2
);
// ok match
ComputeMatchForLabel
(
s1
,
s2
,
tiedToAncestor
,
MatchingDistance3
);
// ok match
ComputeMatchForLabel
(
s1
,
s2
,
tiedToAncestor
,
MaxDistance
);
// any match
}
...
...
@@ -168,6 +166,7 @@ private void ComputeMatchForLabel(List<TNode> s1, List<TNode> s2, int tiedToAnce
// So in the case of totally matching sequences, we process them in O(n) -
// both node1 and firstNonMatch2 will be advanced simultaneously.
Debug
.
Assert
(
maxAcceptableDistance
>=
ExactMatchDistance
&&
maxAcceptableDistance
<=
MaxDistance
);
int
count1
=
s1
.
Count
;
int
count2
=
s2
.
Count
;
int
firstNonMatch2
=
0
;
...
...
@@ -184,7 +183,7 @@ private void ComputeMatchForLabel(List<TNode> s1, List<TNode> s2, int tiedToAnce
// Find node2 that matches node1 the best, i.e. has minimal distance.
double
bestDistance
=
MaxDistance
;
double
bestDistance
=
MaxDistance
*
2
;
TNode
bestMatch
=
default
(
TNode
);
bool
matched
=
false
;
int
i2
;
...
...
@@ -258,6 +257,11 @@ private void ComputeMatchForLabel(List<TNode> s1, List<TNode> s2, int tiedToAnce
{
firstNonMatch2
=
i2
+
1
;
}
if
(
firstNonMatch2
==
count2
)
{
return
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录