diff --git a/is.go b/is.go index c363c82..b51b110 100644 --- a/is.go +++ b/is.go @@ -258,17 +258,19 @@ func loadComment(path string, line int) (string, bool) { s := bufio.NewScanner(f) i := 1 for s.Scan() { - if i == line { - text := s.Text() - commentI := strings.Index(text, "// ") - if commentI == -1 { - return "", false // no comment - } - text = text[commentI+2:] - text = strings.TrimSpace(text) - return text, true + if i != line { + i++ + continue + } + + text := s.Text() + commentI := strings.Index(text, "// ") + if commentI == -1 { + return "", false // no comment } - i++ + text = text[commentI+2:] + text = strings.TrimSpace(text) + return text, true } return "", false } @@ -284,33 +286,34 @@ func loadArguments(path string, line int) (string, bool) { s := bufio.NewScanner(f) i := 1 for s.Scan() { - if i == line { - text := s.Text() - braceI := strings.Index(text, "(") - if braceI == -1 { - return "", false + if i != line { + i++ + continue + } + text := s.Text() + braceI := strings.Index(text, "(") + if braceI == -1 { + return "", false + } + text = text[braceI+1:] + cs := bufio.NewScanner(strings.NewReader(text)) + cs.Split(bufio.ScanBytes) + j := 0 + c := 1 + for cs.Scan() { + switch cs.Text() { + case ")": + c-- + case "(": + c++ } - text = text[braceI+1:] - cs := bufio.NewScanner(strings.NewReader(text)) - cs.Split(bufio.ScanBytes) - j := 0 - c := 1 - for cs.Scan() { - switch cs.Text() { - case ")": - c-- - case "(": - c++ - } - if c == 0 { - break - } - j++ + if c == 0 { + break } - text = text[:j] - return text, true + j++ } - i++ + text = text[:j] + return text, true } return "", false }