Skip to content

Commit fe28634

Browse files
committed
feat(settings): hide temp files used in diff from recently opened list
Signed-off-by: Konstantinos Maninakis <[email protected]>
1 parent cff5cfc commit fe28634

File tree

8 files changed

+103
-36
lines changed

8 files changed

+103
-36
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"repo",
1515
"ts",
1616
"log",
17-
"config",
17+
"settings",
1818
"scm",
1919
"onboarding",
2020
"publish",

CHANGELOG.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- use more subtle styling when a reaction involves the local radicle identity (italic text vs border & background)
99
- show "you" instead of local identity's alias
1010
- on hover show the truncated DId next to each identity
11+
- **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))
1112
- **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))
1213
- **patch-list:** show path to containing directory for each changed file of a patch ([#100](https://github.com/cytechmobile/radicle-vscode-extension/issues/100))
1314
- **patch-list:** feat(patch-list): increase count of fetched patches per status to 500 ([#100](https://github.com/cytechmobile/radicle-vscode-extension/issues/100))
@@ -35,7 +36,7 @@
3536
- update readme links and marketplace metadata to point to Radicle instead of GitHub ([#113](https://github.com/cytechmobile/radicle-vscode-extension/pull/113))
3637
- **readme:** add badges showcasing current published version, installation count & repository identifier (RID) of the extension ([#113](https://github.com/cytechmobile/radicle-vscode-extension/pull/113))
3738
- **contributing:** suggest `rad clone` instead of git clone from GitHub ([#113](https://github.com/cytechmobile/radicle-vscode-extension/pull/113))
38-
- **contributing:** major improvement with new sections referencing zulip, creating a Radicle Issue and more
39+
- **contributing:** major improvement with new sections referencing zulip, creating a Radicle Issue and more ([#122](https://github.com/cytechmobile/radicle-vscode-extension/issues/122))
3940

4041
-----
4142

@@ -412,26 +413,26 @@
412413
- **auth:** securely store passphrase after successful user input and autotomatically re-use next time (if available) ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
413414
- **commands:** new VS Code command to de-authenticate / re-lock the currently used Radicle identity and remove the associated passphrase from Secret Storage ([#33](https://github.com/cytechmobile/radicle-vscode-extension/issues/33))
414415
- **log:** indicate in logs and notifications if an identity was pre-unlocked, got auto-unlocked using stored passphrase, got unlocked with user provided passphrase, or got created anew ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
415-
- **config:** new `pathToNodeHome` setting, which sets the `RAD_HOME` env variable ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
416-
- **config:** new `httpApiEndpoint` setting, useful when reverse-proxies are running in front of `radicle-httpd` etc ([#26](https://github.com/cytechmobile/radicle-vscode-extension/issues/26))
416+
- **settings:** new `pathToNodeHome` setting, which sets the `RAD_HOME` env variable ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
417+
- **settings:** new `httpApiEndpoint` setting, useful when reverse-proxies are running in front of `radicle-httpd` etc ([#26](https://github.com/cytechmobile/radicle-vscode-extension/issues/26))
417418
- **commands:** new VS Code command to clone a Radicle project from a filterable list of all seeded ones ([#27](https://github.com/cytechmobile/radicle-vscode-extension/issues/27))
418419
- **commands:** show rad clone command in the native Source Control three-dot-menu's Radicle submenu ([#27](https://github.com/cytechmobile/radicle-vscode-extension/issues/27))
419420
- **onboarding:** when opening VS Code without any folder in the workspace show in the dedicated Welcome View an additional button to clone from Radicle ([#27](https://github.com/cytechmobile/radicle-vscode-extension/issues/27))
420-
- **config:** set default value for existing config `pathToRadBinary` ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
421+
- **settings:** set default value for existing config `pathToRadBinary` ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
421422
- **log:** log auth status on extension init as well as on `pathToCliBinary` and `pathToNodeHome` configs' change ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
422423

423424
### 🩹 Fixes
424425

425-
- **config:** use previously ignored config `pathToCliBinary` to resolve Radicle CLI before executing commands ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
426+
- **settings:** use previously ignored config `pathToCliBinary` to resolve Radicle CLI before executing commands ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
426427
- **log:** don't log `body` param if it is empty string
427428
- **log:** escalate user notification shown when Radicle CLI is not resolved from warning to error ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
428429

429430
### 💅 Refactors
430431

431432
- **store:** create new global store for extension context and replace func param drilling with new getter ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
432433
- **exec:** completely rewrite foundational logic for shell script execution to be simpler, more powerful and result in cleaner client code ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
433-
- **config:** use new typesafe getter and setter for accessing VS Code configuration options ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
434-
- **config:** rename config `pathToBinary` -> `pathToCliBinary` ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
434+
- **settings:** use new typesafe getter and setter for accessing VS Code configuration options ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
435+
- **settings:** rename config `pathToBinary` -> `pathToCliBinary` ([#28](https://github.com/cytechmobile/radicle-vscode-extension/issues/28))
435436
- **repo:** move functions out of overgrown `utils` directory and into new `helpers` and `ux` directories ([#34](https://github.com/cytechmobile/radicle-vscode-extension/issues/34))
436437
- **repo:** add readme files documenting the intended contents of `utils`, `helpers` and `ux` directories ([8da729e](https://github.com/cytechmobile/radicle-vscode-extension/commit/8da729ee16726484859cf4c56592c7d7189699f8))
437438

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,30 +444,30 @@
444444
],
445445
"configuration": [
446446
{
447-
"title": "Radicle",
448447
"properties": {
449-
"radicle.advanced.pathToRadBinary": {
450-
"scope": "machine-overridable",
451-
"type": "string",
452-
"default": "",
453-
"markdownDescription": "Specifies the path to the Radicle CLI binary stored on your machine. \n\nLeave empty to use the default path or if command `rad` is already globally available in your shell."
448+
"radicle.hideTempFiles": {
449+
"scope": "application",
450+
"type": "boolean",
451+
"default": "true",
452+
"description": "Exclude temporary files generated by the extension (e.g. old/new versions of files changed in patches) from being listed among the recently opened or in search."
454453
}
455454
}
456455
},
457456
{
458-
"title": "Radicle",
457+
"title": "Advanced",
459458
"properties": {
459+
"radicle.advanced.pathToRadBinary": {
460+
"scope": "machine-overridable",
461+
"type": "string",
462+
"default": "",
463+
"markdownDescription": "Specifies the path to the Radicle CLI binary stored on your machine. \n\nLeave empty to use the default path or if command `rad` is already globally available in your shell."
464+
},
460465
"radicle.advanced.pathToNodeHome": {
461466
"scope": "machine-overridable",
462467
"type": "string",
463468
"default": "",
464469
"markdownDescription": "Specifies the path to the Radicle node's home directory. \n\nLeave empty to use the default path or if environment variable `RAD_HOME` is already globally available in your shell."
465-
}
466-
}
467-
},
468-
{
469-
"title": "Radicle",
470-
"properties": {
470+
},
471471
"radicle.advanced.httpApiEndpoint": {
472472
"scope": "machine-overridable",
473473
"type": "string",

src/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { sep } from 'node:path'
2+
import { tmpdir } from 'node:os'
3+
4+
export const extTempDir = `${tmpdir()}${sep}radicle`

src/helpers/config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface ExtensionConfig {
1313
'radicle.advanced.pathToRadBinary': string
1414
'radicle.advanced.pathToNodeHome': string
1515
'radicle.advanced.httpApiEndpoint': string
16+
'radicle.hideTempFiles': boolean
1617
}
1718

1819
/**
@@ -23,15 +24,19 @@ export interface ExtensionConfig {
2324
*/
2425
export function getConfig<K extends keyof ExtensionConfig>(
2526
configKey: K,
26-
): ExtensionConfig[typeof configKey] | undefined {
27+
): ExtensionConfig[K] | undefined {
2728
const config = workspace.getConfiguration()
2829

2930
switch (configKey) {
3031
case 'radicle.advanced.pathToRadBinary':
3132
case 'radicle.advanced.pathToNodeHome':
3233
case 'radicle.advanced.httpApiEndpoint':
3334
// if the config has the value of the empty string (default) then return `undefined`
34-
return config.get<ExtensionConfig[typeof configKey]>(configKey)?.trim() || undefined
35+
// @ts-expect-error
36+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
37+
return config.get<ExtensionConfig[K]>(configKey)?.trim() || undefined
38+
case 'radicle.hideTempFiles':
39+
return config.get<ExtensionConfig[K]>(configKey)
3540
default:
3641
return assertUnreachable(configKey)
3742
}
@@ -42,7 +47,7 @@ export function getConfig<K extends keyof ExtensionConfig>(
4247
*/
4348
export function setConfig<K extends keyof ExtensionConfig>(
4449
configKey: K,
45-
value: ExtensionConfig[typeof configKey],
50+
value: ExtensionConfig[K],
4651
): Thenable<void> {
4752
const config = workspace.getConfiguration()
4853

@@ -51,6 +56,8 @@ export function setConfig<K extends keyof ExtensionConfig>(
5156
case 'radicle.advanced.pathToNodeHome':
5257
case 'radicle.advanced.httpApiEndpoint':
5358
return config.update(configKey, value, ConfigurationTarget.Global)
59+
case 'radicle.hideTempFiles':
60+
return config.update(configKey, value, ConfigurationTarget.Global)
5461
default:
5562
return assertUnreachable(configKey)
5663
}

src/helpers/configWatcher.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { workspace } from 'vscode'
22
import {
3+
validateHideTempFilesConfigAlignment,
34
validateHttpdConnection,
45
validateRadCliInstallation,
56
validateRadicleIdentityAuthentication,
@@ -22,34 +23,40 @@ function onConfigChange(
2223

2324
interface OnConfigChangeParam {
2425
configKey: Parameters<typeof onConfigChange>['0']
25-
onChangeCallback: Parameters<typeof onConfigChange>['1']
26+
onConfigChange: Parameters<typeof onConfigChange>['1']
27+
onBeforeWatcherRegistration?: () => void
2628
}
2729

2830
// TODO: maninak instead of calling stuff directly to change, onChange set the values in a new configStore and have other things depend on it
2931
const configWatchers = [
3032
{
3133
configKey: 'radicle.advanced.pathToRadBinary',
32-
onChangeCallback: () => {
34+
onConfigChange: () => {
3335
validateRadCliInstallation()
3436
validateRadicleIdentityAuthentication({ minimizeUserNotifications: true })
3537
},
3638
},
3739
{
3840
configKey: 'radicle.advanced.pathToNodeHome',
39-
onChangeCallback: () => {
41+
onConfigChange: () => {
4042
// no need to notify since we check AND notify on rad command execution
4143
validateRadicleIdentityAuthentication({ minimizeUserNotifications: true })
4244
usePatchStore().resetAllPatches()
4345
},
4446
},
4547
{
4648
configKey: 'radicle.advanced.httpApiEndpoint',
47-
onChangeCallback: () => {
49+
onConfigChange: () => {
4850
resetHttpdConnection()
4951
validateHttpdConnection()
5052
usePatchStore().resetAllPatches()
5153
},
5254
},
55+
{
56+
configKey: 'radicle.hideTempFiles',
57+
onConfigChange: validateHideTempFilesConfigAlignment,
58+
onBeforeWatcherRegistration: validateHideTempFilesConfigAlignment,
59+
},
5360
] satisfies OnConfigChangeParam[]
5461

5562
/**
@@ -58,6 +65,7 @@ const configWatchers = [
5865
*/
5966
export function registerAllConfigWatchers(): void {
6067
configWatchers.forEach((cw) => {
61-
onConfigChange(cw.configKey, cw.onChangeCallback)
68+
cw.onBeforeWatcherRegistration?.()
69+
onConfigChange(cw.configKey, cw.onConfigChange)
6270
})
6371
}

src/ux/patchesView.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Path, { sep } from 'node:path'
2-
import { tmpdir } from 'node:os'
32
import * as fs from 'node:fs/promises'
43
import {
54
EventEmitter,
@@ -12,6 +11,7 @@ import {
1211
TreeItemCollapsibleState,
1312
Uri,
1413
} from 'vscode'
14+
import { extTempDir } from '../constants'
1515
import { usePatchStore } from '../stores'
1616
import {
1717
debouncedClearMemoizedGetCurrentProjectIdCache,
@@ -155,8 +155,7 @@ export const patchesTreeDataProvider: TreeDataProvider<
155155
}
156156

157157
// create a placeholder empty file used to diff added or removed files
158-
const tempFileUrlPrefix = `${tmpdir()}${sep}radicle`
159-
const emptyFileUrl = `${tempFileUrlPrefix}${sep}empty`
158+
const emptyFileUrl = `${extTempDir}${sep}empty`
160159

161160
try {
162161
await fs.mkdir(Path.dirname(emptyFileUrl), { recursive: true })
@@ -178,11 +177,11 @@ export const patchesTreeDataProvider: TreeDataProvider<
178177
const fileDir = Path.dirname(filePath)
179178
const filename = Path.basename(filePath)
180179

181-
const oldVersionUrl = `${tempFileUrlPrefix}${sep}${shortenHash(
180+
const oldVersionUrl = `${extTempDir}${sep}${shortenHash(
182181
oldVersionCommitSha,
183182
)}${sep}${fileDir}${sep}${filename}`
184183
// TODO: should the newVersionUrl be just the filechange.path (with full path to the actual file on the fs) if the current git commit is same as newVersionCommitSha and the file isn't on the git (un-)staged changes?
185-
const newVersionUrl = `${tempFileUrlPrefix}${sep}${shortenHash(
184+
const newVersionUrl = `${extTempDir}${sep}${shortenHash(
186185
newVersionCommitSha,
187186
)}${sep}${fileDir}${sep}${filename}`
188187

src/ux/settings.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { commands, workspace } from 'vscode'
2-
import type { getConfig } from '../helpers'
1+
import { sep } from 'node:path'
2+
import { ConfigurationTarget, commands, workspace } from 'vscode'
3+
import { extTempDir } from '../constants'
4+
import { getConfig } from '../helpers'
5+
import { log } from '../utils'
36

47
/**
58
* Opens the Settings UI with the options filtered to show only the specified config
@@ -16,3 +19,48 @@ export function openSettingsFocusedAtConfig(config: Parameters<typeof getConfig>
1619
config,
1720
)
1821
}
22+
23+
/**
24+
* Checks extension config for user's desired behaviour and ensure's the
25+
* native vscode config is set to match.
26+
*/
27+
export function validateHideTempFilesConfigAlignment() {
28+
const excludeGlob = `${extTempDir}${sep}**`
29+
30+
const shouldExclude = getConfig('radicle.hideTempFiles')
31+
32+
const searchExcludeConfigKey = 'search.exclude'
33+
const searchExcludeConfig = workspace.getConfiguration().get<object>(searchExcludeConfigKey)
34+
35+
if (!searchExcludeConfig) {
36+
log(
37+
`Didn't find any configuration for key "${searchExcludeConfigKey}". Bailing validation of config alignment.`,
38+
'warn',
39+
)
40+
41+
return
42+
}
43+
44+
const isAlreadyConfigedToExclude = Boolean(
45+
Object.entries(searchExcludeConfig).find(
46+
([key, value]) => key === excludeGlob && value === true,
47+
),
48+
)
49+
50+
if (shouldExclude && !isAlreadyConfigedToExclude) {
51+
const newSearchExcludeConfig = { ...searchExcludeConfig, [excludeGlob]: true }
52+
workspace
53+
.getConfiguration()
54+
.update(searchExcludeConfigKey, newSearchExcludeConfig, ConfigurationTarget.Global)
55+
} else if (!shouldExclude && isAlreadyConfigedToExclude) {
56+
// @ts-expect-error Type '{}' has no matching index signature for type 'string'.
57+
const { [excludeGlob]: _, ...searchExcludeConfigWithoutExcludeGlob } = searchExcludeConfig
58+
workspace
59+
.getConfiguration()
60+
.update(
61+
searchExcludeConfigKey,
62+
searchExcludeConfigWithoutExcludeGlob,
63+
ConfigurationTarget.Global,
64+
)
65+
}
66+
}

0 commit comments

Comments
 (0)