From 4ce6b9e8e84f60bbf157c216c5bf32eb19177236 Mon Sep 17 00:00:00 2001
From: Edgar HIPP <hipp.edg@gmail.com>
Date: Sat, 16 Jan 2016 07:06:50 +0100
Subject: [PATCH] Getting line number now works

---
 extractor.go | 17 ++++++++++++++---
 pe_test.go   | 14 +++++++++++++-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/extractor.go b/extractor.go
index 326855c..c19b7d5 100644
--- a/extractor.go
+++ b/extractor.go
@@ -32,6 +32,7 @@ func postProcess(input string) string {
 func GetAllMatches(input string, options MatchOptions) []string {
 	result := []string{}
 	candidatePath := string("")
+	restOfLine := string("")
 	indexes := pathExtractor(input)
 	for _, index := range indexes {
 		candidatePath = input[index[0]:index[1]]
@@ -46,12 +47,22 @@ func GetAllMatches(input string, options MatchOptions) []string {
 			candidatePath = replaceGitPath(candidatePath)
 		}
 		candidatePath = postProcess(candidatePath)
-		lineNumber := 45
-		columnNumber := 1
 		if options.format == "ackmate" {
-			candidatePath = fmt.Sprint(candidatePath, ":", lineNumber, ":", columnNumber)
+			restOfLine = input[index[1]:]
+			cursorPos := getCursorPosition(restOfLine)
+			candidatePath = fmt.Sprint(candidatePath, cursorPos)
 		}
 		result = append(result, candidatePath)
 	}
 	return result
 }
+
+func getCursorPosition(input string) string {
+	r := regexp.MustCompile("^(:[0-9]+(:[0-9]+)?)$")
+	temp := [][]byte{}
+	temp = r.FindSubmatch([]byte(input))
+	if len(temp) <= 1 {
+		return ""
+	}
+	return string(temp[1])
+}
diff --git a/pe_test.go b/pe_test.go
index 7e52783..3f24886 100644
--- a/pe_test.go
+++ b/pe_test.go
@@ -183,7 +183,19 @@ func TestEverything(t *testing.T) {
 	if output[0] == "test.js" {
 		t.Errorf("Ackmate should not forget number", output)
 	}
-	if output[0] != "test.js:45:1" {
+	if output[0] != "test.js:45" {
+		t.Errorf("Ackmate should output right line number", output)
+	}
+
+	output = GetAllMatches("test.js:45:12", MatchOptions{format: "ackmate"})
+	if len(output) != 1 {
+		t.Errorf("Ackmate doesnt match", output)
+	}
+
+	if output[0] == "test.js" {
+		t.Errorf("Ackmate should not forget number", output)
+	}
+	if output[0] != "test.js:45:12" {
 		t.Errorf("Ackmate should output right line number", output)
 	}
 }
-- 
2.51.0