Skip to content

feat(lsp): notification message when downloading #6508

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

Merged
merged 4 commits into from
Feb 11, 2025
Merged
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
11 changes: 11 additions & 0 deletions packages/core/src/dev/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { NotificationsController } from '../notifications/controller'
import { DevNotificationsState } from '../notifications/types'
import { QuickPickItem } from 'vscode'
import { ChildProcess } from '../shared/utilities/processUtils'
import { WorkspaceLSPResolver } from '../amazonq/lsp/workspaceInstaller'

interface MenuOption {
readonly label: string
Expand Down Expand Up @@ -450,6 +451,12 @@ const resettableFeatures: readonly ResettableFeature[] = [
detail: 'Resets memory/global state for the notifications panel (includes dismissed, onReceive).',
executor: resetNotificationsState,
},
{
name: 'workspace lsp',
label: 'Lsp',
detail: 'Resets workspace LSP',
executor: resetWorkspaceLspDownload,
},
] as const

// TODO this is *somewhat* similar to `openStorageFromInput`. If we need another
Expand Down Expand Up @@ -538,6 +545,10 @@ async function resetNotificationsState() {
await targetNotificationsController.reset()
}

async function resetWorkspaceLspDownload() {
await new WorkspaceLSPResolver().resolve()
}

async function editNotifications() {
const storageKey = 'aws.notifications.dev'
const current = globalState.get(storageKey) ?? {}
Expand Down
50 changes: 29 additions & 21 deletions packages/core/src/shared/lsp/lspResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { getApplicationSupportFolder } from '../vscode/env'
import { createHash } from '../crypto'
import { lspSetupStage, StageResolver, tryStageResolvers } from './utils/setupStage'
import { HttpResourceFetcher } from '../resourcefetcher/httpResourceFetcher'
import { showMessageWithCancel } from '../../shared/utilities/messages'
import { Timeout } from '../utilities/timeoutUtils'

export class LanguageServerResolver {
constructor(
Expand All @@ -31,32 +33,38 @@ export class LanguageServerResolver {
* @throws ToolkitError if no compatible version can be found
*/
async resolve() {
const latestVersion = this.latestCompatibleLspVersion()
const targetContents = this.getLSPTargetContents(latestVersion)
const cacheDirectory = this.getDownloadDirectory(latestVersion.serverVersion)

const serverResolvers: StageResolver<LspResult>[] = [
{
resolve: async () => await this.getLocalServer(cacheDirectory, latestVersion, targetContents),
telemetryMetadata: { id: this.lsName, languageServerLocation: 'cache' },
},
{
resolve: async () => await this.fetchRemoteServer(cacheDirectory, latestVersion, targetContents),
telemetryMetadata: { id: this.lsName, languageServerLocation: 'remote' },
},
{
resolve: async () => await this.getFallbackServer(latestVersion),
telemetryMetadata: { id: this.lsName, languageServerLocation: 'fallback' },
},
]

return await tryStageResolvers('getServer', serverResolvers, getServerVersion)

const timeout = new Timeout(5000)
await showMessageWithCancel(`Downloading '${this.lsName}' language server`, timeout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the cancel handled? I.e. it should actually cancel the download. Look for existing showMessageWithCancel to see examples.

When the user hits Cancel, it should actually cancel the download.

function getServerVersion(result: LspResult) {
return {
languageServerVersion: result.version,
}
}
try {
const latestVersion = this.latestCompatibleLspVersion()
const targetContents = this.getLSPTargetContents(latestVersion)
const cacheDirectory = this.getDownloadDirectory(latestVersion.serverVersion)

const serverResolvers: StageResolver<LspResult>[] = [
{
resolve: async () => await this.getLocalServer(cacheDirectory, latestVersion, targetContents),
telemetryMetadata: { id: this.lsName, languageServerLocation: 'cache' },
},
{
resolve: async () => await this.fetchRemoteServer(cacheDirectory, latestVersion, targetContents),
telemetryMetadata: { id: this.lsName, languageServerLocation: 'remote' },
},
{
resolve: async () => await this.getFallbackServer(latestVersion),
telemetryMetadata: { id: this.lsName, languageServerLocation: 'fallback' },
},
]

return await tryStageResolvers('getServer', serverResolvers, getServerVersion)
} finally {
logger.info(`Finished setting up LSP server`)
timeout.cancel()
}
}

private async getFallbackServer(latestVersion: LspVersion): Promise<LspResult> {
Expand Down
Loading