Skip to content

Commit 5f71ff9

Browse files
committed
refactor(diff): use VSCode Git extension
This takes a different approach to resolving #94 Use the Git integration for Visual Studio Code (an extension that is bundled with VSCode and neither be disabled or uninstalled, thus can be effectively considered part of VSCode) to read files directly off of Git. Signed-off-by: Lorenz Leutgeb <[email protected]>
1 parent a669d86 commit 5f71ff9

File tree

8 files changed

+503
-205
lines changed

8 files changed

+503
-205
lines changed

.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ module.exports = {
2525
'!.*rc.*',
2626
'!*.config.js',
2727
'!*.d.ts',
28+
29+
// Ignore, since this file is vendored from VSCode and should not be changed.
30+
// See `CONTRIBUTING.md`.
31+
'src/types/git.ts',
2832
],
2933
rules: {
3034
/*

CONTRIBUTING.md

+13
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,16 @@ If necessary, specific code shared between extension and webviews should be extr
8989
### Getting user input
9090

9191
Use custom wrapper `askUser()` instead of the native [InputBox API](https://code.visualstudio.com/api/references/vscode-api#InputBox) which would result in procedural, verbose and brittle client code.
92+
93+
## Vendored Dependencies
94+
95+
Types for the [Git integration for VSCode](https://github.com/microsoft/vscode/tree/main/extensions/git) are vendored at [`src/types/git.ts`](src/types/git.ts).
96+
97+
To update those, proceed as follows:
98+
99+
```sh
100+
$ export VSCODE_TAG="1.88.1" # Adjust this to match desired version of VSCode.
101+
$ git remote add vscode "https://github.com/microsoft/vscode.git"
102+
$ git fetch --depth 1 vscode "$VSCODE_TAG"
103+
$ git show $(git ls-remote --refs --tags vscode "$VSCODE_TAG" | cut -d$'\t' -f1):extensions/git/src/api/git.ts > src/types/git.ts
104+
```

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@
506506
"ts-xor": "^1.3.0",
507507
"typescript": "^5.3.3"
508508
},
509+
"extensionDependencies": [
510+
"vscode.git"
511+
],
509512
"simple-git-hooks": {
510513
"pre-commit": "npm run lint"
511514
},

src/helpers/command.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type TextDocumentShowOptions, Uri, commands, window } from 'vscode'
1+
import { type TextDocumentShowOptions, type Uri, commands, window } from 'vscode'
22
import { getExtensionContext, usePatchStore } from '../stores'
33
import { exec, log, showLog } from '../utils'
44
import {
@@ -116,8 +116,8 @@ export function registerAllCommands(): void {
116116
registerVsCodeCmd(
117117
'radicle.openOriginalVersionOfPatchedFile',
118118
async (node: FilechangeNode | undefined) => {
119-
if (node?.oldVersionUrl) {
120-
await commands.executeCommand('vscode.open', Uri.file(node.oldVersionUrl))
119+
if (node?.oldVersionUri) {
120+
await commands.executeCommand('vscode.open', node.oldVersionUri)
121121
commands.executeCommand('workbench.action.files.setActiveEditorReadonlyInSession')
122122
} else {
123123
log(
@@ -131,8 +131,8 @@ export function registerAllCommands(): void {
131131
registerVsCodeCmd(
132132
'radicle.openChangedVersionOfPatchedFile',
133133
async (node: FilechangeNode | undefined) => {
134-
if (node?.newVersionUrl) {
135-
await commands.executeCommand('vscode.open', Uri.file(node.newVersionUrl))
134+
if (node?.newVersionUri) {
135+
await commands.executeCommand('vscode.open', node.newVersionUri)
136136
commands.executeCommand('workbench.action.files.setActiveEditorReadonlyInSession')
137137
} else {
138138
log(

0 commit comments

Comments
 (0)