Skip to content

Commit

Permalink
refactor(diff): Don't create temporary files
Browse files Browse the repository at this point in the history
This reverts most of cytechmobile#123 and
instead takes a different approach to resolving
cytechmobile#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 c0216c4 commit 82b0f22
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 193 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.d.ts',
],
rules: {
/*
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
- use more subtle styling when a reaction involves the local radicle identity (italic text vs border & background)
- show "you" instead of local identity's alias
- on hover show the truncated DId next to each identity
- **settings:** add config to toggle excluding temporary files created by the extension, e.g. those used to produce the diff of a patch's changed files, from the list of recently opened files. This is enabled by default. This currently works only partly, but should automatically be fully working when [the underlying VS Code bug](https://github.com/microsoft/vscode/issues/157395#issuecomment-2080293320) is fixed. ([#94](https://github.com/cytechmobile/radicle-vscode-extension/issues/94))
- **patch-list:** show diff for copied and moved files of a patch too when available ([#100](https://github.com/cytechmobile/radicle-vscode-extension/issues/100))
- **patch-list:** show path to containing directory for each changed file of a patch ([#100](https://github.com/cytechmobile/radicle-vscode-extension/issues/100))
- **patch-list:** feat(patch-list): increase count of fetched patches per status to 500 ([#100](https://github.com/cytechmobile/radicle-vscode-extension/issues/100))
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.d.ts`](src/types/git.d.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.d.ts > src/types/git.d.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
4 changes: 0 additions & 4 deletions src/constants.ts

This file was deleted.

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
6 changes: 0 additions & 6 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface ExtensionConfig {
'radicle.advanced.pathToRadBinary': string
'radicle.advanced.pathToNodeHome': string
'radicle.advanced.httpApiEndpoint': string
'radicle.hideTempFiles': boolean
}

/**
Expand All @@ -33,10 +32,7 @@ export function getConfig<K extends keyof ExtensionConfig>(
case 'radicle.advanced.httpApiEndpoint':
// if the config has the value of the empty string (default) then return `undefined`
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
return config.get<ExtensionConfig[K]>(configKey)?.trim() || undefined
case 'radicle.hideTempFiles':
return config.get<ExtensionConfig[K]>(configKey)
default:
return assertUnreachable(configKey)
}
Expand All @@ -56,8 +52,6 @@ export function setConfig<K extends keyof ExtensionConfig>(
case 'radicle.advanced.pathToNodeHome':
case 'radicle.advanced.httpApiEndpoint':
return config.update(configKey, value, ConfigurationTarget.Global)
case 'radicle.hideTempFiles':
return config.update(configKey, value, ConfigurationTarget.Global)
default:
return assertUnreachable(configKey)
}
Expand Down
7 changes: 0 additions & 7 deletions src/helpers/configWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { workspace } from 'vscode'
import {
validateHideTempFilesConfigAlignment,
validateHttpdConnection,
validateRadCliInstallation,
validateRadicleIdentityAuthentication,
Expand Down Expand Up @@ -52,11 +51,6 @@ const configWatchers = [
usePatchStore().resetAllPatches()
},
},
{
configKey: 'radicle.hideTempFiles',
onConfigChange: validateHideTempFilesConfigAlignment,
onBeforeWatcherRegistration: validateHideTempFilesConfigAlignment,
},
] satisfies OnConfigChangeParam[]

/**
Expand All @@ -65,7 +59,6 @@ const configWatchers = [
*/
export function registerAllConfigWatchers(): void {
configWatchers.forEach((cw) => {
cw.onBeforeWatcherRegistration?.()
onConfigChange(cw.configKey, cw.onConfigChange)
})
}
Loading

0 comments on commit 82b0f22

Please sign in to comment.