Skip to content

Commit 54e2561

Browse files
authored
Merge branch 'main' into keybinding
2 parents 752555c + f5460c7 commit 54e2561

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,49 @@ class FeatureDevSessionContextTest : FeatureDevTestBase(HeavyJavaCodeInsightTest
161161

162162
assertEquals(zippedFiles, expectedFiles)
163163
}
164+
165+
@Test
166+
fun testConvertGitIgnorePatternToRegex() {
167+
val sampleGitIgnorePatterns = listOf(".*", "build/", "*.txt", "*.png")
168+
val sampleFileNames = listOf(
169+
".gitignore/",
170+
".env/",
171+
"file.txt/",
172+
".git/config/",
173+
"src/file.txt/",
174+
"build/",
175+
"build/output.jar/",
176+
"builds/",
177+
"mybuild/",
178+
"build.json/",
179+
"log.txt/",
180+
"file.txt.json/",
181+
"file.png/",
182+
"src/file.png/"
183+
)
184+
185+
val patterns = sampleGitIgnorePatterns.map { pattern -> featureDevSessionContext.convertGitIgnorePatternToRegex(pattern).toRegex() }
186+
187+
val matchedFiles = sampleFileNames.filter { fileName ->
188+
patterns.any { pattern ->
189+
pattern.matches(fileName)
190+
}
191+
}
192+
193+
val expectedFilesToMatch =
194+
listOf(
195+
".gitignore/",
196+
".env/",
197+
"file.txt/",
198+
".git/config/",
199+
"src/file.txt/",
200+
"build/",
201+
"build/output.jar/",
202+
"log.txt/",
203+
"file.png/",
204+
"src/file.png/"
205+
)
206+
207+
assertEquals(expectedFilesToMatch, matchedFiles)
208+
}
164209
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En
314314
logger.info { "sending message: ${msgType.endpoint} to lsp on port ${encoderServer.port}" }
315315
val url = URL("http://localhost:${encoderServer.port}/${msgType.endpoint}")
316316
if (!encoderServer.isNodeProcessRunning()) {
317-
logger.warn { "language server is not running" }
317+
logger.warn { "language server for ${project.name} is not running" }
318318
return null
319319
}
320320
// use 1h as timeout for index, 5 seconds for other APIs

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,17 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo
279279
}
280280

281281
// gitignore patterns are not regex, method update needed.
282-
private fun convertGitIgnorePatternToRegex(pattern: String): String = pattern
283-
.replace(".", "\\.")
284-
.replace("*", ".*")
285-
.let { if (it.endsWith("/")) "$it.*" else "$it/.*" } // Add a trailing /* to all patterns. (we add a trailing / to all files when matching)
282+
fun convertGitIgnorePatternToRegex(pattern: String): String {
283+
// Special case for ".*" to match only dotfiles
284+
if (pattern == ".*") {
285+
return "^\\..*/.*"
286+
}
287+
288+
return pattern
289+
.replace(".", "\\.")
290+
.replace("*", ".*")
291+
.let { if (it.endsWith("/")) "$it.*" else "$it/.*" } // Add a trailing /* to all patterns. (we add a trailing / to all files when matching)
292+
}
286293
var selectedSourceFolder: VirtualFile
287294
set(newRoot) {
288295
_selectedSourceFolder = newRoot

0 commit comments

Comments
 (0)