Skip to content

One way to handle multi-line prototypes in arduino files #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/arduino.cc/builder/ctags/ctags_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"runtime"
"strconv"
"strings"
"bufio"
)

const KIND_PROTOTYPE = "prototype"
Expand Down Expand Up @@ -154,6 +155,35 @@ func prototypeAndCodeDontMatch(tag *types.CTag) bool {
}

code := removeSpacesAndTabs(tag.Code)

// original code is multi-line, which tags doesn't have - could we find this code in the
// original source file, for purposes of checking here?
if strings.Index(code, ")") == -1 {
file, err := os.Open(tag.Filename)
if err == nil {
defer file.Close()

scanner := bufio.NewScanner(file)
line := 1

// skip lines until we get to the start of this tag
for scanner.Scan() && line < tag.Line {
line++;
}

// read up to 10 lines in search of a closing paren
newcode := scanner.Text()
for scanner.Scan() && line < (tag.Line + 10) && strings.Index(newcode, ")") == -1 {
newcode += scanner.Text()
}

// don't bother replacing the code text if we haven't found a closing paren
if strings.Index(newcode, ")") != -1 {
code = removeSpacesAndTabs(newcode)
}
}
}

prototype := removeSpacesAndTabs(tag.Prototype)
prototype = removeTralingSemicolon(prototype)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
void setup() { myctagstestfunc(1,2,3,4); }

void myctagstestfunc(int a,
int b,
int c,
int d) { }

void loop() {}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func TestTryBuild035(t *testing.T) {
tryBuild(t, "sketch_with_enum_class", "sketch_with_enum_class.ino")
}

func TestTryBuild036(t *testing.T) {
tryBuild(t, "sketch_with_multiline_prototypes", "sketch_with_multiline_prototypes.ino")
}

func makeDefaultContext(t *testing.T) map[string]interface{} {
DownloadCoresAndToolsAndLibraries(t)

Expand Down