@@ -110,31 +110,73 @@ func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
110110 code = removeEverythingAfterClosingRoundBracket (code )
111111 // Get how many characters are "missing"
112112 n := strings .Index (prototype , code )
113+ line := 0
113114 // Add these characters to "code" string
114- code = getFunctionProtoWithNPreviousCharacters (tag , code , n )
115+ code , line = getFunctionProtoWithNPreviousCharacters (tag , code , n )
115116 // Check again for perfect matching
116117 ret = strings .Index (code , prototype )
118+ if ret != - 1 {
119+ tag .Line = line
120+ }
117121 }
118122
119123 return ret == - 1
120124}
121125
126+ func findTemplateMultiline (tag * types.CTag ) string {
127+ code , _ := getFunctionProtoUntilTemplateToken (tag , tag .Code )
128+ return removeEverythingAfterClosingRoundBracket (code )
129+ }
130+
122131func removeEverythingAfterClosingRoundBracket (s string ) string {
123132 n := strings .Index (s , ")" )
124133 return s [0 : n + 1 ]
125134}
126135
127- func getFunctionProtoWithNPreviousCharacters (tag * types.CTag , code string , n int ) string {
136+ func getFunctionProtoUntilTemplateToken (tag * types.CTag , code string ) (string , int ) {
137+
138+ /* FIXME I'm ugly */
139+ line := 0
140+
141+ file , err := os .Open (tag .Filename )
142+ if err == nil {
143+ defer file .Close ()
144+
145+ scanner := bufio .NewScanner (file )
146+ multilinecomment := false
147+ var textBuffer []string
148+
149+ // buffer lines until we get to the start of this tag
150+ for scanner .Scan () && line < (tag .Line - 1 ) {
151+ line ++
152+ text := scanner .Text ()
153+ textBuffer = append (textBuffer , text )
154+ }
155+
156+ for line > 0 && ! strings .Contains (code , TEMPLATE ) {
157+
158+ line = line - 1
159+ text := textBuffer [line ]
160+
161+ text , multilinecomment = removeComments (text , multilinecomment )
162+
163+ code = text + code
164+ }
165+ }
166+ return code , line
167+ }
168+
169+ func getFunctionProtoWithNPreviousCharacters (tag * types.CTag , code string , n int ) (string , int ) {
128170
129171 /* FIXME I'm ugly */
130172 expectedPrototypeLen := len (code ) + n
173+ line := 0
131174
132175 file , err := os .Open (tag .Filename )
133176 if err == nil {
134177 defer file .Close ()
135178
136179 scanner := bufio .NewScanner (file )
137- line := 0
138180 multilinecomment := false
139181 var textBuffer []string
140182
@@ -156,7 +198,7 @@ func getFunctionProtoWithNPreviousCharacters(tag *types.CTag, code string, n int
156198 code = removeSpacesAndTabs (code )
157199 }
158200 }
159- return code
201+ return code , line
160202}
161203
162204func removeComments (text string , multilinecomment bool ) (string , bool ) {
0 commit comments