Skip to content
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
2 changes: 1 addition & 1 deletion packages/core/src/dev/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ const resettableFeatures: readonly ResettableFeature[] = [
},
{
name: 'workspace lsp',
label: 'Lsp',
label: 'Download Lsp ',
detail: 'Resets workspace LSP',
executor: resetWorkspaceLspDownload,
},
Expand Down
54 changes: 45 additions & 9 deletions packages/core/src/shared/lsp/manifestResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as vscode from 'vscode'
import { getLogger } from '../logger/logger'
import { ToolkitError } from '../errors'
import { Timeout } from '../utilities/timeoutUtils'
import globals from '../extensionGlobals'
import { Manifest } from './types'
import { StageResolver, tryStageResolvers } from './utils/setupStage'
import { HttpResourceFetcher } from '../resourcefetcher/httpResourceFetcher'
import * as localizedText from '../localizedText'
import { AmazonQPromptSettings, amazonQPrompts } from '../settings'

const logger = getLogger('lsp')

Expand Down Expand Up @@ -60,27 +63,29 @@ export class ManifestResolver {
}).getNewETagContent(this.getEtag())

if (!resp.content) {
throw new ToolkitError('New content was not downloaded; fallback to the locally stored manifest')
throw new ToolkitError(
`New content was not downloaded; fallback to the locally stored "${this.lsName}" manifest`
)
}

const manifest = this.parseManifest(resp.content)
await this.saveManifest(resp.eTag, resp.content)
this.checkDeprecation(manifest)
await this.checkDeprecation(manifest)
manifest.location = 'remote'
return manifest
}

private async getLocalManifest(): Promise<Manifest> {
logger.info('Failed to download latest LSP manifest. Falling back to local manifest.')
logger.info(`Failed to download latest "${this.lsName}" manifest. Falling back to local manifest.`)
const storage = this.getStorage()
const manifestData = storage[this.lsName]

if (!manifestData?.content) {
throw new ToolkitError('Failed to download LSP manifest and no local manifest found.')
throw new ToolkitError(`Failed to download "${this.lsName}" manifest and no local manifest found.`)
}

const manifest = this.parseManifest(manifestData.content)
this.checkDeprecation(manifest)
await this.checkDeprecation(manifest)
manifest.location = 'cache'
return manifest
}
Expand All @@ -90,14 +95,45 @@ export class ManifestResolver {
return JSON.parse(content) as Manifest
} catch (error) {
throw new ToolkitError(
`Failed to parse manifest: ${error instanceof Error ? error.message : 'Unknown error'}`
`Failed to parse "${this.lsName}" manifest: ${error instanceof Error ? error.message : 'Unknown error'}`
)
}
}

private checkDeprecation(manifest: Manifest): void {
if (manifest.isManifestDeprecated) {
logger.info('This LSP manifest is deprecated. No future updates will be available.')
/**
* Check if the current manifest is deprecated.
* If yes and user hasn't muted this notification, shows a toast message with two buttons:
* - OK: close and do nothing
* - Don't Show Again: Update suppressed prompt setting so the deprecation message is never shown for this manifest.
* @param manifest
*/
private async checkDeprecation(manifest: Manifest): Promise<void> {
const prompts = AmazonQPromptSettings.instance
const lspId = `${this.lsName}LspManifestMessage` as keyof typeof amazonQPrompts

// Sanity check, if the lsName is changed then we also need to update the prompt keys in settings-amazonq.gen
if (!(lspId in amazonQPrompts)) {
logger.error(`LSP ID "${lspId}" not found in amazonQPrompts.`)
return
}

if (!manifest.isManifestDeprecated) {
// In case we got an new url, make sure the prompt is re-enabled for active manifests
await prompts.enablePrompt(lspId)
return
}

const deprecationMessage = `"${this.lsName}" manifest is deprecated. No future updates will be available.`
logger.info(deprecationMessage)

if (prompts.isPromptEnabled(lspId)) {
void vscode.window
.showInformationMessage(deprecationMessage, localizedText.ok, localizedText.dontShow)
.then(async (button) => {
if (button === localizedText.dontShow) {
await prompts.disablePrompt(lspId)
}
})
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/shared/settings-amazonq.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const amazonqSettings = {
"amazonQWelcomePage": {},
"amazonQSessionConfigurationMessage": {},
"minIdeVersion": {},
"ssoCacheError": {}
"ssoCacheError": {},
"AmazonQLspManifestMessage": {},
"AmazonQ-WorkspaceLspManifestMessage":{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this not follow the existing naming convention, which is found in the items just above this?

},
"amazonQ.showInlineCodeSuggestionsWithCodeReferences": {},
"amazonQ.allowFeatureDevelopmentToRunCodeAndTests": {},
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,12 @@ export class AmazonQPromptSettings
}
}

public async enablePrompt(promptName: amazonQPromptName): Promise<void> {
if (!this.isPromptEnabled(promptName)) {
await this.update(promptName, false)
}
}

public async disablePrompt(promptName: amazonQPromptName): Promise<void> {
if (this.isPromptEnabled(promptName)) {
await this.update(promptName, true)
Expand Down
Loading