Skip to content

Commit d2d99c5

Browse files
committed
fix: use cache dirs from dirs create
1 parent 2682b89 commit d2d99c5

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

packages/core/src/shared/languageServer/lspResolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from 'path'
1010
import { FileType } from 'vscode'
1111
import AdmZip from 'adm-zip'
1212
import { TargetContent, logger, LspResult, LspVersion, Manifest } from './types'
13-
import { getApplicationSupportFolder } from '../vscode/env'
13+
import { getApplicationCacheFolder } from '../vscode/env'
1414
import { createHash } from '../crypto'
1515
import request from '../request'
1616

@@ -341,8 +341,8 @@ export class LanguageServerResolver {
341341
}
342342

343343
private defaultDownloadFolder() {
344-
const applicationSupportFolder = getApplicationSupportFolder()
345-
return path.join(applicationSupportFolder, `aws/toolkits/language-servers/${this.lsName}`)
344+
const applicationCacheFolder = getApplicationCacheFolder()
345+
return path.join(applicationCacheFolder, `aws/toolkits/language-servers/${this.lsName}`)
346346
}
347347

348348
getDownloadDirectory(version: string) {

packages/core/src/shared/vscode/env.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { ChildProcess } from '../utilities/processUtils'
1313
import globals, { isWeb } from '../extensionGlobals'
1414
import * as devConfig from '../../dev/config'
1515
import path from 'path'
16+
import { fs } from '../fs/fs'
17+
import { ToolkitError } from '../errors'
1618

1719
/**
1820
* Returns true if the current build is running on CI (build server).
@@ -272,16 +274,28 @@ export async function getMachineId(): Promise<string> {
272274
return (await proc.run()).stdout.trim() ?? 'unknown-host'
273275
}
274276

275-
export function getApplicationSupportFolder() {
277+
/**
278+
* Gets the application cache folder for the current platform
279+
*
280+
* Follows the cache_dir convention outlined in https://crates.io/crates/dirs
281+
*/
282+
export function getApplicationCacheFolder() {
283+
const homeDir = fs.getUserHomeDir()
276284
switch (process.platform) {
277285
case 'darwin': {
278-
return path.join(os.homedir(), 'Library/Application Support')
286+
return path.join(homeDir, 'Library/Caches')
279287
}
280288
case 'win32': {
281-
return process.env.APPDATA
289+
const localAppData = process.env.LOCALAPPDATA
290+
if (!localAppData) {
291+
throw new ToolkitError('LOCALAPPDATA environment variable not set', {
292+
code: 'LocalAppDataNotFound',
293+
})
294+
}
295+
return localAppData
282296
}
283297
case 'linux': {
284-
return process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache')
298+
return path.join(homeDir, '.cache')
285299
}
286300
default: {
287301
throw new Error(`Unsupported platform: ${process.platform}. Expected 'darwin', 'win32', or 'linux'.`)

0 commit comments

Comments
 (0)