Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d4ddda41
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4ddda41
编写于
9月 22, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #44422: Improve diff hunks merging strategy
上级
caa53344
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
141 addition
and
36 deletion
+141
-36
src/vs/base/common/diff/diff.ts
src/vs/base/common/diff/diff.ts
+23
-36
src/vs/editor/test/common/diff/diffComputer.test.ts
src/vs/editor/test/common/diff/diffComputer.test.ts
+118
-0
未找到文件。
src/vs/base/common/diff/diff.ts
浏览文件 @
d4ddda41
...
...
@@ -263,7 +263,7 @@ export class LcsDiff {
// We have to clean up the computed diff to be more intuitive
// but it turns out this cannot be done correctly until the entire set
// of diffs have been computed
return
this
.
Shift
Changes
(
changes
);
return
this
.
Prettify
Changes
(
changes
);
}
return
changes
;
...
...
@@ -746,45 +746,32 @@ export class LcsDiff {
* @param changes The list of changes to shift
* @returns The shifted changes
*/
private
ShiftChanges
(
changes
:
DiffChange
[]):
DiffChange
[]
{
let
mergedDiffs
:
boolean
;
do
{
mergedDiffs
=
false
;
// Shift all the changes down first
for
(
let
i
=
0
;
i
<
changes
.
length
;
i
++
)
{
const
change
=
changes
[
i
];
const
originalStop
=
(
i
<
changes
.
length
-
1
)
?
changes
[
i
+
1
].
originalStart
:
this
.
OriginalSequence
.
getLength
();
const
modifiedStop
=
(
i
<
changes
.
length
-
1
)
?
changes
[
i
+
1
].
modifiedStart
:
this
.
ModifiedSequence
.
getLength
();
const
checkOriginal
=
change
.
originalLength
>
0
;
const
checkModified
=
change
.
modifiedLength
>
0
;
while
(
change
.
originalStart
+
change
.
originalLength
<
originalStop
&&
change
.
modifiedStart
+
change
.
modifiedLength
<
modifiedStop
&&
(
!
checkOriginal
||
this
.
OriginalElementsAreEqual
(
change
.
originalStart
,
change
.
originalStart
+
change
.
originalLength
))
&&
(
!
checkModified
||
this
.
ModifiedElementsAreEqual
(
change
.
modifiedStart
,
change
.
modifiedStart
+
change
.
modifiedLength
)))
{
change
.
originalStart
++
;
change
.
modifiedStart
++
;
}
private
PrettifyChanges
(
changes
:
DiffChange
[]):
DiffChange
[]
{
// Shift all the changes down first
for
(
let
i
=
0
;
i
<
changes
.
length
;
i
++
)
{
const
change
=
changes
[
i
];
const
originalStop
=
(
i
<
changes
.
length
-
1
)
?
changes
[
i
+
1
].
originalStart
:
this
.
OriginalSequence
.
getLength
();
const
modifiedStop
=
(
i
<
changes
.
length
-
1
)
?
changes
[
i
+
1
].
modifiedStart
:
this
.
ModifiedSequence
.
getLength
();
const
checkOriginal
=
change
.
originalLength
>
0
;
const
checkModified
=
change
.
modifiedLength
>
0
;
while
(
change
.
originalStart
+
change
.
originalLength
<
originalStop
&&
change
.
modifiedStart
+
change
.
modifiedLength
<
modifiedStop
&&
(
!
checkOriginal
||
this
.
OriginalElementsAreEqual
(
change
.
originalStart
,
change
.
originalStart
+
change
.
originalLength
))
&&
(
!
checkModified
||
this
.
ModifiedElementsAreEqual
(
change
.
modifiedStart
,
change
.
modifiedStart
+
change
.
modifiedLength
)))
{
change
.
originalStart
++
;
change
.
modifiedStart
++
;
}
// Build up the new list (we have to build a new list because we
// might have changes we can merge together now)
let
result
=
new
Array
<
DiffChange
>
();
let
mergedChangeArr
:
DiffChange
[]
=
[
null
];
for
(
let
i
=
0
;
i
<
changes
.
length
;
i
++
)
{
if
(
i
<
changes
.
length
-
1
&&
this
.
ChangesOverlap
(
changes
[
i
],
changes
[
i
+
1
],
mergedChangeArr
))
{
mergedDiffs
=
true
;
result
.
push
(
mergedChangeArr
[
0
]);
i
++
;
}
else
{
result
.
push
(
changes
[
i
]);
}
if
(
i
<
changes
.
length
-
1
&&
this
.
ChangesOverlap
(
changes
[
i
],
changes
[
i
+
1
],
mergedChangeArr
))
{
changes
[
i
]
=
mergedChangeArr
[
0
];
changes
.
splice
(
i
+
1
,
1
);
i
--
;
continue
;
}
changes
=
result
;
}
while
(
mergedDiffs
);
}
// Shift changes back up until we hit empty or whitespace-only lines
for
(
let
i
=
changes
.
length
-
1
;
i
>=
0
;
i
--
)
{
...
...
src/vs/editor/test/common/diff/diffComputer.test.ts
浏览文件 @
d4ddda41
...
...
@@ -729,4 +729,122 @@ suite('Editor Diff - DiffComputer', () => {
];
assertDiff
(
original
,
modified
,
expected
,
false
,
false
,
false
);
});
test
(
'
issue #44422: Less than ideal diff results
'
,
()
=>
{
let
original
=
[
'
export class C {
'
,
''
,
'
public m1(): void {
'
,
'
{
'
,
'
//2
'
,
'
//3
'
,
'
//4
'
,
'
//5
'
,
'
//6
'
,
'
//7
'
,
'
//8
'
,
'
//9
'
,
'
//10
'
,
'
//11
'
,
'
//12
'
,
'
//13
'
,
'
//14
'
,
'
//15
'
,
'
//16
'
,
'
//17
'
,
'
//18
'
,
'
}
'
,
'
}
'
,
''
,
'
public m2(): void {
'
,
'
if (a) {
'
,
'
if (b) {
'
,
'
//A1
'
,
'
//A2
'
,
'
//A3
'
,
'
//A4
'
,
'
//A5
'
,
'
//A6
'
,
'
//A7
'
,
'
//A8
'
,
'
}
'
,
'
}
'
,
''
,
'
//A9
'
,
'
//A10
'
,
'
//A11
'
,
'
//A12
'
,
'
//A13
'
,
'
//A14
'
,
'
//A15
'
,
'
}
'
,
''
,
'
public m3(): void {
'
,
'
if (a) {
'
,
'
//B1
'
,
'
}
'
,
'
//B2
'
,
'
//B3
'
,
'
}
'
,
''
,
'
public m4(): boolean {
'
,
'
//1
'
,
'
//2
'
,
'
//3
'
,
'
//4
'
,
'
}
'
,
''
,
'
}
'
,
];
let
modified
=
[
'
export class C {
'
,
''
,
'
constructor() {
'
,
''
,
''
,
''
,
''
,
'
}
'
,
''
,
'
public m1(): void {
'
,
'
{
'
,
'
//2
'
,
'
//3
'
,
'
//4
'
,
'
//5
'
,
'
//6
'
,
'
//7
'
,
'
//8
'
,
'
//9
'
,
'
//10
'
,
'
//11
'
,
'
//12
'
,
'
//13
'
,
'
//14
'
,
'
//15
'
,
'
//16
'
,
'
//17
'
,
'
//18
'
,
'
}
'
,
'
}
'
,
''
,
'
public m4(): boolean {
'
,
'
//1
'
,
'
//2
'
,
'
//3
'
,
'
//4
'
,
'
}
'
,
''
,
'
}
'
,
];
let
expected
=
[
createLineChange
(
2
,
0
,
3
,
9
),
createLineChange
(
25
,
55
,
31
,
0
)
];
assertDiff
(
original
,
modified
,
expected
,
false
,
false
,
false
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录