Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion packages/core/src/shared/fs/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
isPermissionsError,
scrubNames,
} from '../errors'
import globals from '../extensionGlobals'
import globals, { isWeb } from '../extensionGlobals'
import { isWin } from '../vscode/env'
import { resolvePath } from '../utilities/pathUtils'
import crypto from 'crypto'
Expand Down Expand Up @@ -543,6 +543,43 @@ export class FileSystem {
return this.#homeDir
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like that this is in a shared module now.

* Gets the application cache folder for the current platform
*
* Follows the cache_dir convention outlined in https://crates.io/crates/dirs
*/
getCacheDir(): string {
if (isWeb()) {
const homeDir = this.#homeDir
if (!homeDir) {
throw new ToolkitError('Web home directory not found', {
code: 'WebHomeDirectoryNotFound',
})
}
return homeDir
}
switch (process.platform) {
case 'darwin': {
return _path.join(this.getUserHomeDir(), 'Library/Caches')
}
case 'win32': {
const localAppData = process.env.LOCALAPPDATA
if (!localAppData) {
throw new ToolkitError('LOCALAPPDATA environment variable not set', {
code: 'LocalAppDataNotFound',
})
}
return localAppData
}
case 'linux': {
return _path.join(this.getUserHomeDir(), '.cache')
}
default: {
throw new Error(`Unsupported platform: ${process.platform}. Expected 'darwin', 'win32', 'linux'.`)
}
}
}

/**
* Gets the (cached) username for this session, or "webuser" in web-mode, or "unknown-user" if
* a username could not be resolved.
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/shared/lsp/lspResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as path from 'path'
import { FileType } from 'vscode'
import AdmZip from 'adm-zip'
import { TargetContent, logger, LspResult, LspVersion, Manifest } from './types'
import { getApplicationSupportFolder } from '../vscode/env'
import { createHash } from '../crypto'
import { lspSetupStage, StageResolver, tryStageResolvers } from './utils/setupStage'
import { HttpResourceFetcher } from '../resourcefetcher/httpResourceFetcher'
Expand Down Expand Up @@ -394,7 +393,7 @@ export class LanguageServerResolver {

// lazy calls to `getApplicationSupportFolder()` to avoid failure on windows.
public static get defaultDir() {
return path.join(getApplicationSupportFolder(), `aws/toolkits/language-servers`)
return path.join(fs.getCacheDir(), `aws/toolkits/language-servers`)
}

defaultDownloadFolder() {
Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/shared/vscode/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { onceChanged } from '../utilities/functionUtils'
import { ChildProcess } from '../utilities/processUtils'
import globals, { isWeb } from '../extensionGlobals'
import * as devConfig from '../../dev/config'
import path from 'path'

/**
* Returns true if the current build is running on CI (build server).
Expand Down Expand Up @@ -271,14 +270,3 @@ export async function getMachineId(): Promise<string> {
// TODO: check exit code.
return (await proc.run()).stdout.trim() ?? 'unknown-host'
}

export function getApplicationSupportFolder() {
switch (process.platform) {
case 'darwin': {
return path.join(os.homedir(), 'Library/Application Support')
}
default: {
throw new Error('Only mac is supported right now')
}
}
}
Loading