Skip to content

Commit 22f6326

Browse files
authored
feat: vary blame modes depending on enableExtensionsDecorationsColumnView experimental feature (#276)
1 parent ca622c7 commit 22f6326

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
[
2828
"git.blame.decorations"
2929
],
30-
"${(config.git.blame.decorations === 'line' && 'file') || (config.git.blame.decorations === 'file' && 'none') || 'line'}",
30+
"${(config.git.blame.decorations === 'line' && 'file') || (config.git.blame.decorations === 'file' && 'none') || (clientApplication.isSourcegraph && experimentalFeatures.enableExtensionsDecorationsColumnView && 'file' || 'line')}",
3131
null
3232
],
3333
"category": "Git",
34-
"title": "${(config.git.blame.decorations === 'line' && 'Show blame for the whole file') || (config.git.blame.decorations === 'file' && 'Hide blame') || 'Show blame for selected lines'}",
34+
"title": "${(config.git.blame.decorations === 'line' && 'Show blame for the whole file') || (config.git.blame.decorations === 'file' && 'Hide blame') || (clientApplication.isSourcegraph && experimentalFeatures.enableExtensionsDecorationsColumnView && 'Show blame for the whole file' || 'Show blame for selected lines')}",
3535
"actionItem": {
3636
"label": "Blame",
37-
"description": "${(config.git.blame.decorations === 'line' && 'Show Git blame line annotations for the whole file') || (config.git.blame.decorations === 'file' && 'Hide Git blame line annotations') || 'Show Git blame line annotations on selected lines'}",
38-
"pressed": "(config.git.blame.decorations === 'line') || (config.git.blame.decorations === 'file')",
37+
"description": "${(config.git.blame.decorations === 'line' && 'Show Git blame line annotations for the whole file') || (config.git.blame.decorations === 'file' && 'Hide Git blame line annotations') || (clientApplication.isSourcegraph && experimentalFeatures.enableExtensionsDecorationsColumnView && 'Show Git blame line annotations for the whole file' || 'Show Git blame line annotations on selected lines')}",
38+
"pressed": "((!clientApplication.isSourcegraph || !experimentalFeatures.enableExtensionsDecorationsColumnView) && config.git.blame.decorations === 'line') || (config.git.blame.decorations === 'file')",
3939
"iconURL": "https://raw.githubusercontent.com/sourcegraph/sourcegraph-git-extras/63dd95962c43b95b3f3a9ea2aa0165d6b38a958c/icon/git_logo.svg?sanitize=true"
4040
}
4141
}
@@ -129,6 +129,7 @@
129129
"@types/node": "16.11.33",
130130
"@types/sinon": "10.0.11",
131131
"expect": "^24.1.0",
132+
"graphql": "^15.4.0",
132133
"husky": "^4.3.5",
133134
"lnfs-cli": "^2.1.0",
134135
"lodash": "^4.17.20",
@@ -139,7 +140,7 @@
139140
"prettier": "^1.19.1",
140141
"sinon": "^9.2.1",
141142
"source-map-support": "^0.5.12",
142-
"sourcegraph": "^25.3.0",
143+
"sourcegraph": "^25.6.0",
143144
"ts-node": "^8.10.2",
144145
"tslint": "^5.11.0",
145146
"typescript": "^4.1.2",

src/blame.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('getDecorationsFromHunk()', () => {
9393
getDecorationFromHunk(FIXTURE_HUNK_1, NOW, 0, { 'git.blame.showPreciseDate': false }, SOURCEGRAPH as any)
9494
).toEqual({
9595
after: {
96-
contentText: 'a, 3 months ago:c',
96+
contentText: '3 months ago • a [c]',
9797
dark: {
9898
backgroundColor: 'rgba(15, 43, 89, 0.65)',
9999
color: 'rgba(235, 235, 255, 0.55)',
@@ -125,7 +125,7 @@ describe('getDecorationsFromHunk()', () => {
125125
SOURCEGRAPH as any
126126
)
127127
expect(decoration.after && decoration.after.contentText).toEqual(
128-
'a, 3 months ago: • asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabs…'
128+
'3 months ago • a [asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabs…]'
129129
)
130130
})
131131

@@ -148,7 +148,7 @@ describe('getDecorationsFromHunk()', () => {
148148
SOURCEGRAPH as any
149149
)
150150
expect(decoration.after && decoration.after.contentText).toEqual(
151-
'asdgjdsag asdklgbasdghlad…, 3 months ago:c'
151+
'3 months ago • asdgjdsag asdklgbasdghlad… [c]'
152152
)
153153
})
154154
})
@@ -322,7 +322,7 @@ describe('getBlameDecorations()', () => {
322322
3,
323323
{ 'git.blame.showPreciseDate': false },
324324
SOURCEGRAPH as any
325-
).after!.contentText!.startsWith(
325+
).after!.contentText!.includes(
326326
`(${FIXTURE_HUNK_4.author.person.user!.username}) ${FIXTURE_HUNK_4.author.person.displayName}`
327327
)
328328
).toBe(true)
@@ -333,7 +333,7 @@ describe('getBlameDecorations()', () => {
333333
2,
334334
{ 'git.blame.showPreciseDate': false },
335335
SOURCEGRAPH as any
336-
).after!.contentText!.startsWith(`${FIXTURE_HUNK_3.author.person.displayName}`)
336+
).after!.contentText!.includes(`${FIXTURE_HUNK_3.author.person.displayName}`)
337337
).toBe(true)
338338
})
339339
})

