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

Filename incorrect when --before and --after used #35

Open
andrewhowdencom opened this issue Aug 11, 2017 · 2 comments
Open

Filename incorrect when --before and --after used #35

andrewhowdencom opened this issue Aug 11, 2017 · 2 comments

Comments

@andrewhowdencom
Copy link

No description provided.

@aykamko
Copy link
Owner

aykamko commented Oct 23, 2017

related to #29

I don't have the bandwidth to fix this issue so I'm calling out to whoever would like to take this on. It's going to require another refactor of how tag parses the search backend's output, yay.

@bturrubiates
Copy link

This isn't a permanent solution, but I was encountering this problem as well using ag as the backend and came up with a quick fix:

diff --git a/tag.go b/tag.go
index b54e9e2..09f8679 100644
--- a/tag.go
+++ b/tag.go
@@ -59,10 +59,12 @@ func getEnvDefault(key, fallback string) string {
 }

 var (
-       red          = color.RedString
-       blue         = color.BlueString
-       lineNumberRe = regexp.MustCompile(`^(\d+):(\d+):.*`)
-       ansi         = regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`) // Source: https://superuser.com/a/380778
+       red                = color.RedString
+       blue               = color.BlueString
+       lineNumberRe       = regexp.MustCompile(`^(\d+):(\d+):.*`)
+       lineContinuationRe = regexp.MustCompile(`^(\d+)-.*`)
+       lineSeperatorRe    = regexp.MustCompile(`^--`)
+       ansi               = regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`) // Source: https://superuser.com/a/380778
 )

 type AliasFile struct {
@@ -156,9 +158,12 @@ func generateTags(cmd *exec.Cmd) int {
                        fmt.Printf("%s %s\n", tagPrefix(aliasIndex), string(line))
                        aliasIndex++
                } else {
-                       // Empty line. End of grouping, reset curPath context
                        fmt.Println(string(line))
-                       curPath = ""
+
+                       // If not continuation or context boundary seperation, reset path context
+                       if !lineContinuationRe.Match(colorlessLine) && !lineSeperatorRe.Match(colorlessLine) {
+                               curPath = ""
+                       }
                }
        }

This is working well for the ag backend, but the rg backend is broken.

Potentially later I'll fix this the correct way and make it work with rg, but for now I thought I'd at least contribute this workaround as a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants