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): user cancellable lsp download #6573

Merged
merged 7 commits into from
Mar 4, 2025
Merged
Changes from 1 commit
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: 27 additions & 12 deletions packages/core/src/shared/lsp/lspResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export class LanguageServerResolver {
* @throws ToolkitError if no compatible version can be found
*/
async resolve() {
const timeout = new Timeout(5000)
await showMessageWithCancel(`Downloading '${this.lsName}' language server`, timeout)
function getServerVersion(result: LspResult) {
return {
languageServerVersion: result.version,
Expand Down Expand Up @@ -63,7 +61,6 @@ export class LanguageServerResolver {
return await tryStageResolvers('getServer', serverResolvers, getServerVersion)
} finally {
logger.info(`Finished setting up LSP server`)
timeout.cancel()
}
}

Expand All @@ -87,19 +84,37 @@ export class LanguageServerResolver {
}
}

/**
* Show a toast notification with progress bar for lsp remote downlaod
* Returns a timeout to be passed down into httpFetcher to handle user cancellation
*/
private async showDownloadProgress() {
const timeout = new Timeout(5000)
timeout?.token.onCancellationRequested((event) => {
logger.info('Remote download cancelled by user')
})
await showMessageWithCancel(`Downloading '${this.lsName}' language server`, timeout)
return timeout
}

private async fetchRemoteServer(
cacheDirectory: string,
latestVersion: LspVersion,
targetContents: TargetContent[]
): Promise<LspResult> {
if (await this.downloadRemoteTargetContent(targetContents, latestVersion.serverVersion)) {
return {
location: 'remote',
version: latestVersion.serverVersion,
assetDirectory: cacheDirectory,
const timeout = await this.showDownloadProgress()
try {
if (await this.downloadRemoteTargetContent(targetContents, latestVersion.serverVersion, timeout)) {
return {
location: 'remote',
version: latestVersion.serverVersion,
assetDirectory: cacheDirectory,
}
} else {
throw new ToolkitError('Failed to download server from remote', { code: 'RemoteDownloadFailed' })
}
} else {
throw new ToolkitError('Failed to download server from remote', { code: 'RemoteDownloadFailed' })
} finally {
timeout.dispose()
}
}

Expand Down Expand Up @@ -193,7 +208,7 @@ export class LanguageServerResolver {
* true, if all of the contents were successfully downloaded and unzipped
* false, if any of the contents failed to download or unzip
*/
private async downloadRemoteTargetContent(contents: TargetContent[], version: string) {
private async downloadRemoteTargetContent(contents: TargetContent[], version: string, timeout: Timeout) {
const downloadDirectory = this.getDownloadDirectory(version)

if (!(await fs.existsDir(downloadDirectory))) {
Expand All @@ -202,7 +217,7 @@ export class LanguageServerResolver {

const fetchTasks = contents.map(async (content) => {
return {
res: await new HttpResourceFetcher(content.url, { showUrl: true }).get(),
res: await new HttpResourceFetcher(content.url, { showUrl: true, timeout: timeout }).get(),
hash: content.hashes[0],
filename: content.filename,
}
Expand Down
Loading