Skip to content

Commit 5ee9731

Browse files
committed
Handle ctags failing to report the correct line number
1 parent 71dd136 commit 5ee9731

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Diff for: ls/ls_clang_to_ide.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (ls *INOLanguageServer) clang2IdeRangeAndDocumentURI(logger jsonrpc.Functio
3535
if inPreprocessed {
3636
logger.Logf("Range is in PREPROCESSED section of the sketch")
3737
}
38-
logger.Logf("Range: %s:%s -> %s:%s", clangURI, clangRange, ideURI, ideRange)
38+
logger.Logf("Range: %s:%s -> %s:%s (.ino)", clangURI, clangRange, ideURI, ideRange)
3939
return ideURI, ideRange, inPreprocessed, err
4040
}
4141

@@ -49,7 +49,7 @@ func (ls *INOLanguageServer) clang2IdeRangeAndDocumentURI(logger jsonrpc.Functio
4949
}
5050
if !inside {
5151
ideURI := clangURI
52-
logger.Logf("Range: %s:%s -> %s:%s", clangURI, clangRange, ideURI, ideRange)
52+
logger.Logf("Range: %s:%s -> %s:%s (ext file)", clangURI, clangRange, ideURI, ideRange)
5353
return clangURI, clangRange, false, nil
5454
}
5555

@@ -67,7 +67,7 @@ func (ls *INOLanguageServer) clang2IdeRangeAndDocumentURI(logger jsonrpc.Functio
6767
if ideRange.Start.Line > 0 {
6868
ideRange.Start.Line--
6969
}
70-
logger.Logf("Range: %s:%s -> %s:%s", clangURI, clangRange, ideURI, ideRange)
70+
logger.Logf("Range: %s:%s -> %s:%s (.cpp/.h)", clangURI, clangRange, ideURI, ideRange)
7171
return ideURI, ideRange, false, err
7272
}
7373

Diff for: sourcemapper/ino.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ func (s *SketchMapper) regeneratehMapping() {
177177
sourceFile = paths.New(unquoteCppString(tokens[2])).Canonical().String()
178178
s.cppToIno[targetLine] = NotIno
179179
} else if sourceFile != "" {
180-
s.mapLine(sourceFile, sourceLine, targetLine)
180+
// Sometimes the Arduino preprocessor fails to interpret correctly the code
181+
// and may report a "#line 0" directive leading to a negative sourceLine.
182+
// In this rare cases just interpret the source line as a NotIno line.
183+
if sourceLine >= 0 {
184+
s.mapLine(sourceFile, sourceLine, targetLine)
185+
} else {
186+
s.cppToIno[targetLine] = NotIno
187+
}
181188
sourceLine++
182189
} else {
183190
s.cppToIno[targetLine] = NotIno

0 commit comments

Comments
 (0)