Skip to content

Commit 1b7eb03

Browse files
authored
feat(amazonq): Add lsp downloading support for windows/linux (#6325)
## Problem - Language servers are only being downloaded on macs ## Solution - Download on windows/linux/web as well --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 7d473c5 commit 1b7eb03

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
isPermissionsError,
1717
scrubNames,
1818
} from '../errors'
19-
import globals from '../extensionGlobals'
19+
import globals, { isWeb } from '../extensionGlobals'
2020
import { isWin } from '../vscode/env'
2121
import { resolvePath } from '../utilities/pathUtils'
2222
import crypto from 'crypto'
@@ -543,6 +543,43 @@ 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+
if (isWeb()) {
553+
const homeDir = this.#homeDir
554+
if (!homeDir) {
555+
throw new ToolkitError('Web home directory not found', {
556+
code: 'WebHomeDirectoryNotFound',
557+
})
558+
}
559+
return homeDir
560+
}
561+
switch (process.platform) {
562+
case 'darwin': {
563+
return _path.join(this.getUserHomeDir(), 'Library/Caches')
564+
}
565+
case 'win32': {
566+
const localAppData = process.env.LOCALAPPDATA
567+
if (!localAppData) {
568+
throw new ToolkitError('LOCALAPPDATA environment variable not set', {
569+
code: 'LocalAppDataNotFound',
570+
})
571+
}
572+
return localAppData
573+
}
574+
case 'linux': {
575+
return _path.join(this.getUserHomeDir(), '.cache')
576+
}
577+
default: {
578+
throw new Error(`Unsupported platform: ${process.platform}. Expected 'darwin', 'win32', 'linux'.`)
579+
}
580+
}
581+
}
582+
546583
/**
547584
* Gets the (cached) username for this session, or "webuser" in web-mode, or "unknown-user" if
548585
* 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)