Skip to content

Commit 6645ab3

Browse files
committed
[ change ] Change version switching UI "Clear cache" to "Delete Downloads"
1 parent c1d055d commit 6645ab3

File tree

7 files changed

+292
-22
lines changed

7 files changed

+292
-22
lines changed

lib/js/src/FS.bs.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/src/State/State__SwitchVersion.bs.js

Lines changed: 18 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/test/tests/Test__FS.bs.js

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/FS.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ let delete = async (uri: VSCode.Uri.t): result<unit, string> => {
3131
}
3232
}
3333

34+
let deleteRecursive = async (uri: VSCode.Uri.t): result<unit, string> => {
35+
try {
36+
await VSCode.Workspace.fs->VSCode.FileSystem.delete(uri, ~options={"recursive": true, "useTrash": false})
37+
Ok()
38+
} catch {
39+
| Js.Exn.Error(obj) => Error(Js.Exn.message(obj)->Option.getOr("Unknown file system error"))
40+
| _ => Error("Unknown file system error")
41+
}
42+
}
43+
3444
let isWritableFileSystem = (uri: VSCode.Uri.t): result<bool, string> => {
3545
try {
3646
let isWritable =

src/State/State__SwitchVersion.res

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Constants = {
44
let alsWithSquirrel = "$(squirrel) ALS v"
55
let downloadLatestALS = "$(cloud-download) Download the latest Agda Language Server"
66
let openDownloadFolder = "$(folder-opened) Open download folder"
7-
let clearCache = "$(trash) Clear cache"
7+
let deleteDownloads = "$(trash) Delete downloads"
88
let downloadedAndInstalled = "Downloaded and installed"
99
let otherDownloads = "$(chevron-right) Other Downloads"
1010
let otherDownloadsDesc = "Browse other versions available for download"
@@ -17,7 +17,7 @@ module ItemData = {
1717
| DownloadAction(bool, string, string) // downloaded, versionString, downloadType
1818
| OtherVersionsSubmenu // submenu button for other versions downloads
1919
| OpenFolder(string) // folderPath
20-
| ClearCache // clear release cache
20+
| DeleteDownloads // delete downloads and clear cache
2121
| NoInstallations
2222
| Separator(string) // label
2323

@@ -41,7 +41,7 @@ module ItemData = {
4141
downloadType
4242
| OtherVersionsSubmenu => "OtherVersionsSubmenu"
4343
| OpenFolder(folderPath) => "OpenFolder: " ++ folderPath
44-
| ClearCache => "ClearCache"
44+
| DeleteDownloads => "DeleteDownloads"
4545
| NoInstallations => "NoInstallations"
4646
| Separator(label) => "Separator: " ++ label
4747
}
@@ -141,7 +141,7 @@ module ItemData = {
141141
}
142142

143143
// Add misc section
144-
Array.concat(sectionsWithDownload, [Separator("Misc"), OpenFolder(folderPath), ClearCache])
144+
Array.concat(sectionsWithDownload, [Separator("Misc"), OpenFolder(folderPath), DeleteDownloads])
145145
}
146146
}
147147

@@ -193,9 +193,9 @@ module Item = {
193193
let description = "Where the language servers are downloaded to"
194194
(label, Some(description), Some(folderPath))
195195
}
196-
| ClearCache => {
197-
let label = Constants.clearCache
198-
let description = "Clear all cached data"
196+
| DeleteDownloads => {
197+
let label = Constants.deleteDownloads
198+
let description = "Delete all downloaded files and clear cached release metadata"
199199
(label, Some(description), None)
200200
}
201201
| NoInstallations => {
@@ -872,13 +872,21 @@ module Handler = {
872872
module PlatformOps = unpack(platformDeps)
873873
await PlatformOps.openFolder(globalStorageUriAsFile)
874874
state.channels.log->Chan.emit(Log.SwitchVersionUI(SelectionCompleted))
875-
} else if selectedItem.label == Constants.clearCache {
875+
} else if selectedItem.label == Constants.deleteDownloads {
876+
// Delete download directories recursively
877+
let deleteDir = async dirName => {
878+
let uri = VSCode.Uri.joinPath(state.globalStorageUri, [dirName])
879+
let _ = await FS.deleteRecursive(uri)
880+
}
881+
await deleteDir("dev-wasm-als")
882+
await deleteDir("dev-als")
883+
await deleteDir("latest-als")
876884
// Clear cache for all repositories
877885
await Memento.ALSReleaseCache.clear(state.memento, "agda", "agda-language-server")
878886
await Memento.ALSReleaseCache.clear(state.memento, "banacorn", "agda-language-server")
879887
await Memento.PickedConnection.clear(state.memento)
880888
await Memento.Endpoints.clear(state.memento)
881-
let _ = await VSCode.Window.showInformationMessage("Cache cleared", [])
889+
let _ = await VSCode.Window.showInformationMessage("All downloads and cache deleted", [])
882890
state.channels.log->Chan.emit(Log.SwitchVersionUI(SelectionCompleted))
883891
} else if selectedItem.label == Constants.downloadLatestALS {
884892
// Handle latest ALS download

0 commit comments

Comments
 (0)