Skip to content
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

show context files on empty at-expression #555

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/java/com/sourcegraph/cody/PromptPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,18 @@ data class AtExpression(
val value: String
)

val atExpressionPattern = """(@(?:\\\s|[^\s])+)(?:\s|$)""".toRegex()
val atExpressionPattern = """(@(?:\\\s|\S)*)(?:\s|$)""".toRegex()

fun findAtExpressions(text: String): List<AtExpression> {
val matches = atExpressionPattern.findAll(text)
val expressions = ArrayList<AtExpression>()
for (match in matches) {
val subMatch = match.groups.get(1)
val mainMatch = match.groups[0] ?: continue
val prevIndex = mainMatch.range.first - 1
// filter out things like email addresses
if (prevIndex >= 0 && !text[prevIndex].isWhitespace()) continue

val subMatch = match.groups[1]
if (subMatch != null) {
val value = subMatch.value.substring(1).replace("\\ ", " ")
expressions.add(
Expand Down
7 changes: 6 additions & 1 deletion src/test/kotlin/com/sourcegraph/cody/PromptPanelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class PromptPanelTest : TestCase() {
"foo ".length + "@file\\ with\\ spaces".length,
"@file\\ with\\ spaces",
"file with spaces"),
)))
)),
Case("@", listOf(AtExpression(0, 1, "@", ""))),
Case("foo @", listOf(AtExpression("foo ".length, "foo @".length, "@", ""))),
Case("@ foo", listOf(AtExpression(0, 1, "@", ""))),
Case("[email protected]", listOf()),
)

for (case in cases) {
assertEquals(case.expected, findAtExpressions(case.text))
Expand Down
Loading