Skip to content

Commit 43afc1a

Browse files
author
Loïc Guychard
authored
feat: add git.blame.decorateWholeFile setting (#103)
Requested by customer https://app.hubspot.com/contacts/2762526/company/554338610 Adds the `git.blame.decorateWholeFile` setting to the extension. If set to `true`, the extension will add decorations for the whole file, rather than just selected lines.
1 parent 3de7bfd commit 43afc1a

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
"description": "Whether to show Git blame annotations at the end of each line.",
5151
"type": "boolean",
5252
"default": false
53+
},
54+
"git.blame.decorateWholeFile": {
55+
"description": "Whether to decorate all lines in a file, rather than just selected lines.",
56+
"type": "boolean",
57+
"default": false
5358
}
5459
}
5560
}

src/blame.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,29 @@ describe('getBlameDecorations()', () => {
279279
).toEqual([getDecorationFromHunk(FIXTURE_HUNK_4, NOW, 3, SOURCEGRAPH as any)])
280280
})
281281

282+
it('gets decorations for all hunks if git.blame.decorateWholeFile is true', async () => {
283+
expect(
284+
await getBlameDecorations({
285+
uri: 'a',
286+
settings: {
287+
'git.blame.lineDecorations': true,
288+
'git.blame.decorateWholeFile': true,
289+
},
290+
now: NOW,
291+
selections: [
292+
new SOURCEGRAPH.Selection(new SOURCEGRAPH.Position(3, 0), new SOURCEGRAPH.Position(3, 0)) as any,
293+
],
294+
queryHunks: () => Promise.resolve([FIXTURE_HUNK_1, FIXTURE_HUNK_2, FIXTURE_HUNK_3, FIXTURE_HUNK_4]),
295+
sourcegraph: SOURCEGRAPH as any,
296+
})
297+
).toEqual([
298+
getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 0, SOURCEGRAPH as any),
299+
getDecorationFromHunk(FIXTURE_HUNK_2, NOW, 1, SOURCEGRAPH as any),
300+
getDecorationFromHunk(FIXTURE_HUNK_3, NOW, 2, SOURCEGRAPH as any),
301+
getDecorationFromHunk(FIXTURE_HUNK_4, NOW, 3, SOURCEGRAPH as any),
302+
])
303+
})
304+
282305
it('renders username in decoration content message', async () => {
283306
expect(
284307
getDecorationFromHunk(FIXTURE_HUNK_4, NOW, 3, SOURCEGRAPH as any).after!.contentText!.startsWith(

src/blame.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const getBlameDecorations = async ({
135135
return []
136136
}
137137
const hunks = await queryHunks({ uri, sourcegraph })
138-
if (selections !== null) {
138+
if (selections !== null && !settings['git.blame.decorateWholeFile']) {
139139
return getBlameDecorationsForSelections(hunks, selections, now, sourcegraph)
140140
} else {
141141
return getAllBlameDecorations(hunks, now, sourcegraph)

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getBlameDecorations } from './blame'
55

66
export interface Settings {
77
['git.blame.lineDecorations']?: boolean
8+
['git.blame.decorateWholeFile']?: boolean
89
}
910

1011
const decorationType = sourcegraph.app.createDecorationType && sourcegraph.app.createDecorationType()

0 commit comments

Comments
 (0)