Skip to content

Commit a739169

Browse files
author
tomzu
committed
use withProgress notification popup
1 parent 119ed30 commit a739169

File tree

4 files changed

+80
-50
lines changed

4 files changed

+80
-50
lines changed

packages/amazonq/src/lsp/lspInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class AmazonQLSPResolver implements LspResolver {
4242
manifest,
4343
name,
4444
new Range(supportedLspServerVersions)
45-
).resolve()
45+
).resolveWithProgress()
4646

4747
const nodePath = path.join(installationResult.assetDirectory, `servers/${getNodeExecutableName()}`)
4848
await fs.chmod(nodePath, 0o755)

packages/core/src/amazonq/lsp/workspaceInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class WorkspaceLSPResolver implements LspResolver {
2424
manifest,
2525
name,
2626
new Range(supportedLspServerVersions)
27-
).resolve()
27+
).resolveWithProgress()
2828

2929
const nodeName =
3030
process.platform === 'win32' ? getNodeExecutableName() : `node-${process.platform}-${process.arch}`

packages/core/src/dev/activation.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { NotificationsController } from '../notifications/controller'
2525
import { DevNotificationsState } from '../notifications/types'
2626
import { QuickPickItem } from 'vscode'
2727
import { ChildProcess } from '../shared/utilities/processUtils'
28+
import { WorkspaceLSPResolver } from '../amazonq/lsp/workspaceInstaller'
2829

2930
interface MenuOption {
3031
readonly label: string
@@ -464,6 +465,12 @@ const resettableFeatures: readonly ResettableFeature[] = [
464465
detail: 'Resets memory/global state for the notifications panel (includes dismissed, onReceive).',
465466
executor: resetNotificationsState,
466467
},
468+
{
469+
name: 'workspace lsp',
470+
label: 'Lsp',
471+
detail: 'Resets workspace LSP',
472+
executor: resetWorkspaceLspDownload,
473+
},
467474
] as const
468475

469476
// TODO this is *somewhat* similar to `openStorageFromInput`. If we need another
@@ -552,6 +559,10 @@ async function resetNotificationsState() {
552559
await targetNotificationsController.reset()
553560
}
554561

