Skip to content

Commit 972dedf

Browse files
author
Loïc Guychard
committed
chore: prettier
1 parent 96a3985 commit 972dedf

File tree

3 files changed

+150
-118
lines changed

3 files changed

+150
-118
lines changed

src/blame.test.ts

Lines changed: 126 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getBlameDecorations,
55
getBlameDecorationsForSelections,
66
getDecorationFromHunk,
7-
Hunk
7+
Hunk,
88
} from './blame'
99
import { createMockSourcegraphAPI } from './util/stubs'
1010

@@ -13,55 +13,54 @@ const FIXTURE_HUNK_1: Hunk = {
1313
endLine: 2,
1414
author: {
1515
person: {
16-
displayName: 'a'
16+
displayName: 'a',
1717
},
18-
date: '2018-09-10T21:52:45Z'
18+
date: '2018-09-10T21:52:45Z',
1919
},
2020
rev: 'b',
2121
message: 'c',
2222
commit: {
23-
url: 'd'
24-
}
23+
url: 'd',
24+
},
2525
}
2626

2727
const FIXTURE_HUNK_2: Hunk = {
2828
startLine: 2,
2929
endLine: 3,
3030
author: {
3131
person: {
32-
displayName: 'e'
32+
displayName: 'e',
3333
},
34-
date: '2018-11-10T21:52:45Z'
34+
date: '2018-11-10T21:52:45Z',
3535
},
3636
rev: 'f',
3737
message: 'g',
3838
commit: {
39-
url: 'h'
40-
}
39+
url: 'h',
40+
},
4141
}
4242

4343
const FIXTURE_HUNK_3: Hunk = {
4444
startLine: 3,
4545
endLine: 4,
4646
author: {
4747
person: {
48-
displayName: 'i'
48+
displayName: 'i',
4949
},
50-
date: '2018-10-10T21:52:45Z'
50+
date: '2018-10-10T21:52:45Z',
5151
},
5252
rev: 'j',
5353
message: 'k',
5454
commit: {
55-
url: 'l'
56-
}
55+
url: 'l',
56+
},
5757
}
5858

5959
const NOW = +new Date('2018-12-01T21:52:45Z')
6060

6161
const SOURCEGRAPH = createMockSourcegraphAPI()
6262

6363
describe('getDecorationsFromHunk()', () => {
64-
6564
it('creates a TextDocumentDecoration from a Hunk', () => {
6665
expect(getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 0, SOURCEGRAPH as any)).toEqual({
6766
after: {
@@ -75,66 +74,87 @@ describe('getDecorationsFromHunk()', () => {
7574
backgroundColor: 'rgba(193, 217, 255, 0.65)',
7675
color: 'rgba(0, 0, 25, 0.55)',
7776
},
78-
linkURL: 'https://sourcegraph.test/d',
79-
},
80-
isWholeLine: true,
81-
range: {
82-
end: 0,
83-
start: 0,
84-
}
85-
}
86-
)
77+
linkURL: 'https://sourcegraph.test/d',
78+
},
79+
isWholeLine: true,
80+
range: {
81+
end: 0,
82+
start: 0,
83+
},
84+
})
8785
})
8886

8987
it('truncates long commit messsages', () => {
90-
const decoration = getDecorationFromHunk({
91-
...FIXTURE_HUNK_1,
92-
message: 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd'
93-
}, NOW, 0, SOURCEGRAPH as any)
94-
expect(decoration.after && decoration.after.contentText).toEqual('a, 3 months ago: • asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabs…')
88+
const decoration = getDecorationFromHunk(
89+
{
90+
...FIXTURE_HUNK_1,
91+
message: 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd',
92+
},
93+
NOW,
94+
0,
95+
SOURCEGRAPH as any
96+
)
97+
expect(decoration.after && decoration.after.contentText).toEqual(
98+
'a, 3 months ago: • asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabs…'
99+
)
95100
})
96101

