@@ -127,16 +127,24 @@ export const getAllBlameDecorations = (
127
127
) => hunks . map ( hunk => getDecorationFromHunk ( hunk , now , hunk . startLine - 1 , settings , sourcegraph ) )
128
128
129
129
export const queryBlameHunks = memoizeAsync (
130
- async ( { uri, sourcegraph } : { uri : string ; sourcegraph : typeof import ( 'sourcegraph' ) } ) : Promise < Hunk [ ] > => {
130
+ async ( {
131
+ uri,
132
+ sourcegraph,
133
+ selections,
134
+ } : {
135
+ uri : string
136
+ sourcegraph : typeof import ( 'sourcegraph' )
137
+ selections : Selection [ ] | null
138
+ } ) : Promise < Hunk [ ] > => {
131
139
const { repo, rev, path } = resolveURI ( uri )
132
140
const { data, errors } = await sourcegraph . commands . executeCommand (
133
141
'queryGraphQL' ,
134
142
gql `
135
- query GitBlame($repo: String!, $rev: String!, $path: String!) {
143
+ query GitBlame($repo: String!, $rev: String!, $path: String!, $startLine: Int!, $endLine: Int! ) {
136
144
repository(name: $repo) {
137
145
commit(rev: $rev) {
138
146
blob(path: $path) {
139
- blame(startLine: 0 , endLine: 0 ) {
147
+ blame(startLine: $startLine , endLine: $endLine ) {
140
148
startLine
141
149
endLine
142
150
author {
@@ -160,7 +168,13 @@ export const queryBlameHunks = memoizeAsync(
160
168
}
161
169
}
162
170
` ,
163
- { repo, rev, path }
171
+ {
172
+ repo,
173
+ rev,
174
+ path,
175
+ startLine : selections ? selections [ 0 ] . start . line + 1 : 0 ,
176
+ endLine : selections ? selections [ 0 ] . end . line + 1 : 0 ,
177
+ }
164
178
)
165
179
if ( errors && errors . length > 0 ) {
166
180
throw new Error ( errors . join ( '\n' ) )
@@ -170,7 +184,12 @@ export const queryBlameHunks = memoizeAsync(
170
184
}
171
185
return data . repository . commit . blob . blame
172
186
} ,
173
- ( { uri } ) => uri
187
+ ( { uri, selections } ) => {
188
+ if ( selections ) {
189
+ return [ uri , selections [ 0 ] . start . line , selections [ 0 ] . end . line ] . join ( ':' )
190
+ }
191
+ return uri
192
+ }
174
193
)
175
194
176
195
/**
0 commit comments