562+
async function resetWorkspaceLspDownload() {
563+
await new WorkspaceLSPResolver().resolve()
564+
}
565+
555566
async function editNotifications() {
556567
const storageKey = 'aws.notifications.dev'
557568
const current = globalState.get(storageKey) ?? {}

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

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import fs from '../fs/fs'
7+
import * as vscode from 'vscode'
78
import { ToolkitError } from '../errors'
89
import * as semver from 'semver'
910
import * as path from 'path'
@@ -22,6 +23,20 @@ export class LanguageServerResolver {
2223
private readonly _defaultDownloadFolder?: string
2324
) {}
2425

26+
// wraps the resolver to show download status message
27+
async resolveWithProgress() {
28+
return vscode.window.withProgress(
29+
{
30+
location: vscode.ProgressLocation.Notification,
31+
title: `Downloading '${this.lsName}' language server`,
32+
cancellable: false,
33+
},
34+
async (progress) => {
35+
return this.resolve()
36+
}
37+
)
38+
}
39+
2540
/**
2641
* Downloads and sets up the Language Server, attempting different locations in order:
2742
* 1. Local cache
@@ -30,63 +45,67 @@ export class LanguageServerResolver {
3045
* @throws ToolkitError if no compatible version can be found
3146
*/
3247
async resolve() {
33-
const result: LspResult = {
34-
location: 'unknown',
35-
version: '',
36-
assetDirectory: '',
37-
}
38-
39-
const latestVersion = this.latestCompatibleLspVersion()
40-
const targetContents = this.getLSPTargetContents(latestVersion)
41-
const cacheDirectory = this.getDownloadDirectory(latestVersion.serverVersion)
48+
try {
49+
const result: LspResult = {
50+
location: 'unknown',
51+
version: '',
52+
assetDirectory: '',
53+
}
4254

43-
if (await this.hasValidLocalCache(cacheDirectory, targetContents)) {
44-
result.location = 'cache'
45-
result.version = latestVersion.serverVersion
46-
result.assetDirectory = cacheDirectory
47-
return result
48-
} else {
49-
// Delete the cached directory since it's invalid
50-
if (await fs.existsDir(cacheDirectory)) {
51-
await fs.delete(cacheDirectory, {
52-
recursive: true,
53-
})
55+
const latestVersion = this.latestCompatibleLspVersion()
56+
const targetContents = this.getLSPTargetContents(latestVersion)
57+
const cacheDirectory = this.getDownloadDirectory(latestVersion.serverVersion)
58+
59+
if (await this.hasValidLocalCache(cacheDirectory, targetContents)) {
60+
result.location = 'cache'
61+
result.version = latestVersion.serverVersion
62+
result.assetDirectory = cacheDirectory
63+
return result
64+
} else {
65+
// Delete the cached directory since it's invalid
66+
if (await fs.existsDir(cacheDirectory)) {
67+
await fs.delete(cacheDirectory, {
68+
recursive: true,
69+
})
70+
}
5471
}
55-
}
5672

57-
if (await this.downloadRemoteTargetContent(targetContents, latestVersion.serverVersion)) {
58-
result.location = 'remote'
59-
result.version = latestVersion.serverVersion
60-
result.assetDirectory = cacheDirectory
61-
return result
62-
} else {
63-
// clean up any leftover content that may have been downloaded
64-
if (await fs.existsDir(cacheDirectory)) {
65-
await fs.delete(cacheDirectory, {
66-
recursive: true,
67-
})
73+
if (await this.downloadRemoteTargetContent(targetContents, latestVersion.serverVersion)) {
74+
result.location = 'remote'
75+
result.version = latestVersion.serverVersion
76+
result.assetDirectory = cacheDirectory
77+
return result
78+
} else {
79+
// clean up any leftover content that may have been downloaded
80+
if (await fs.existsDir(cacheDirectory)) {
81+
await fs.delete(cacheDirectory, {
82+
recursive: true,
83+
})
84+
}
6885
}
69-
}
7086

71-
logger.info(
72-
`Unable to download language server version ${latestVersion.serverVersion}. Attempting to fetch from fallback location`
73-
)
87+
logger.info(
88+
`Unable to download language server version ${latestVersion.serverVersion}. Attempting to fetch from fallback location`
89+
)
7490

75-
const fallbackDirectory = await this.getFallbackDir(latestVersion.serverVersion)
76-
if (!fallbackDirectory) {
77-
throw new ToolkitError('Unable to find a compatible version of the Language Server')
78-
}
91+
const fallbackDirectory = await this.getFallbackDir(latestVersion.serverVersion)
92+
if (!fallbackDirectory) {
93+
throw new ToolkitError('Unable to find a compatible version of the Language Server')
94+
}
7995

80-
const version = path.basename(fallbackDirectory)
81-
logger.info(
82-
`Unable to install ${this.lsName} language server v${latestVersion.serverVersion}. Launching a previous version from ${fallbackDirectory}`
83-
)
96+
const version = path.basename(fallbackDirectory)
97+
logger.info(
98+
`Unable to install ${this.lsName} language server v${latestVersion.serverVersion}. Launching a previous version from ${fallbackDirectory}`
99+
)
84100

85-
result.location = 'fallback'
86-
result.version = version
87-
result.assetDirectory = fallbackDirectory
101+
result.location = 'fallback'
102+
result.version = version
103+
result.assetDirectory = fallbackDirectory
88104

89-
return result
105+
return result
106+
} finally {
107+
logger.info(`Finished setting up LSP server`)
108+
}
90109
}
91110

92111
/**

0 commit comments

Comments
 (0)