File tree 3 files changed +12
-6
lines changed
3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -53,13 +53,16 @@ var KNOWN_TAG_KINDS = map[string]bool{
53
53
}
54
54
55
55
type CTagsParser struct {
56
- tags []* types.CTag
56
+ tags []* types.CTag
57
+ mainFile string
57
58
}
58
59
59
- func (p * CTagsParser ) Parse (ctagsOutput string ) []* types.CTag {
60
+ func (p * CTagsParser ) Parse (ctagsOutput string , mainFile string ) []* types.CTag {
60
61
rows := strings .Split (ctagsOutput , "\n " )
61
62
rows = removeEmpty (rows )
62
63
64
+ p .mainFile = mainFile
65
+
63
66
for _ , row := range rows {
64
67
p .tags = append (p .tags , parseTag (row ))
65
68
}
Original file line number Diff line number Diff line change @@ -48,10 +48,12 @@ func (p *CTagsParser) findLineWhereToInsertPrototypes() int {
48
48
} else {
49
49
return firstFunctionPointerAsArgument
50
50
}
51
- } else if firstFunctionLine == - 1 {
51
+ } else if firstFunctionLine != - 1 {
52
+ return firstFunctionLine
53
+ } else if firstFunctionPointerAsArgument != - 1 {
52
54
return firstFunctionPointerAsArgument
53
55
} else {
54
- return firstFunctionLine
56
+ return 0
55
57
}
56
58
}
57
59
@@ -86,7 +88,7 @@ func (p *CTagsParser) collectFunctionNames() []string {
86
88
87
89
func (p * CTagsParser ) firstFunctionAtLine () int {
88
90
for _ , tag := range p .tags {
89
- if ! tagIsUnknown (tag ) && isHandled (tag ) && tag .Kind == KIND_FUNCTION {
91
+ if ! tagIsUnknown (tag ) && isHandled (tag ) && tag .Kind == KIND_FUNCTION && tag . Filename == p . mainFile {
90
92
return tag .Line
91
93
}
92
94
}
Original file line number Diff line number Diff line change @@ -74,7 +74,8 @@ func (s *CTagsRunner) Run(ctx *types.Context) error {
74
74
ctx .CTagsOutput = string (sourceBytes )
75
75
76
76
parser := & ctags.CTagsParser {}
77
- ctx .CTagsOfPreprocessedSource = parser .Parse (ctx .CTagsOutput )
77
+ ctx .CTagsOfPreprocessedSource = parser .Parse (ctx .CTagsOutput , ctx .Sketch .MainFile .Name )
78
+
78
79
protos , line := parser .GeneratePrototypes ()
79
80
if line != - 1 {
80
81
ctx .PrototypesLineWhereToInsert = line
You can’t perform that action at this time.
0 commit comments