Skip to content

Commit 357cf1e

Browse files
committed
A somewhat heavy handed way to deal with arduino#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 bf70c66 commit 357cf1e

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"
@@ -154,6 +155,35 @@ func prototypeAndCodeDontMatch(tag *types.CTag) bool {
154155
}
155156

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

0 commit comments

Comments
 (0)