@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.LocalFileSystem
2020import com.intellij.openapi.vfs.VfsUtil
2121import com.intellij.openapi.vfs.VfsUtilCore
2222import com.intellij.openapi.vfs.VirtualFileManager
23+ import com.intellij.openapi.application.ApplicationInfo
2324import migration.software.aws.toolkits.jetbrains.settings.AwsSettings
2425import org.eclipse.lsp4j.ConfigurationParams
2526import org.eclipse.lsp4j.MessageActionItem
@@ -308,13 +309,30 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
308309 if (params.filters.isNotEmpty() && ! params.canSelectFolders) {
309310 // Create a combined list of all allowed extensions
310311 val allowedExtensions = params.filters.values.flatten().toSet()
311-
312- withFileFilter { virtualFile ->
313- if (virtualFile.isDirectory) {
314- true // Always allow directories for navigation
315- } else {
316- val extension = virtualFile.extension?.lowercase()
317- extension != null && allowedExtensions.contains(extension)
312+ if (isExtensionFilterSupported()) {
313+ // Use reflection to call withExtensionFilter which is only available in 2024.3+
314+ try {
315+ val method = this .javaClass.getMethod(" withExtensionFilter" , String ::class .java, Array <String >::class .java)
316+ method.invoke(this , " Image" , allowedExtensions.toTypedArray())
317+ } catch (e: Exception ) {
318+ // Fallback to withFileFilter if reflection fails
319+ withFileFilter { virtualFile ->
320+ if (virtualFile.isDirectory) {
321+ true // Always allow directories for navigation
322+ } else {
323+ val extension = virtualFile.extension?.lowercase()
324+ extension != null && allowedExtensions.contains(extension)
325+ }
326+ }
327+ }
328+ } else {
329+ withFileFilter { virtualFile ->
330+ if (virtualFile.isDirectory) {
331+ true // Always allow directories for navigation
332+ } else {
333+ val extension = virtualFile.extension?.lowercase()
334+ extension != null && allowedExtensions.contains(extension)
335+ }
318336 }
319337 }
320338 }
@@ -579,6 +597,20 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
579597 }
580598 }
581599
600+ /* *
601+ * Checks if the current JetBrains IDE version supports the withExtensionFilter API.
602+ *
603+ * The withExtensionFilter method was introduced in IntelliJ Platform 2024.3 (baseline version 243).
604+ * For older versions, we need to fall back to withFileFilter which provides similar functionality
605+ * but with different UI behavior (files are not visually filtered in the file chooser dialog).
606+ *
607+ * @return true if the IDE version supports withExtensionFilter (2024.3+), false otherwise
608+ */
609+ private fun isExtensionFilterSupported (): Boolean {
610+ val baselineVersion = ApplicationInfo .getInstance().build.baselineVersion
611+ return baselineVersion >= 243 // 2024.3 or later
612+ }
613+
582614 companion object {
583615 val localHistoryPath = Paths .get(
584616 UserHomeDirectoryUtils .userHomeDirectory(),
0 commit comments