src/blame.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const getDecorationFromHunk = (
101101
color: 'rgba(235, 235, 255, 0.55)',
102102
backgroundColor: 'rgba(15, 43, 89, 0.65)',
103103
},
104-
contentText: `${username}${displayName}, ${dateString}: • ${truncate(hunk.message, 45)}`,
104+
contentText: `${dateString}${username}${displayName} [${truncate(hunk.message, 45)}]`,
105105
hoverMessage,
106106
linkURL,
107107
},

src/extension.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ export interface Settings {
1010
['git.blame.lineDecorations']?: boolean
1111
['git.blame.decorateWholeFile']?: boolean
1212
['git.blame.showPreciseDate']?: boolean
13+
14+
experimentalFeatures?: {
15+
enableExtensionsDecorationsColumnView?: boolean
16+
}
1317
}
1418

15-
const decorationType = sourcegraph.app.createDecorationType && sourcegraph.app.createDecorationType()
19+
const isBlameForSelectedLinesEnabled = () =>
20+
!sourcegraph.configuration.get<Settings>().get('experimentalFeatures')?.enableExtensionsDecorationsColumnView ||
21+
sourcegraph.internal.clientApplication !== 'sourcegraph'
22+
23+
const decorationType =
24+
sourcegraph.app.createDecorationType && sourcegraph.app.createDecorationType({ display: 'column' })
1625

1726
const statusBarItemType = sourcegraph.app.createStatusBarItemType && sourcegraph.app.createStatusBarItemType()
1827

@@ -32,7 +41,7 @@ export function activate(context: sourcegraph.ExtensionContext): void {
3241
// When the configuration or current file changes, publish new decorations.
3342
context.subscriptions.add(
3443
combineLatest(configurationChanges, selectionChanges).subscribe(([, { editor, selections }]) =>
35-
decorate(editor, selections)
44+
decorate(editor, isBlameForSelectedLinesEnabled() ? selections : null)
3645
)
3746
)
3847
} else {

yarn.lock

+9-4
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,11 @@ grapheme-breaker@^0.3.2:
32593259
brfs "^1.2.0"
32603260
unicode-trie "^0.3.1"
32613261

3262+
graphql@^15.4.0:
3263+
version "15.8.0"
3264+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.8.0.tgz#33410e96b012fa3bdb1091cc99a94769db212b38"
3265+
integrity sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==
3266+
32623267
32633268
version "1.10.5"
32643269
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
@@ -6583,10 +6588,10 @@ source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6:
65836588
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
65846589
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
65856590

6586-
sourcegraph@^25.3.0:
6587-
version "25.3.0"
6588-
resolved "https://registry.yarnpkg.com/sourcegraph/-/sourcegraph-25.3.0.tgz#0ad58f40a6fb286ddaf5f441c28b2c1241098e94"
6589-
integrity sha512-677uVs3rq1gVeiKTZ6wrlq862dUIn02ZmEgxoPTfFMI3tlJWhdgFZOg2GpFEgFRoB1ct7rMMlRrI1cEQdB7Rkg==
6591+
sourcegraph@^25.6.0:
6592+
version "25.6.0"
6593+
resolved "https://registry.yarnpkg.com/sourcegraph/-/sourcegraph-25.6.0.tgz#fc23822a8e207e25ff9bfc217dad4a14bfbd1e84"
6594+
integrity sha512-BKe/hugALfgMyM38ecWpeFLtXvVklq++aUpGlm4Y3fY8/ufbUE/FAaYchF9qkidli8Usef5xnDRCKbAfsPRpWA==
65906595

65916596
spawn-wrap@^1.4.2:
65926597
version "1.4.2"

0 commit comments

Comments
 (0)