Skip to content

Commit 076a459

Browse files
committed
feat(amazonq): fallback to bundled flare assets if cannot be downloaded
1 parent fad5b24 commit 076a459

File tree

1 file changed

+36
-26
lines changed
  • plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts

1 file changed

+36
-26
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import org.jetbrains.annotations.VisibleForTesting
1616
import software.aws.toolkits.core.utils.error
1717
import software.aws.toolkits.core.utils.getLogger
1818
import software.aws.toolkits.core.utils.info
19+
import software.aws.toolkits.core.utils.warn
20+
import software.aws.toolkits.jetbrains.AwsPlugin
21+
import software.aws.toolkits.jetbrains.AwsToolkit
1922
import java.nio.file.Path
2023

2124
@Service
@@ -54,36 +57,43 @@ class ArtifactManager @NonInjectable internal constructor(private val manifestFe
5457
return mutex.withLock {
5558
coroutineScope {
5659
async {
57-
val manifest = manifestFetcher.fetch() ?: throw LspException(
58-
"Language Support is not available, as manifest is missing.",
59-
LspException.ErrorCode.MANIFEST_FETCH_FAILED
60-
)
61-
val lspVersions = getLSPVersionsFromManifestWithSpecifiedRange(manifest)
62-
63-
artifactHelper.removeDelistedVersions(lspVersions.deListedVersions)
64-
65-
if (lspVersions.inRangeVersions.isEmpty()) {
66-
// No versions are found which are in the given range. Fallback to local lsp artifacts.
67-
val localLspArtifacts = artifactHelper.getAllLocalLspArtifactsWithinManifestRange(DEFAULT_VERSION_RANGE)
68-
if (localLspArtifacts.isNotEmpty()) {
69-
return@async localLspArtifacts.first().first
60+
try {
61+
val manifest = manifestFetcher.fetch() ?: throw LspException(
62+
"Language Support is not available, as manifest is missing.",
63+
LspException.ErrorCode.MANIFEST_FETCH_FAILED
64+
)
65+
val lspVersions = getLSPVersionsFromManifestWithSpecifiedRange(manifest)
66+
67+
artifactHelper.removeDelistedVersions(lspVersions.deListedVersions)
68+
69+
if (lspVersions.inRangeVersions.isEmpty()) {
70+
// No versions are found which are in the given range. Fallback to local lsp artifacts.
71+
val localLspArtifacts = artifactHelper.getAllLocalLspArtifactsWithinManifestRange(DEFAULT_VERSION_RANGE)
72+
if (localLspArtifacts.isNotEmpty()) {
73+
return@async localLspArtifacts.first().first
74+
}
75+
throw LspException("Language server versions not found in manifest.", LspException.ErrorCode.NO_COMPATIBLE_LSP_VERSION)
7076
}
71-
throw LspException("Language server versions not found in manifest.", LspException.ErrorCode.NO_COMPATIBLE_LSP_VERSION)
72-
}
7377

74-
val targetVersion = lspVersions.inRangeVersions.first()
78+
val targetVersion = lspVersions.inRangeVersions.first()
7579

76-
// If there is an LSP Manifest with the same version
77-
val target = getTargetFromLspManifest(targetVersion)
78-
// Get Local LSP files and check if we can re-use existing LSP Artifacts
79-
val artifactPath: Path = if (artifactHelper.getExistingLspArtifacts(targetVersion, target)) {
80-
artifactHelper.getAllLocalLspArtifactsWithinManifestRange(DEFAULT_VERSION_RANGE).first().first
81-
} else {
82-
artifactHelper.tryDownloadLspArtifacts(project, targetVersion, target)
83-
?: throw LspException("Failed to download LSP artifacts", LspException.ErrorCode.DOWNLOAD_FAILED)
80+
// If there is an LSP Manifest with the same version
81+
val target = getTargetFromLspManifest(targetVersion)
82+
// Get Local LSP files and check if we can re-use existing LSP Artifacts
83+
val artifactPath: Path = if (artifactHelper.getExistingLspArtifacts(targetVersion, target)) {
84+
artifactHelper.getAllLocalLspArtifactsWithinManifestRange(DEFAULT_VERSION_RANGE).first().first
85+
} else {
86+
artifactHelper.tryDownloadLspArtifacts(project, targetVersion, target)
87+
?: throw LspException("Failed to download LSP artifacts", LspException.ErrorCode.DOWNLOAD_FAILED)
88+
}
89+
artifactHelper.deleteOlderLspArtifacts(DEFAULT_VERSION_RANGE)
90+
return@async artifactPath
91+
} catch(e: Exception) {
92+
logger.warn(e) { "Failed to resolve assets from Flare CDN" }
93+
val path = AwsToolkit.PLUGINS_INFO[AwsPlugin.Q]?.path?.resolve("flare") ?: error("not even bundled")
94+
logger.info { "Falling back to bundled assets at $path" }
95+
return@async path
8496
}
85-
artifactHelper.deleteOlderLspArtifacts(DEFAULT_VERSION_RANGE)
86-
return@async artifactPath
8797
}
8898
}.also {
8999
artifactDeferred = it

0 commit comments

Comments
 (0)