-
Notifications
You must be signed in to change notification settings - Fork 273
fix(amazonq): change to use withExtensionFilter to hide unallowed files #5909
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
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
58ab971
fix(amazonq): change to use withExtensionFilter to hide unallowed files
yzhangok 3b2cee2
fix(amazonq): change to use withExtensionFilter
yzhangok 3e0bb8e
Merge branch 'main' into file-chooser
yzhangok c2fad64
fix(amazonq): optimize imports
yzhangok 5687629
fix(amazonq): comments
yzhangok cfec3f7
fix(amazonq): fix detekt
yzhangok b6347fc
Merge branch 'main' into file-chooser
yzhangok 4578b57
fix(amazonq): remove interface and rename
yzhangok c747a68
fix(amazonq): detekt
yzhangok 8daf725
Merge branch 'main' into file-chooser
manodnyab d944608
Merge branch 'main' into file-chooser
samgst-amazon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.changes/next-release/bugfix-7029c1d5-212c-48ac-9513-38f0beca8fa8.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type" : "bugfix", | ||
"description" : "Fix unsupported files being shown in file picker when selecting images for adding image context in Windows" | ||
} |
26 changes: 26 additions & 0 deletions
26
...rc-242/software/aws/toolkits/jetbrains/services/amazonq/lsp/util/FileChooserCompatImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.amazonq.lsp.util | ||
|
||
import com.intellij.openapi.fileChooser.FileChooserDescriptor | ||
|
||
/** | ||
* FileChooserCompat implementation for IntelliJ Platform versions before 2024.3 (baseline < 243). | ||
* Uses withFileFilter method which provides filtering functionality but doesn't visually filter | ||
* files in the chooser dialog. | ||
*/ | ||
internal class FileChooserCompatImpl : FileChooserCompat { | ||
override fun applyExtensionFilter( | ||
descriptor: FileChooserDescriptor, | ||
filterName: String, | ||
allowedExtensions: Set<String>, | ||
): FileChooserDescriptor = descriptor.withFileFilter { virtualFile -> | ||
if (virtualFile.isDirectory) { | ||
true // Always allow directories for navigation | ||
} else { | ||
val extension = virtualFile.extension?.lowercase() | ||
extension != null && allowedExtensions.contains(extension) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...c-243+/software/aws/toolkits/jetbrains/services/amazonq/lsp/util/FileChooserCompatImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.amazonq.lsp.util | ||
|
||
import com.intellij.openapi.fileChooser.FileChooserDescriptor | ||
|
||
/** | ||
* FileChooserCompat implementation for IntelliJ Platform versions 2024.3+ (baseline >= 243). | ||
* Uses withExtensionFilter method which provides both filtering functionality and visual | ||
* filtering in the chooser dialog. | ||
*/ | ||
internal class FileChooserCompatImpl : FileChooserCompat { | ||
override fun applyExtensionFilter( | ||
descriptor: FileChooserDescriptor, | ||
filterName: String, | ||
allowedExtensions: Set<String>, | ||
): FileChooserDescriptor = descriptor.withExtensionFilter(filterName, *allowedExtensions.toTypedArray()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...munity/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/util/FileChooserCompat.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.amazonq.lsp.util | ||
|
||
import com.intellij.openapi.fileChooser.FileChooserDescriptor | ||
|
||
/** | ||
* Compatibility interface for handling file chooser extension filtering across different IntelliJ Platform versions. | ||
* | ||
* The withExtensionFilter method was introduced in IntelliJ Platform 2024.3 (baseline version 243). | ||
* For older versions, fall back to withFileFilter which provides similar functionality | ||
*/ | ||
interface FileChooserCompat { | ||
/** | ||
* Applies file extension filtering to the given FileChooserDescriptor. | ||
* | ||
* @param descriptor The FileChooserDescriptor to apply filtering to | ||
* @param filterName The display name for the filter (e.g., "Images") | ||
* @param allowedExtensions Set of allowed file extensions (e.g., "jpg", "png") | ||
* @return The modified FileChooserDescriptor | ||
*/ | ||
fun applyExtensionFilter( | ||
descriptor: FileChooserDescriptor, | ||
filterName: String, | ||
allowedExtensions: Set<String>, | ||
): FileChooserDescriptor | ||
|
||
companion object { | ||
fun getInstance(): FileChooserCompat = FileChooserCompatImpl() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this interface, can we just add a separate function in the separate modules?