Skip to content

Commit fbfaa56

Browse files
focalintentfacchinm
authored andcommitted
bypass ctags limitations by extracting complete prototype from source file
A somewhat heavy handed way to deal with #80 - if we detect that the code for a tag is multiline (that is, there's no closing paren), use the Filename/Line info in the tag to attempt to read a few lines from the original code to hopefully get a better block of code to look for the prototype in.
1 parent fc8856c commit fbfaa56

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/arduino.cc/builder/ctags/ctags_parser.go

+30
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"runtime"
3939
"strconv"
4040
"strings"
41+
"bufio"
4142
)
4243

4344
const KIND_PROTOTYPE = "prototype"
@@ -158,6 +159,35 @@ func prototypeAndCodeDontMatch(tag *types.CTag) bool {
158159
}
159160

160161
code := removeSpacesAndTabs(tag.Code)
162+
163+
// original code is multi-line, which tags doesn't have - could we find this code in the
164+
// original source file, for purposes of checking here?
165+
if strings.Index(code, ")") == -1 {
166+
file, err := os.Open(tag.Filename)
167+
if err == nil {
168+
defer file.Close()
169+
170+
scanner := bufio.NewScanner(file)
171+
line := 1
172+
173+
// skip lines until we get to the start of this tag
174+
for scanner.Scan() && line < tag.Line {
175+
line++;
176+
}
177+
178+
// read up to 10 lines in search of a closing paren
179+
newcode := scanner.Text()
180+
for scanner.Scan() && line < (tag.Line + 10) && strings.Index(newcode, ")") == -1 {
181+
newcode += scanner.Text()
182+
}
183+
184+
// don't bother replacing the code text if we haven't found a closing paren
185+
if strings.Index(newcode, ")") != -1 {
186+
code = removeSpacesAndTabs(newcode)
187+
}
188+
}
189+
}
190+
161191
prototype := removeSpacesAndTabs(tag.Prototype)
162192
prototype = removeTralingSemicolon(prototype)
163193

0 commit comments

Comments
 (0)