Skip to content

Commit a394c85

Browse files
committed
Removing FeatureDevSessionContext changes.
1 parent 556f3f1 commit a394c85

File tree

2 files changed

+108
-18
lines changed

2 files changed

+108
-18
lines changed

plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/FeatureDevSessionContextTest.kt

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.intellij.openapi.vfs.VirtualFile
55
import com.intellij.testFramework.RuleChain
6+
import org.junit.Assert.assertEquals
67
import org.junit.Assert.assertFalse
78
import org.junit.Assert.assertTrue
89
import org.junit.Before
@@ -75,6 +76,7 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
7576
@Test
7677
fun testZipProject() {
7778
addFilesToProjectModule(
79+
".gitignore",
7880
".gradle/cached.jar",
7981
"src/MyClass.java",
8082
"gradlew",
@@ -83,6 +85,19 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
8385
"settings.gradle",
8486
"build.gradle",
8587
"gradle/wrapper/gradle-wrapper.properties",
88+
"builder/GetTestBuilder.java",
89+
".aws-sam/build/function1",
90+
".gem/specs.rb",
91+
"archive.zip",
92+
"output.bin",
93+
"images/logo.png",
94+
"assets/header.jpg",
95+
"icons/menu.svg",
96+
"license.txt",
97+
"License.md",
98+
"node_modules/express",
99+
"build/outputs",
100+
"dist/bundle.js"
86101
)
87102

88103
val zipResult = featureDevSessionContext.getProjectZip()
@@ -102,11 +117,73 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
102117
"gradlew",
103118
"gradlew.bat",
104119
"README.md",
105-
"settings.gradle",
106-
"build.gradle",
107120
"gradle/wrapper/gradle-wrapper.properties",
121+
"builder/GetTestBuilder.java"
108122
)
109123

110124
assertTrue(zippedFiles == expectedFiles)
111125
}
126+
127+
@Test
128+
fun `test basic pattern conversion`() {
129+
val input = "*.txt"
130+
val expected = "(?:^|.*/?)[^/]*[^/]\\.txt(?:/.*)?\$"
131+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
132+
}
133+
134+
@Test
135+
fun `test pattern with special characters`() {
136+
val input = "test[abc].txt"
137+
val expected = "(?:^|.*/?)test\\[abc\\]\\.txt(?:/.*)?$"
138+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
139+
}
140+
141+
@Test
142+
fun `test pattern with double asterisk`() {
143+
val input = "**/build"
144+
val expected = "(?:^|.*/?).[^/]*[^/][^/]/build(?:/.*)?\$"
145+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
146+
}
147+
148+
@Test
149+
fun `test pattern starting with slash`() {
150+
val input = "/root/file.txt"
151+
val expected = "^root/file\\.txt(?:/.*)?$"
152+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
153+
}
154+
155+
@Test
156+
fun `test pattern ending with slash`() {
157+
val input = "build/"
158+
val expected = "(?:^|.*/?)build/.*"
159+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
160+
}
161+
162+
@Test
163+
fun `test pattern with question mark`() {
164+
val input = "file?.txt"
165+
val expected = "(?:^|.*/?)file[^/]\\.txt(?:/.*)?$"
166+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
167+
}
168+
169+
@Test
170+
fun `test complex pattern with multiple special characters`() {
171+
val input = "**/test-[0-9]*.{java,kt}"
172+
val expected = "(?:^|.*/?).[^/]*[^/][^/]/test-\\[0-9\\][^/]*[^/]\\.\\{java\\,kt\\}(?:/.*)?\$"
173+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
174+
}
175+
176+
@Test
177+
fun `test empty pattern`() {
178+
val input = ""
179+
val expected = "(?:^|.*/?)(?:/.*)?$"
180+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
181+
}
182+
183+
@Test
184+
fun `test pattern with all special regex characters`() {
185+
val input = ".$+()[]{}^|"
186+
val expected = "(?:^|.*/?)\\.\\\$\\+\\(\\)\\[\\]\\{\\}\\^\\|(?:/.*)?$"
187+
assertEquals(expected, featureDevSessionContext.convertGitIgnorePatternToRegex(input))
188+
}
112189
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,34 @@ class RepoSizeLimitError(override val message: String) : RuntimeException(), Rep
4545

4646
class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Long? = null) {
4747
// TODO: Need to correct this class location in the modules going further to support both amazonq and codescan.
48-
48+
4949
private val additionalGitIgnoreRules = setOf(
50-
"\\.aws-sam",
51-
"\\.svn",
52-
"/\\.(?:hg|git)/?", // Combine version control system patterns
53-
"\\.(?:rvm|gem)", // Combine Ruby-related patterns
54-
"/?\\.(?:gitignore|project|idea/?)", // Combine project config patterns
55-
"\\.(?:zip|bin)$", // Combine binary file patterns
56-
"\\.(?:png|jpg|svg)$", // Combine image file patterns
57-
"\\.pyc$", // Python compiled files
58-
"/[Ll][Ii][Cc][Ee][Nn][Ss][Ee]\\.(txt|md)$", // Case-insensitive license files
59-
"(?:^|.*/?)node_modules(?:/.*)?\$",
60-
"(?:^|.*/?)build(?:/.*)?\$",
61-
"(?:^|.*/?)dist(?:/.*)?\$"
62-
).map { Regex(it) }
50+
".aws-sam",
51+
".gem",
52+
".git",
53+
".gitignore",
54+
".gradle",
55+
".hg",
56+
".idea",
57+
".project",
58+
".rvm",
59+
".svn",
60+
"*.zip",
61+
"*.bin",
62+
"*.png",
63+
"*.jpg",
64+
"*.svg",
65+
"*.pyc",
66+
"license.txt",
67+
"License.txt",
68+
"LICENSE.txt",
69+
"license.md",
70+
"License.md",
71+
"LICENSE.md",
72+
"node_modules",
73+
"build",
74+
"dist"
75+
)
6376

6477
// well known source files that do not have extensions
6578
private val wellKnownSourceFiles = setOf(
@@ -81,7 +94,7 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
8194
init {
8295
ignorePatternsWithGitIgnore = try {
8396
buildList {
84-
addAll(additionalGitIgnoreRules)
97+
addAll(additionalGitIgnoreRules.map { convertGitIgnorePatternToRegex(it) })
8598
addAll(parseGitIgnore())
8699
}.mapNotNull { pattern ->
87100
runCatching { Regex(pattern) }.getOrNull()
@@ -239,7 +252,7 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
239252
}
240253

241254
// gitignore patterns are not regex, method update needed.
242-
private fun convertGitIgnorePatternToRegex(pattern: String): String = pattern
255+
fun convertGitIgnorePatternToRegex(pattern: String): String = pattern
243256
// Escape special regex characters except * and ?
244257
.replace(".", "\\.")
245258
.replace("+", "\\+")

0 commit comments

Comments
 (0)