Skip to content

Instantly share code, notes, and snippets.

@m87h
Created May 8, 2025 21:32
Show Gist options
  • Save m87h/b3c8447743d9edf7f7fba7a38bf29a56 to your computer and use it in GitHub Desktop.
Save m87h/b3c8447743d9edf7f7fba7a38bf29a56 to your computer and use it in GitHub Desktop.
vscode-defold-buddy-cache-dir.diff
diff --color -ur a/src/commands/initialize-project-command.ts b/src/commands/initialize-project-command.ts
--- a/src/commands/initialize-project-command.ts 2025-05-08 23:30:37
+++ b/src/commands/initialize-project-command.ts 2025-05-08 22:31:06
@@ -2,7 +2,7 @@
import * as vscode from 'vscode';
import { config } from '../config';
import { StateMemento } from '../persistence/state-memento';
-import { getWorkspacePath } from '../utils/common';
+import { getCachePath, getWorkspacePath } from '../utils/common';
import { LuaProjectInitializer } from '../utils/lua-project-initializer';
import { TealProjectInitializer } from '../utils/teal-project-initializer';
import { ZipArchiveManager } from '../utils/zip-archive-manager';
@@ -36,16 +36,16 @@
}
}
-async function downloadAnnotationsZipOrTakeFromCache(context: vscode.ExtensionContext, userSettings: ISettingsPickedByUser): Promise<vscode.Uri> {
- let cachedAnnotationsZip = await getAlreadyDownloadedAnnotationsFromCache(context, userSettings);
+async function downloadAnnotationsZipOrTakeFromCache(userSettings: ISettingsPickedByUser): Promise<vscode.Uri> {
+ let cachedAnnotationsZip = await getAlreadyDownloadedAnnotationsFromCache(userSettings);
if (!cachedAnnotationsZip) {
- cachedAnnotationsZip = await downloadApiAnnotations(context, userSettings);
+ cachedAnnotationsZip = await downloadApiAnnotations(userSettings);
}
return cachedAnnotationsZip;
}
-async function setupCurrentDefoldProjectForLua(context: vscode.ExtensionContext, userSettings: ISettingsPickedByUser) {
- const annotationsZip = await downloadAnnotationsZipOrTakeFromCache(context, {
+async function setupCurrentDefoldProjectForLua(userSettings: ISettingsPickedByUser) {
+ const annotationsZip = await downloadAnnotationsZipOrTakeFromCache({
...userSettings,
language: 'lua',
});
@@ -56,7 +56,7 @@
}
async function setupCurrentDefoldProjectForTeal(context: vscode.ExtensionContext, userSettings: ISettingsPickedByUser) {
- const annotationsZip = await downloadAnnotationsZipOrTakeFromCache(context, {
+ const annotationsZip = await downloadAnnotationsZipOrTakeFromCache({
...userSettings,
language: 'teal',
});
@@ -126,8 +126,8 @@
} || undefined;
}
-async function getAlreadyDownloadedAnnotationsFromCache(context: vscode.ExtensionContext, userSettings: ISettingsPickedByUser): Promise<vscode.Uri | undefined> {
- const archiveUri = getZipCachePath(context, userSettings);
+async function getAlreadyDownloadedAnnotationsFromCache(userSettings: ISettingsPickedByUser): Promise<vscode.Uri | undefined> {
+ const archiveUri = getZipCachePath(userSettings);
try {
const stats = await vscode.workspace.fs.stat(archiveUri);
return stats.type === vscode.FileType.File
@@ -138,10 +138,10 @@
}
}
-async function downloadApiAnnotations(context: vscode.ExtensionContext, userSettings: ISettingsPickedByUser): Promise<vscode.Uri> {
+async function downloadApiAnnotations(userSettings: ISettingsPickedByUser): Promise<vscode.Uri> {
const response = await axios.get(getDownloadUrl(userSettings), { responseType: 'arraybuffer' });
if (response.status === 200 && response.data) {
- const archiveUri = getZipCachePath(context, userSettings);
+ const archiveUri = getZipCachePath(userSettings);
try { await vscode.workspace.fs.delete(archiveUri, { useTrash: false }); } catch {}
await vscode.workspace.fs.writeFile(archiveUri, response.data);
return archiveUri;
@@ -170,10 +170,10 @@
async function initializeCurrentProject(userSettings: ISettingsPickedByUser, context: vscode.ExtensionContext) {
switch (userSettings.language) {
case 'lua':
- await setupCurrentDefoldProjectForLua(context, userSettings);
+ await setupCurrentDefoldProjectForLua(userSettings);
break;
case 'teal':
- await setupCurrentDefoldProjectForLua(context, userSettings);
+ await setupCurrentDefoldProjectForLua(userSettings);
await setupCurrentDefoldProjectForTeal(context, userSettings);
break;
default:
@@ -211,12 +211,12 @@
}
}
-function getZipCachePath(context: vscode.ExtensionContext, userSettings: ISettingsPickedByUser) {
+function getZipCachePath(userSettings: ISettingsPickedByUser) {
switch (userSettings.language) {
case 'lua':
- return vscode.Uri.joinPath(context.extensionUri, 'cache', 'api', `${userSettings.version}.zip`);
+ return vscode.Uri.joinPath(getCachePath(), 'api', `${userSettings.version}.zip`);
case 'teal':
- return vscode.Uri.joinPath(context.extensionUri, 'cache', 'api', `${userSettings.version}-teal.zip`);
+ return vscode.Uri.joinPath(getCachePath(), 'api', `${userSettings.version}-teal.zip`);
default:
throw new Error(`Support for ${userSettings.language} is not implemented yet`);
}
diff --color -ur a/src/utils/common.ts b/src/utils/common.ts
--- a/src/utils/common.ts 2025-05-08 23:30:37
+++ b/src/utils/common.ts 2025-05-08 22:26:51
@@ -1,4 +1,22 @@
import * as vscode from 'vscode';
+import * as os from 'os';
+import * as path from 'path';
+
+export function getCachePath(): vscode.Uri {
+ let base: vscode.Uri;
+ switch (os.platform()) {
+ case 'win32':
+ base = vscode.Uri.file(process.env.LOCALAPPDATA ?? path.join(os.homedir(), '.cache'));
+ break;
+ case 'darwin':
+ base = vscode.Uri.file(path.join(os.homedir(), 'Library', 'Caches'));
+ break;
+ default:
+ base = vscode.Uri.file(process.env.XDG_CACHE_HOME ?? path.join(os.homedir(), '.cache'));
+ }
+
+ return vscode.Uri.joinPath(base, 'vscode-defold-buddy');
+}
export function getWorkspacePath(folder: string): vscode.Uri | undefined {
if (!vscode.workspace.workspaceFolders?.length) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment