Skip to content

Commit

Permalink
refactor(diff): use VSCode Git extension
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lorenzleutgeb committed Apr 30, 2024
1 parent a669d86 commit 6a91efa
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 205 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module.exports = {
'!.*rc.*',
'!*.config.js',
'!*.d.ts',

// Ignore, since this file is vendored from VSCode and should not be changed.
// See `CONTRIBUTING.md`.
'src/types/git.ts',
],
rules: {
/*
Expand Down
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,16 @@ If necessary, specific code shared between extension and webviews should be extr
### Getting user input

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.

## Vendored Dependencies

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).

To update those, proceed as follows:

```sh
$ export VSCODE_TAG="1.88.1" # Adjust this to match desired version of VSCode.
$ git remote add vscode "https://github.com/microsoft/vscode.git"
$ git fetch --depth 1 vscode "$VSCODE_TAG"
$ git show $(git ls-remote --refs --tags vscode "$VSCODE_TAG" | cut -d$'\t' -f1):extensions/git/src/api/git.ts > src/types/git.ts
```
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@
"ts-xor": "^1.3.0",
"typescript": "^5.3.3"
},
"extensionDependencies": [
"vscode.git"
],
"simple-git-hooks": {
"pre-commit": "npm run lint"
},
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type TextDocumentShowOptions, Uri, commands, window } from 'vscode'
import { type TextDocumentShowOptions, type Uri, commands, window } from 'vscode'
import { getExtensionContext, usePatchStore } from '../stores'
import { exec, log, showLog } from '../utils'
import {
Expand Down Expand Up @@ -116,8 +116,8 @@ export function registerAllCommands(): void {
registerVsCodeCmd(
'radicle.openOriginalVersionOfPatchedFile',
async (node: FilechangeNode | undefined) => {
if (node?.oldVersionUrl) {
await commands.executeCommand('vscode.open', Uri.file(node.oldVersionUrl))
if (node?.oldVersionUri) {
await commands.executeCommand('vscode.open', node.oldVersionUri)
commands.executeCommand('workbench.action.files.setActiveEditorReadonlyInSession')
} else {
log(
Expand All @@ -131,8 +131,8 @@ export function registerAllCommands(): void {
registerVsCodeCmd(
'radicle.openChangedVersionOfPatchedFile',
async (node: FilechangeNode | undefined) => {
if (node?.newVersionUrl) {
await commands.executeCommand('vscode.open', Uri.file(node.newVersionUrl))
if (node?.newVersionUri) {
await commands.executeCommand('vscode.open', node.newVersionUri)
commands.executeCommand('workbench.action.files.setActiveEditorReadonlyInSession')
} else {
log(
Expand Down
Loading

0 comments on commit 6a91efa

Please sign in to comment.