Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(amazonq): Add lsp downloading support for windows/linux #6325

Open
wants to merge 1 commit into
base: feature/amazonqLSP
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions packages/core/src/shared/fs/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,34 @@ export class FileSystem {
return this.#homeDir
}

/**
* Gets the application cache folder for the current platform
*
* Follows the cache_dir convention outlined in https://crates.io/crates/dirs
*/
getCacheDir(): string {
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', or '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')
}
}
}