97102
it('truncates long display names', () => {
98-
const decoration = getDecorationFromHunk({
99-
...FIXTURE_HUNK_1,
100-
author: {
101-
person: {
102-
displayName: 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd'
103+
const decoration = getDecorationFromHunk(
104+
{
105+
...FIXTURE_HUNK_1,
106+
author: {
107+
person: {
108+
displayName: 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd',
109+
},
110+
date: '2018-09-10T21:52:45Z',
103111
},
104-
date:'2018-09-10T21:52:45Z'
105-
}
106-
}, NOW, 0, SOURCEGRAPH as any)
107-
expect(decoration.after && decoration.after.contentText).toEqual('asdgjdsag asdklgbasdghlad…, 3 months ago: • c')
112+
},
113+
NOW,
114+
0,
115+
SOURCEGRAPH as any
116+
)
117+
expect(decoration.after && decoration.after.contentText).toEqual(
118+
'asdgjdsag asdklgbasdghlad…, 3 months ago: • c'
119+
)
108120
})
109121
})
110122

111123
describe('getBlameDecorationsForSelections()', () => {
112-
113124
it('adds decorations only for hunks that are within the selections', () => {
114-
const decorations = getBlameDecorationsForSelections([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3], [
115-
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(1, 0), new SOURCEGRAPH.Position(1, 0)) as any
116-
], NOW, SOURCEGRAPH as any)
117-
expect(decorations).toEqual([
118-
getDecorationFromHunk(FIXTURE_HUNK_2, NOW, 1, SOURCEGRAPH as any)
119-
])
125+
const decorations = getBlameDecorationsForSelections(
126+
[FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3],
127+
[new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(1, 0), new SOURCEGRAPH.Position(1, 0)) as any],
128+
NOW,
129+
SOURCEGRAPH as any
130+
)
131+
expect(decorations).toEqual([getDecorationFromHunk(FIXTURE_HUNK_2, NOW, 1, SOURCEGRAPH as any)])
120132
})
121133

122134
it('handles multiple selections', () => {
123-
const decorations = getBlameDecorationsForSelections([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3], [
124-
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(1, 0), new SOURCEGRAPH.Position(1, 0)) as any,
125-
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(2, 0), new SOURCEGRAPH.Position(5, 0)) as any,
126-
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(6, 0), new SOURCEGRAPH.Position(10, 0)) as any,
127-
], NOW, SOURCEGRAPH as any)
135+
const decorations = getBlameDecorationsForSelections(
136+
[FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3],
137+
[
138+
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(1, 0), new SOURCEGRAPH.Position(1, 0)) as any,
139+
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(2, 0), new SOURCEGRAPH.Position(5, 0)) as any,
140+
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(6, 0), new SOURCEGRAPH.Position(10, 0)) as any,
141+
],
142+
NOW,
143+
SOURCEGRAPH as any
144+
)
128145
expect(decorations).toEqual([
129146
getDecorationFromHunk(FIXTURE_HUNK_2, NOW, 1, SOURCEGRAPH as any),
130147
getDecorationFromHunk(FIXTURE_HUNK_3, NOW, 2, SOURCEGRAPH as any),
131148
])
132149
})
133150

134151
it('handles multiple hunks per selection', () => {
135-
const decorations = getBlameDecorationsForSelections([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3], [
136-
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(0, 0), new SOURCEGRAPH.Position(5, 0)) as any
137-
], NOW, SOURCEGRAPH as any)
152+
const decorations = getBlameDecorationsForSelections(
153+
[FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3],
154+
[new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(0, 0), new SOURCEGRAPH.Position(5, 0)) as any],
155+
NOW,
156+
SOURCEGRAPH as any
157+
)
138158
expect(decorations).toEqual([
139159
getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 0, SOURCEGRAPH as any),
140160
getDecorationFromHunk(FIXTURE_HUNK_2, NOW, 1, SOURCEGRAPH as any),
@@ -143,87 +163,83 @@ describe('getBlameDecorationsForSelections()', () => {
143163
})
144164

145165
it('decorates the start line of the selection if the start line of the hunk is outside of the selection boundaries', () => {
146-
const decorations = getBlameDecorationsForSelections([{
147-
...FIXTURE_HUNK_1,
148-
startLine: 1,
149-
endLine: 10
150-
}], [
151-
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(2, 0), new SOURCEGRAPH.Position(2, 0)) as any
152-
], NOW, SOURCEGRAPH as any)
153-
expect(decorations).toEqual([
154-
getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 2, SOURCEGRAPH as any),
155-
])
166+
const decorations = getBlameDecorationsForSelections(
167+
[
168+
{
169+
...FIXTURE_HUNK_1,
170+
startLine: 1,
171+
endLine: 10,
172+
},
173+
],
174+
[new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(2, 0), new SOURCEGRAPH.Position(2, 0)) as any],
175+
NOW,
176+
SOURCEGRAPH as any
177+
)
178+
expect(decorations).toEqual([getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 2, SOURCEGRAPH as any)])
156179
})
157-
158180
})
159181

