Skip to content

Commit 3884259

Browse files
committed
feat(amazonq): Add lsp downloading support for windows/lunx
1 parent 428a495 commit 3884259

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

packages/core/src/shared/fs/fs.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,34 @@ export class FileSystem {
543543
return this.#homeDir
544544
}
545545

546+
/**
547+
* Gets the application cache folder for the current platform
548+
*
549+
* Follows the cache_dir convention outlined in https://crates.io/crates/dirs
550+
*/
551+
getCacheDir(): string {
552+
switch (process.platform) {
553+
case 'darwin': {
554+
return _path.join(this.getUserHomeDir(), 'Library/Caches')
555+
}
556+
case 'win32': {
557+
const localAppData = process.env.LOCALAPPDATA
558+
if (!localAppData) {
559+
throw new ToolkitError('LOCALAPPDATA environment variable not set', {
560+
code: 'LocalAppDataNotFound',
561+
})
562+
}
563+
return localAppData
564+
}
565+
case 'linux': {
566+
return _path.join(this.getUserHomeDir(), '.cache')
567+
}
568+
default: {
569+
throw new Error(`Unsupported platform: ${process.platform}. Expected 'darwin', 'win32', or 'linux'.`)
570+
}
571+
}
572+
}
573+
546574
/**
547575
* Gets the (cached) username for this session, or "webuser" in web-mode, or "unknown-user" if
548576
* a username could not be resolved.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ 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'
1413
import { createHash } from '../crypto'
1514
import { lspSetupStage, StageResolver, tryStageResolvers } from './utils/setupStage'
1615
import { HttpResourceFetcher } from '../resourcefetcher/httpResourceFetcher'
@@ -394,7 +393,7 @@ export class LanguageServerResolver {
394393

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

400399
defaultDownloadFolder() {

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { onceChanged } from '../utilities/functionUtils'
1212
import { ChildProcess } from '../utilities/processUtils'
1313
import globals, { isWeb } from '../extensionGlobals'
1414
import * as devConfig from '../../dev/config'
15-
import path from 'path'
1615

1716
/**
1817
* Returns true if the current build is running on CI (build server).
@@ -271,14 +270,3 @@ export async function getMachineId(): Promise<string> {
271270
// TODO: check exit code.
272271
return (await proc.run()).stdout.trim() ?? 'unknown-host'
273272
}
274-
275-
export function getApplicationSupportFolder() {
276-
switch (process.platform) {
277-
case 'darwin': {
278-
return path.join(os.homedir(), 'Library/Application Support')
279-
}
280-
default: {
281-
throw new Error('Only mac is supported right now')
282-
}
283-
}
284-
}

0 commit comments

Comments
 (0)