File tree 2 files changed +18
-23
lines changed
2 files changed +18
-23
lines changed Original file line number Diff line number Diff line change 1
- import type { GitExtensionAPI } from '../types'
1
+ import * as vscode from 'vscode'
2
+ import type { GitExtension , GitExtensionAPI } from '../types'
2
3
import { exec } from '.'
3
4
4
5
/**
@@ -36,14 +37,13 @@ export function getCurrentGitBranch(): string | undefined {
36
37
return currentBranch
37
38
}
38
39
39
- // TODO(lorenzleutgeb): Get some typings for vscode!
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- declare const vscode : any
42
-
43
40
export function getGitExtensionAPI ( ) : GitExtensionAPI {
44
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
45
- const gitExtension = vscode . extensions . getExtension ( 'vscode.git' ) . exports
41
+ const gitExtensionId = 'vscode.git'
42
+ const gitExtension = vscode . extensions . getExtension < GitExtension > ( gitExtensionId )
43
+
44
+ if ( gitExtension === undefined ) {
45
+ throw new Error ( `Could not load VSCode Git extension with id '${ gitExtensionId } '` )
46
+ }
46
47
47
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
48
- return gitExtension . getAPI ( 1 ) as GitExtensionAPI
48
+ return gitExtension . exports . getAPI ( 1 )
49
49
}
Original file line number Diff line number Diff line change @@ -16,11 +16,18 @@ import {
16
16
fetchFromHttpd ,
17
17
memoizedGetCurrentProjectId ,
18
18
} from '../helpers'
19
- import { type AugmentedPatch , type Patch , type Unarray , isPatch } from '../types'
19
+ import {
20
+ type AugmentedPatch ,
21
+ type GitExtensionAPI ,
22
+ type Patch ,
23
+ type Unarray ,
24
+ isPatch ,
25
+ } from '../types'
20
26
import {
21
27
assertUnreachable ,
22
28
capitalizeFirstLetter ,
23
29
getFirstAndLatestRevisions ,
30
+ getGitExtensionAPI ,
24
31
getIdentityAliasOrId ,
25
32
getRepoRoot ,
26
33
getTimeAgo ,
@@ -161,21 +168,9 @@ export const patchesTreeDataProvider: TreeDataProvider<
161
168
const filename = Path . basename ( filePath )
162
169
const absPath = `${ getRepoRoot ( ) } ${ sep } ${ filePath } `
163
170
164
- /*
165
- TODO(lorenzleutgeb): Instead of constructing GitUris ourselves, use API of Git Extension.
166
171
const gitExtensionApi : GitExtensionAPI = getGitExtensionAPI ( )
167
- const mkUri = (ref: string) => gitExtensionApi.toGitUri(Uri.from({ scheme: 'file', path: absPath }), ref);
168
- */
169
-
170
172
const mkUri = ( ref : string ) =>
171
- Uri . from ( {
172
- scheme : 'git' ,
173
- path : absPath ,
174
- query : JSON . stringify ( {
175
- path : absPath ,
176
- ref,
177
- } ) ,
178
- } )
173
+ gitExtensionApi . toGitUri ( Uri . from ( { scheme : 'file' , path : absPath } ) , ref )
179
174
180
175
const oldVersionUri = mkUri ( oldVersionCommitSha )
181
176
const newVersionUri = mkUri ( newVersionCommitSha )
You can’t perform that action at this time.
0 commit comments