Skip to content

Commit 5dd2e16

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 edd491d commit 5dd2e16

File tree

8 files changed

+503
-205
lines changed

8 files changed

+503
-205
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,16 @@ npx vsce package --no-dependencies
140140
```
141141

142142
This should generate a .vsix file which you can then import into VS Code (`Ctrl + Shift + P` + "install vsix").
143+
144+
## Vendored Dependencies
145+
146+
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).
147+
148+
To update those, proceed as follows:
149+
150+
```sh
151+
$ export VSCODE_TAG="1.88.1" # Adjust this to match desired version of VSCode.
152+
$ git remote add vscode "https://github.com/microsoft/vscode.git"
153+
$ git fetch --depth 1 vscode "$VSCODE_TAG"
154+
$ git show $(git ls-remote --refs --tags vscode "$VSCODE_TAG" | cut -d$'\t' -f1):extensions/git/src/api/git.ts > src/types/git.ts
155+
```

package.json

Lines changed: 3 additions & 0 deletions
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

Lines changed: 5 additions & 5 deletions
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 {
@@ -122,8 +122,8 @@ export function registerAllCommands(): void {
122122
registerVsCodeCmd(
123123
'radicle.openOriginalVersionOfPatchedFile',
124124
async (node: FilechangeNode | undefined) => {
125-
if (node?.oldVersionUrl) {
126-
await commands.executeCommand('vscode.open', Uri.file(node.oldVersionUrl))
125+
if (node?.oldVersionUri) {
126+
await commands.executeCommand('vscode.open', node.oldVersionUri)
127127
commands.executeCommand('workbench.action.files.setActiveEditorReadonlyInSession')
128128
} else {
129129
log(
@@ -137,8 +137,8 @@ export function registerAllCommands(): void {
137137
registerVsCodeCmd(
138138
'radicle.openChangedVersionOfPatchedFile',
139139
async (node: FilechangeNode | undefined) => {
140-
if (node?.newVersionUrl) {
141-
await commands.executeCommand('vscode.open', Uri.file(node.newVersionUrl))
140+
if (node?.newVersionUri) {
141+
await commands.executeCommand('vscode.open', node.newVersionUri)
142142
commands.executeCommand('workbench.action.files.setActiveEditorReadonlyInSession')
143143
} else {
144144
log(

0 commit comments

Comments
 (0)