@@ -27,12 +27,16 @@ func (ls *INOLanguageServer) clangURIRefersToIno(clangURI lsp.DocumentURI) bool
27
27
return clangURI .AsPath ().EquivalentTo (ls .buildSketchCpp )
28
28
}
29
29
30
+ func (ls * INOLanguageServer ) clang2IdeRangeAndDocumentURI (logger jsonrpc.FunctionLogger , clangURI lsp.DocumentURI , clangRange lsp.Range ) (lsp.DocumentURI , lsp.Range , bool , error ) {
31
+ return ls .clang2IdeRangeAndDocumentURI2 (logger , clangURI , clangRange , nil )
32
+ }
33
+
30
34
// Convert Range and DocumentURI from Clang to IDE.
31
35
// Returns:
32
36
// - The IDE DocumentURI and Range
33
37
// - a boolean that is true if the clang range is in the preprocessed area of the sketch
34
38
// - an error
35
- func (ls * INOLanguageServer ) clang2IdeRangeAndDocumentURI (logger jsonrpc.FunctionLogger , clangURI lsp.DocumentURI , clangRange lsp.Range ) (lsp.DocumentURI , lsp.Range , bool , error ) {
39
+ func (ls * INOLanguageServer ) clang2IdeRangeAndDocumentURI2 (logger jsonrpc.FunctionLogger , clangURI lsp.DocumentURI , clangRange lsp.Range , opts * translationOpts ) (lsp.DocumentURI , lsp.Range , bool , error ) {
36
40
// Sketchbook/Sketch/Sketch.ino <-> build-path/sketch/Sketch.ino.cpp
37
41
// Sketchbook/Sketch/AnotherTab.ino <-> build-path/sketch/Sketch.ino.cpp (different section from above)
38
42
if ls .clangURIRefersToIno (clangURI ) {
@@ -80,7 +84,25 @@ func (ls *INOLanguageServer) clang2IdeRangeAndDocumentURI(logger jsonrpc.Functio
80
84
return lsp .NilURI , lsp .NilRange , false , err
81
85
}
82
86
idePath := ls .sketchRoot .JoinPath (rel ).String ()
83
- ideURI , err := ls .idePathToIdeURI (logger , idePath )
87
+
88
+ var ideURI lsp.DocumentURI
89
+ if opts == nil || ! opts .loadRelToIde {
90
+ ideURI , err = ls .idePathToIdeURI (logger , idePath )
91
+ } else {
92
+ doc , ok := ls .trackedIdeDocs [idePath ]
93
+ if ! ok {
94
+ var shouldOpen bool
95
+ doc , shouldOpen , err = makeTextDocumentItem (logger , idePath )
96
+ if err != nil {
97
+ logger .Logf ("ERROR: could not open '%s': %s" , idePath , err )
98
+ }
99
+ if shouldOpen {
100
+ ls .implTextDocumentDidOpenNotifFromIDE (logger , doc )
101
+ }
102
+
103
+ }
104
+ ideURI = doc .URI
105
+ }
84
106
if ideRange .End .Line > 0 {
85
107
ideRange .End .Line --
86
108
}
@@ -296,9 +318,12 @@ func (ls *INOLanguageServer) cland2IdeTextEdits(logger jsonrpc.FunctionLogger, c
296
318
}
297
319
298
320
func (ls * INOLanguageServer ) clang2IdeLocationsArray (logger jsonrpc.FunctionLogger , clangLocations []lsp.Location ) ([]lsp.Location , error ) {
321
+ return ls .clang2IdeLocationsArray2 (logger , clangLocations , nil )
322
+ }
323
+ func (ls * INOLanguageServer ) clang2IdeLocationsArray2 (logger jsonrpc.FunctionLogger , clangLocations []lsp.Location , opts * translationOpts ) ([]lsp.Location , error ) {
299
324
ideLocations := []lsp.Location {}
300
325
for _ , clangLocation := range clangLocations {
301
- ideLocation , inPreprocessed , err := ls .clang2IdeLocation (logger , clangLocation )
326
+ ideLocation , inPreprocessed , err := ls .clang2IdeLocation2 (logger , clangLocation , opts )
302
327
if err != nil {
303
328
logger .Logf ("ERROR converting location %s: %s" , clangLocation , err )
304
329
return nil , err
@@ -313,7 +338,10 @@ func (ls *INOLanguageServer) clang2IdeLocationsArray(logger jsonrpc.FunctionLogg
313
338
}
314
339
315
340
func (ls * INOLanguageServer ) clang2IdeLocation (logger jsonrpc.FunctionLogger , clangLocation lsp.Location ) (lsp.Location , bool , error ) {
316
- ideURI , ideRange , inPreprocessed , err := ls .clang2IdeRangeAndDocumentURI (logger , clangLocation .URI , clangLocation .Range )
341
+ return ls .clang2IdeLocation2 (logger , clangLocation , nil )
342
+ }
343
+ func (ls * INOLanguageServer ) clang2IdeLocation2 (logger jsonrpc.FunctionLogger , clangLocation lsp.Location , opts * translationOpts ) (lsp.Location , bool , error ) {
344
+ ideURI , ideRange , inPreprocessed , err := ls .clang2IdeRangeAndDocumentURI2 (logger , clangLocation .URI , clangLocation .Range , opts )
317
345
return lsp.Location {
318
346
URI : ideURI ,
319
347
Range : ideRange ,
0 commit comments