-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use cli ls extension [IDE-76] (#551)
* feat: use cli ls extension --------- Co-authored-by: DariusZdroba <[email protected]>
- Loading branch information
1 parent
0d56250
commit 3a41a25
Showing
31 changed files
with
586 additions
and
679 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import axios, { CancelTokenSource } from 'axios'; | ||
import { IConfiguration } from '../common/configuration/configuration'; | ||
import { PROTOCOL_VERSION } from '../common/constants/languageServer'; | ||
import { DownloadAxiosResponse } from '../common/download/downloader'; | ||
import { ILog } from '../common/logger/interfaces'; | ||
import { getAxiosConfig } from '../common/proxy'; | ||
import { IVSCodeWorkspace } from '../common/vscode/workspace'; | ||
import { CliExecutable } from './cliExecutable'; | ||
import { CliSupportedPlatform } from './supportedPlatforms'; | ||
|
||
export interface IStaticCliApi { | ||
getLatestCliVersion(releaseChannel: string): Promise<string>; | ||
downloadBinary(platform: CliSupportedPlatform): Promise<[Promise<DownloadAxiosResponse>, CancelTokenSource]>; | ||
getSha256Checksum(version: string, platform: CliSupportedPlatform): Promise<string>; | ||
} | ||
|
||
export class StaticCliApi implements IStaticCliApi { | ||
constructor( | ||
private readonly workspace: IVSCodeWorkspace, | ||
private readonly configuration: IConfiguration, | ||
private readonly logger: ILog, | ||
) {} | ||
|
||
getLatestVersionDownloadUrl(releaseChannel: string): string { | ||
const downloadUrl = `${this.configuration.getCliBaseDownloadUrl()}/cli/${releaseChannel}/ls-protocol-version-${PROTOCOL_VERSION}`; | ||
return downloadUrl; | ||
} | ||
|
||
getDownloadUrl(version: string, platform: CliSupportedPlatform): string { | ||
if (!version.startsWith('v')) { | ||
version = `v${version}`; | ||
} | ||
const downloadUrl = `${this.configuration.getCliBaseDownloadUrl()}/cli/${version}/${this.getFileName(platform)}`; | ||
return downloadUrl; | ||
} | ||
|
||
getSha256DownloadUrl(version: string, platform: CliSupportedPlatform): string { | ||
const downloadUrl = `${this.getDownloadUrl(version, platform)}.sha256`; | ||
return downloadUrl; | ||
} | ||
|
||
getFileName(platform: CliSupportedPlatform): string { | ||
return CliExecutable.getFileName(platform); | ||
} | ||
|
||
async getLatestCliVersion(releaseChannel: string): Promise<string> { | ||
let { data } = await axios.get<string>( | ||
this.getLatestVersionDownloadUrl(releaseChannel), | ||
await getAxiosConfig(this.workspace, this.configuration, this.logger), | ||
); | ||
data = data.replace('\n', ''); | ||
if (data == '') return Promise.reject(new Error('CLI Version not found')); | ||
return data; | ||
} | ||
|
||
async downloadBinary(platform: CliSupportedPlatform): Promise<[Promise<DownloadAxiosResponse>, CancelTokenSource]> { | ||
const axiosCancelToken = axios.CancelToken.source(); | ||
const latestCliVersion = await this.getLatestCliVersion(this.configuration.getCliReleaseChannel()); | ||
|
||
const downloadUrl = this.getDownloadUrl(latestCliVersion, platform); | ||
|
||
const response = axios.get(downloadUrl, { | ||
responseType: 'stream', | ||
cancelToken: axiosCancelToken.token, | ||
...(await getAxiosConfig(this.workspace, this.configuration, this.logger)), | ||
}); | ||
|
||
return [response as Promise<DownloadAxiosResponse>, axiosCancelToken]; | ||
} | ||
|
||
async getSha256Checksum(version: string, platform: CliSupportedPlatform): Promise<string> { | ||
const fileName = this.getFileName(platform); | ||
const { data } = await axios.get<string>( | ||
`${this.getSha256DownloadUrl(version, platform)}`, | ||
await getAxiosConfig(this.workspace, this.configuration, this.logger), | ||
); | ||
|
||
const checksum = data.replace(fileName, '').replace('\n', '').trim(); | ||
|
||
if (!checksum) return Promise.reject(new Error('Checksum not found')); | ||
|
||
return checksum; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
const SupportedCliPlatformsList = ['linux', 'win32', 'darwin'] as const; | ||
const SupportedCliPlatformsList = [ | ||
'linux', | ||
'linux_arm64', | ||
'linux_alpine', | ||
'linux_alpine_arm64', | ||
'windows', | ||
'windows_arm64', | ||
'macos', | ||
'macos_arm64', | ||
] as const; | ||
export type CliSupportedPlatform = typeof SupportedCliPlatformsList[number]; |
Oops, something went wrong.