Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
49ee1404
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,发现更多精彩内容 >>
提交
49ee1404
编写于
5月 22, 2017
作者:
P
Phil Price
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove legacy parser
上级
1535f99f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
129 deletion
+0
-129
extensions/merge-conflict/src/mergeConflictParserLegacy.ts
extensions/merge-conflict/src/mergeConflictParserLegacy.ts
+0
-129
未找到文件。
extensions/merge-conflict/src/mergeConflictParserLegacy.ts
已删除
100644 → 0
浏览文件 @
1535f99f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
*
as
interfaces
from
'
./interfaces
'
;
import
{
DocumentMergeConflict
}
from
'
./documentMergeConflict
'
;
import
*
as
vm
from
'
vm
'
;
export
class
MergeConflictParser
{
static
scanDocument
(
document
:
vscode
.
TextDocument
):
interfaces
.
IDocumentMergeConflict
[]
{
// Conflict matching regex, comments are in the format of "description - [group index] group name"
// Premise is: Match the current change (<<<<<<), match anything up to the splitter (======) then
// match anything up to the incoming change (>>>>>>), this leaves some oddities with newlines not being
// pulled into the "body" of each change, DocumentMergeConflict.applyEdit will deal with these cases
// and append newlines when needed
const
conflictMatcher
=
new
RegExp
([
/
(
^<<<<<<<
\s(
.+
)\r?\n)
/
,
// "Current" conflict header - [1] entire line, [2] name
/
([\s\S]
*
?)
/
,
// "Current" conflict body - [3] body text
/
(
^=======
\r?\n)
/
,
// Splitter - [4] entire line
/
([\s\S]
*
?)
/
,
// Incoming conflict body - [5]
/
(
^>>>>>>>
\s(
.+
)\r?\n)
/
// Incoming conflict header - [6] entire line, [7] name
].
map
(
r
=>
r
.
source
).
join
(
''
),
'
mg
'
);
const
offsetGroups
=
[
1
,
3
,
4
,
5
,
6
];
// Skip inner matches when calculating length
let
text
=
document
.
getText
();
let
sandboxScope
=
{
result
:
[],
conflictMatcher
,
text
:
text
};
const
context
=
vm
.
createContext
(
sandboxScope
);
const
script
=
new
vm
.
Script
(
`
let match;
while (match = conflictMatcher.exec(text)) {
// Ensure we don't get stuck in an infinite loop
if (match.index === conflictMatcher.lastIndex) {
conflictMatcher.lastIndex++;
}
result.push(match);
}`
);
try
{
// If the regex takes longer than 1s consider it dead
script
.
runInContext
(
context
,
{
timeout
:
1000
});
}
catch
(
ex
)
{
return
[];
}
return
sandboxScope
.
result
.
map
(
match
=>
new
DocumentMergeConflict
(
document
,
MergeConflictParser
.
matchesToDescriptor
(
document
,
match
,
offsetGroups
)));
}
static
containsConflict
(
document
:
vscode
.
TextDocument
):
boolean
{
if
(
!
document
)
{
return
false
;
}
// TODO: Ask source control if the file contains a conflict
let
text
=
document
.
getText
();
return
text
.
includes
(
'
<<<<<<<
'
)
&&
text
.
includes
(
'
>>>>>>>
'
);
}
static
matchesToDescriptor
(
document
:
vscode
.
TextDocument
,
match
:
RegExpExecArray
,
offsets
?:
number
[]):
interfaces
.
IDocumentMergeConflictDescriptor
{
var
item
:
interfaces
.
IDocumentMergeConflictDescriptor
=
{
range
:
new
vscode
.
Range
(
document
.
positionAt
(
match
.
index
),
document
.
positionAt
(
match
.
index
+
match
[
0
].
length
)),
current
:
{
name
:
match
[
2
],
header
:
this
.
getMatchPositions
(
document
,
match
,
1
,
offsets
),
content
:
this
.
getMatchPositions
(
document
,
match
,
3
,
offsets
),
},
splitter
:
this
.
getMatchPositions
(
document
,
match
,
4
,
offsets
),
incoming
:
{
name
:
match
[
9
],
header
:
this
.
getMatchPositions
(
document
,
match
,
6
,
offsets
),
content
:
this
.
getMatchPositions
(
document
,
match
,
5
,
offsets
),
}
};
return
item
;
}
static
getMatchPositions
(
document
:
vscode
.
TextDocument
,
match
:
RegExpExecArray
,
groupIndex
:
number
,
offsetGroups
?:
number
[]):
vscode
.
Range
{
// Javascript doesnt give of offsets within the match, we need to calculate these
// based of the prior groups, skipping nested matches (yuck).
if
(
!
offsetGroups
)
{
offsetGroups
=
match
.
map
((
i
,
idx
)
=>
idx
);
}
let
start
=
match
.
index
;
for
(
var
i
=
0
;
i
<
offsetGroups
.
length
;
i
++
)
{
let
value
=
offsetGroups
[
i
];
if
(
value
>=
groupIndex
)
{
break
;
}
start
+=
match
[
value
]
!==
undefined
?
match
[
value
].
length
:
0
;
}
const
groupMatch
=
match
[
groupIndex
];
let
targetMatchLength
=
groupMatch
!==
undefined
?
groupMatch
.
length
:
-
1
;
let
end
=
(
start
+
targetMatchLength
);
if
(
groupMatch
!==
undefined
)
{
// Move the end up if it's capped by a trailing \r\n, this is so regions don't expand into
// the line below, and can be "pulled down" by editing the line below
if
(
match
[
groupIndex
].
lastIndexOf
(
'
\n
'
)
===
targetMatchLength
-
1
)
{
end
--
;
// .. for windows encodings of new lines
if
(
match
[
groupIndex
].
lastIndexOf
(
'
\r
'
)
===
targetMatchLength
-
2
)
{
end
--
;
}
}
}
return
new
vscode
.
Range
(
document
.
positionAt
(
start
),
document
.
positionAt
(
end
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录