Skip to content

Commit 4e41dc5

Browse files
committed
chore(deps): Load and use vscode.git extension
Signed-off-by: Lorenz Leutgeb <[email protected]>
1 parent 31d9205 commit 4e41dc5

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/utils/git.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { GitExtensionAPI } from '../types'
1+
import * as vscode from 'vscode'
2+
import type { GitExtension, GitExtensionAPI } from '../types'
23
import { exec } from '.'
34

45
/**
@@ -36,14 +37,13 @@ export function getCurrentGitBranch(): string | undefined {
3637
return currentBranch
3738
}
3839

39-
// TODO(lorenzleutgeb): Get some typings for vscode!
40-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
41-
declare const vscode: any
42-
4340
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+
}
4647

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)
4949
}

src/ux/patchesView.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ import {
1616
fetchFromHttpd,
1717
memoizedGetCurrentProjectId,
1818
} 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'
2026
import {
2127
assertUnreachable,
2228
capitalizeFirstLetter,
2329
getFirstAndLatestRevisions,
30+
getGitExtensionAPI,
2431
getIdentityAliasOrId,
2532
getRepoRoot,
2633
getTimeAgo,
@@ -161,21 +168,9 @@ export const patchesTreeDataProvider: TreeDataProvider<
161168
const filename = Path.basename(filePath)
162169
const absPath = `${getRepoRoot()}${sep}${filePath}`
163170

164-
/*
165-
TODO(lorenzleutgeb): Instead of constructing GitUris ourselves, use API of Git Extension.
166171
const gitExtensionApi: GitExtensionAPI = getGitExtensionAPI()
167-
const mkUri = (ref: string) => gitExtensionApi.toGitUri(Uri.from({ scheme: 'file', path: absPath }), ref);
168-
*/
169-
170172
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)
179174

180175
const oldVersionUri = mkUri(oldVersionCommitSha)
181176
const newVersionUri = mkUri(newVersionCommitSha)

0 commit comments

Comments
 (0)