Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
csdn-workflow
提交
974a38d0
C
csdn-workflow
项目概览
BaiXuePrincess
/
csdn-workflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
csdn-workflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
974a38d0
编写于
6月 03, 2021
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: handle commenting on the last line
上级
6502597a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
6 deletion
+39
-6
src/git/diff_line_count.test.ts
src/git/diff_line_count.test.ts
+13
-0
src/git/diff_line_count.ts
src/git/diff_line_count.ts
+2
-1
src/review/commenting_range_provider.test.ts
src/review/commenting_range_provider.test.ts
+18
-2
src/review/commenting_range_provider.ts
src/review/commenting_range_provider.ts
+6
-3
未找到文件。
src/git/diff_line_count.test.ts
浏览文件 @
974a38d0
...
...
@@ -100,6 +100,17 @@ describe('diff_line_count', () => {
` 18`
,
].
join
(
'
\n
'
);
const
hunkWithoutNewLines
=
[
'
@@ -1 +1,4 @@
'
,
'
-# Initial readme
'
,
'
\\
No newline at end of file
'
,
'
+1
'
,
'
+2
'
,
'
+3
'
,
'
+4
'
,
'
\\
No newline at end of file
'
,
].
join
(
'
\n
'
);
const
testVersion
=
(
diff
:
string
):
RestMrVersion
=>
({
...
mrVersion
,
diffs
:
[{
...
diffFile
,
diff
}],
...
...
@@ -112,6 +123,8 @@ describe('diff_line_count', () => {
${
'
hunkWithAddedAndRemovedLines
'
}
|
${
hunkWithAddedAndRemovedLines
}
|
${[
13
,
14
,
18
,
24
]}
${
'
multiHunk
'
}
|
${
multiHunk
}
|
${[
15
,
39
,
40
,
97
,
98
]}
${
'
hunkWithHunkHeaders
'
}
|
${
hunkWithHunkHeaders
}
|
${[
15
]}
${
'
hunkWithHunkHeaders
'
}
|
${
hunkWithHunkHeaders
}
|
${[
15
]}
${
'
hunkWithoutNewLines
'
}
|
${
hunkWithoutNewLines
}
|
${[
1
,
2
,
3
,
4
]}
`
(
'
$hunkName gets correctly parsed
'
,
({
hunk
,
newLines
})
=>
{
const
ranges
=
getAddedLinesForFile
(
testVersion
(
hunk
),
diffFile
.
new_path
);
...
...
src/git/diff_line_count.ts
浏览文件 @
974a38d0
...
...
@@ -16,7 +16,7 @@ const isEmpty = (obj: any): boolean =>
* `@@ -38,9 +36,8 @@` reads: hunk starts at line 38 of the old version and 36 of the new version.
*/
const
getHunkStartingLine
=
(
headerString
=
''
):
{
oldStart
:
number
;
newStart
:
number
}
|
null
=>
{
const
headerMatch
=
headerString
.
match
(
/@@ -
(\d
+
)
,
\d
+
\+(\d
+
)
,
\d
+
@@/
);
const
headerMatch
=
headerString
.
match
(
/@@ -
(\d
+
)
(?:
,
\d
+
)?
\+(\d
+
)(?:
,
\d
+
)?
@@/
);
return
(
headerMatch
&&
{
oldStart
:
parseInt
(
headerMatch
[
1
],
10
),
...
...
@@ -48,6 +48,7 @@ const parseHunk = (hunk: string): HunkLine[] => {
assert
(
header
);
const
result
=
remainingLines
.
filter
(
l
=>
l
)
// no empty lines
.
filter
(
l
=>
!
l
.
startsWith
(
'
\\
'
))
// ignore '\ No newline at end of file'
.
reduce
(
({
oldIndex
,
newIndex
,
lines
},
line
)
=>
{
const
prefix
=
line
[
0
];
...
...
src/review/commenting_range_provider.test.ts
浏览文件 @
974a38d0
...
...
@@ -35,15 +35,31 @@ describe('CommentingRangeProvider', () => {
});
it
(
'
returns full range (all lines in the document) for old file
'
,
()
=>
{
const
testDocument
=
{
const
testDocument
=
(
{
uri
:
oldFileUrl
,
lineCount
:
200
,
}
as
vscode
.
TextDocument
;
lineAt
:
()
=>
({
isEmptyOrWhitespace
:
false
,
}),
}
as
unknown
)
as
vscode
.
TextDocument
;
expect
(
commentingRangeProvider
.
provideCommentingRanges
(
testDocument
)).
toEqual
([
new
vscode
.
Range
(
new
vscode
.
Position
(
0
,
0
),
new
vscode
.
Position
(
199
,
0
)),
]);
});
it
(
'
returns range without the last line for old file if the last line is empty
'
,
()
=>
{
const
testDocument
=
({
uri
:
oldFileUrl
,
lineCount
:
200
,
lineAt
:
()
=>
({
isEmptyOrWhitespace
:
true
,
}),
}
as
unknown
)
as
vscode
.
TextDocument
;
expect
(
commentingRangeProvider
.
provideCommentingRanges
(
testDocument
)).
toEqual
([
new
vscode
.
Range
(
new
vscode
.
Position
(
0
,
0
),
new
vscode
.
Position
(
198
,
0
)),
]);
});
const
threeNewLinesHunk
=
[
'
@@ -0,0 +1,3 @@
'
,
'
+new file 2
'
,
'
+
'
,
'
+12
'
,
''
].
join
(
'
\n
'
);
it
(
'
shows correct commenting ranges for a new file
'
,
()
=>
{
...
...
src/review/commenting_range_provider.ts
浏览文件 @
974a38d0
...
...
@@ -3,6 +3,10 @@ import { REVIEW_URI_SCHEME } from '../constants';
import
{
getAddedLinesForFile
}
from
'
../git/diff_line_count
'
;
import
{
fromReviewUri
}
from
'
./review_uri
'
;
const
lastLineEmpty
=
(
document
:
vscode
.
TextDocument
):
boolean
=>
{
const
lastLIne
=
document
.
lineAt
(
document
.
lineCount
-
1
);
return
lastLIne
.
isEmptyOrWhitespace
;
};
export
class
CommentingRangeProvider
implements
vscode
.
CommentingRangeProvider
{
private
mr
:
RestIssuable
;
...
...
@@ -22,9 +26,8 @@ export class CommentingRangeProvider implements vscode.CommentingRangeProvider {
}
const
oldFile
=
params
.
commit
===
this
.
mrVersion
.
base_commit_sha
;
if
(
oldFile
)
{
return
[
new
vscode
.
Range
(
new
vscode
.
Position
(
0
,
0
),
new
vscode
.
Position
(
document
.
lineCount
-
1
,
0
)),
];
const
endOfRange
=
lastLineEmpty
(
document
)
?
document
.
lineCount
-
2
:
document
.
lineCount
-
1
;
return
[
new
vscode
.
Range
(
new
vscode
.
Position
(
0
,
0
),
new
vscode
.
Position
(
endOfRange
,
0
))];
}
const
result
=
getAddedLinesForFile
(
this
.
mrVersion
,
params
.
path
);
return
result
.
map
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录