FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-pull-request-github/src/common/commentingRanges.ts at master · zbjit/vscode-pull-request-github · GitHub
zbjit
/
vscode-pull-request-github
Public
forked from
microsoft/vscode-pull-request-github
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
vscode-pull-request-github
/
src
/
common
/
commentingRanges.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (53 loc) · 2.13 KB
Breadcrumbs
vscode-pull-request-github
/
src
/
common
/
commentingRanges.ts
Copy path
File metadata and controls
58 lines (53 loc) · 2.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*---------------------------------------------------------------------------------------------
* 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
{
DiffHunk
,
DiffChangeType
}
from
'./diffHunk'
;
import
{
getZeroBased
}
from
'./diffPositionMapping'
;
/**
* For the base file, the only commentable areas are deleted lines. For the modified file,
* comments can be added on any part of the diff hunk.
*
@param
diffHunks The diff hunks of the file
*
@param
isBase Whether the commenting ranges are calculated for the base or modified file
*/
export
function
getCommentingRanges
(
diffHunks
:
DiffHunk
[
]
,
isBase
:
boolean
)
:
vscode
.
Range
[
]
{
const
ranges
:
vscode
.
Range
[
]
=
[
]
;
for
(
let
i
=
0
;
i
<
diffHunks
.
length
;
i
++
)
{
const
diffHunk
=
diffHunks
[
i
]
;
let
startingLine
:
number
|
undefined
;
let
length
:
number
;
if
(
isBase
)
{
let
endingLine
:
number
|
undefined
;
for
(
let
j
=
0
;
j
<
diffHunk
.
diffLines
.
length
;
j
++
)
{
const
diffLine
=
diffHunk
.
diffLines
[
j
]
;
if
(
diffLine
.
type
===
DiffChangeType
.
Delete
)
{
if
(
startingLine
!==
undefined
)
{
endingLine
=
getZeroBased
(
diffLine
.
oldLineNumber
)
;
}
else
{
startingLine
=
getZeroBased
(
diffLine
.
oldLineNumber
)
;
endingLine
=
getZeroBased
(
diffLine
.
oldLineNumber
)
;
}
}
else
{
if
(
startingLine
!==
undefined
&&
endingLine
!==
undefined
)
{
ranges
.
push
(
new
vscode
.
Range
(
startingLine
,
0
,
endingLine
,
0
)
)
;
startingLine
=
undefined
;
endingLine
=
undefined
;
}
}
}
if
(
startingLine
!==
undefined
&&
endingLine
!==
undefined
)
{
ranges
.
push
(
new
vscode
.
Range
(
startingLine
,
0
,
endingLine
,
0
)
)
;
startingLine
=
undefined
;
endingLine
=
undefined
;
}
}
else
{
if
(
diffHunk
.
newLineNumber
)
{
startingLine
=
getZeroBased
(
diffHunk
.
newLineNumber
)
;
length
=
getZeroBased
(
diffHunk
.
newLength
)
;
ranges
.
push
(
new
vscode
.
Range
(
startingLine
,
0
,
startingLine
+
length
,
0
)
)
;
}
}
}
return
ranges
;
}
Back
|
FazBrowse Home
|
New Git URL