160182
describe('getAllBlameDecorations()', () => {
161-
162183
it('adds decorations for all hunks', () => {
163-
expect(getAllBlameDecorations([
164-
FIXTURE_HUNK_1,
165-
FIXTURE_HUNK_2,
166-
FIXTURE_HUNK_3
167-
], NOW, SOURCEGRAPH as any)).toEqual([
184+
expect(
185+
getAllBlameDecorations([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3], NOW, SOURCEGRAPH as any)
186+
).toEqual([
168187
getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 0, SOURCEGRAPH as any),
169188
getDecorationFromHunk(FIXTURE_HUNK_2, NOW, 1, SOURCEGRAPH as any),
170189
getDecorationFromHunk(FIXTURE_HUNK_3, NOW, 2, SOURCEGRAPH as any),
171-
172190
])
173191
})
174-
175192
})
176193

177194
describe('getBlameDecorations()', () => {
178-
179195
it('gets no decorations if git.blame.lineDecorations is false', async () => {
180-
expect(await getBlameDecorations({
181-
uri: 'a',
182-
settings: {
183-
'git.blame.lineDecorations': false
184-
},
185-
now: NOW,
186-
selections: null,
187-
queryHunks: () => Promise.resolve([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3]),
188-
sourcegraph: SOURCEGRAPH as any
189-
})).toEqual([])
196+
expect(
197+
await getBlameDecorations({
198+
uri: 'a',
199+
settings: {
200+
'git.blame.lineDecorations': false,
201+
},
202+
now: NOW,
203+
selections: null,
204+
queryHunks: () => Promise.resolve([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3]),
205+
sourcegraph: SOURCEGRAPH as any,
206+
})
207+
).toEqual([])
190208
})
191209

192210
it('gets decorations for all hunks if no selections are passed', async () => {
193-
expect(await getBlameDecorations({
194-
uri: 'a',
195-
settings: {
196-
'git.blame.lineDecorations': true
197-
},
198-
now: NOW,
199-
selections: null,
200-
queryHunks: () => Promise.resolve([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3]),
201-
sourcegraph: SOURCEGRAPH as any
202-
})).toEqual([
211+
expect(
212+
await getBlameDecorations({
213+
uri: 'a',
214+
settings: {
215+
'git.blame.lineDecorations': true,
216+
},
217+
now: NOW,
218+
selections: null,
219+
queryHunks: () => Promise.resolve([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3]),
220+
sourcegraph: SOURCEGRAPH as any,
221+
})
222+
).toEqual([
203223
getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 0, SOURCEGRAPH as any),
204224
getDecorationFromHunk(FIXTURE_HUNK_2, NOW, 1, SOURCEGRAPH as any),
205225
getDecorationFromHunk(FIXTURE_HUNK_3, NOW, 2, SOURCEGRAPH as any),
206226
])
207227
})
208228

209229
it('gets decorations for the selections if selections are passed', async () => {
210-
expect(await getBlameDecorations({
211-
uri: 'a',
212-
settings: {
213-
'git.blame.lineDecorations': true
214-
},
215-
now: NOW,
216-
selections: [
217-
new SOURCEGRAPH.Selection(
218-
new SOURCEGRAPH.Position(2, 0),
219-
new SOURCEGRAPH.Position(2, 0)
220-
) as any
221-
],
222-
queryHunks: () => Promise.resolve([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3]),
223-
sourcegraph: SOURCEGRAPH as any
224-
})).toEqual([
225-
getDecorationFromHunk(FIXTURE_HUNK_3, NOW, 2, SOURCEGRAPH as any),
226-
])
230+
expect(
231+
await getBlameDecorations({
232+
uri: 'a',
233+
settings: {
234+
'git.blame.lineDecorations': true,
235+
},
236+
now: NOW,
237+
selections: [
238+
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(2, 0), new SOURCEGRAPH.Position(2, 0)) as any,
239+
],
240+
queryHunks: () => Promise.resolve([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3]),
241+
sourcegraph: SOURCEGRAPH as any,
242+
})
243+
).toEqual([getDecorationFromHunk(FIXTURE_HUNK_3, NOW, 2, SOURCEGRAPH as any)])
227244
})
228-
229245
})

src/blame.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { Settings } from './extension'
55
import { resolveURI } from './uri'
66
import { memoizeAsync } from './util/memoizeAsync'
77

8-
export const getDecorationFromHunk = (hunk: Hunk, now: number, decoratedLine: number, sourcegraph: typeof import('sourcegraph')): TextDocumentDecoration => ({
8+
export const getDecorationFromHunk = (
9+
hunk: Hunk,
10+
now: number,
11+
decoratedLine: number,
12+
sourcegraph: typeof import('sourcegraph')
13+
): TextDocumentDecoration => ({
914
range: new sourcegraph.Range(decoratedLine, 0, decoratedLine, 0),
1015
isWholeLine: true,
1116
after: {
@@ -25,7 +30,12 @@ export const getDecorationFromHunk = (hunk: Hunk, now: number, decoratedLine: nu
2530
},
2631
})
2732

28-
export const getBlameDecorationsForSelections = (hunks: Hunk[], selections: Selection[], now: number, sourcegraph: typeof import('sourcegraph')) => {
33+
export const getBlameDecorationsForSelections = (
34+
hunks: Hunk[],
35+
selections: Selection[],
36+
now: number,
37+
sourcegraph: typeof import('sourcegraph')
38+
) => {
2939
const decorations: TextDocumentDecoration[] = []
3040
for (const hunk of hunks) {
3141
// Hunk start and end lines are 1-indexed, but selection lines are zero-indexed
@@ -51,7 +61,7 @@ export const getAllBlameDecorations = (hunks: Hunk[], now: number, sourcegraph:
5161
hunks.map(hunk => getDecorationFromHunk(hunk, now, hunk.startLine - 1, sourcegraph))
5262

5363
const queryBlameHunks = memoizeAsync(
54-
async ({uri, sourcegraph}: {uri: string, sourcegraph: typeof import('sourcegraph')}): Promise<Hunk[]> => {
64+
async ({ uri, sourcegraph }: { uri: string; sourcegraph: typeof import('sourcegraph') }): Promise<Hunk[]> => {
5565
const { repo, rev, path } = resolveURI(uri)
5666
const { data, errors } = await sourcegraph.commands.executeCommand(
5767
'queryGraphQL',
@@ -105,13 +115,13 @@ export const getBlameDecorations = async ({
105115
selections,
106116
now,
107117
queryHunks = queryBlameHunks,
108-
sourcegraph
118+
sourcegraph,
109119
}: {
110120
uri: string
111121
settings: Settings
112-
selections: Selection[] | null,
113-
now: number,
114-
queryHunks?: ({ uri, sourcegraph } : { uri: string, sourcegraph: typeof import('sourcegraph') }) => Promise<Hunk[]>,
122+
selections: Selection[] | null
123+
now: number
124+
queryHunks?: ({ uri, sourcegraph }: { uri: string; sourcegraph: typeof import('sourcegraph') }) => Promise<Hunk[]>
115125
sourcegraph: typeof import('sourcegraph')
116126
}): Promise<TextDocumentDecoration[]> => {
117127
if (!settings['git.blame.lineDecorations']) {

0 commit comments

Comments
 (0)