@@ -150,17 +150,16 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
150150 log .Printf (" > %s -> '%s'" , change .Range , strconv .Quote (change .Text ))
151151 }
152152
153- res , err := handler .didChange (ctx , p )
154- if err != nil {
153+ if res , err := handler .didChange (ctx , p ); err != nil {
155154 log .Printf (" --E error: %s" , err )
156155 return nil , err
157- }
158- if res == nil {
156+ } else if res == nil {
159157 log .Println (" --X notification is not propagated to clangd" )
160158 return nil , err // do not propagate to clangd
159+ } else {
160+ p = res
161161 }
162162
163- p = res
164163 log .Printf (" --> didChange(%s@%d)" , p .TextDocument .URI , p .TextDocument .Version )
165164 for _ , change := range p .ContentChanges {
166165 log .Printf (" > %s -> '%s'" , change .Range , strconv .Quote (change .Text ))
@@ -432,11 +431,13 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
432431 if trackedDoc .Version + 1 != doc .Version {
433432 return nil , errors .Errorf ("document out-of-sync: expected version %d but got %d" , trackedDoc .Version + 1 , doc .Version )
434433 }
435- trackedDoc .Version ++
434+ for _ , change := range req .ContentChanges {
435+ textutils .ApplyLSPTextDocumentContentChangeEvent (trackedDoc , & change )
436+ }
436437
438+ // If changes are applied to a .ino file we increment the global .ino.cpp versioning
439+ // for each increment of the single .ino file.
437440 if doc .URI .AsPath ().Ext () == ".ino" {
438- // If changes are applied to a .ino file we increment the global .ino.cpp versioning
439- // for each increment of the single .ino file.
440441
441442 cppChanges := []lsp.TextDocumentContentChangeEvent {}
442443 for _ , inoChange := range req .ContentChanges {
@@ -475,14 +476,15 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
475476 },
476477 }
477478 return cppReq , nil
478- } else {
479-
480- // TODO
481- return nil , unknownURI (doc .URI )
482-
483479 }
484480
485- return nil , unknownURI (doc .URI )
481+ // If changes are applied to other files pass them by converting just the URI
482+ cppReq := & lsp.DidChangeTextDocumentParams {
483+ TextDocument : req .TextDocument ,
484+ ContentChanges : req .ContentChanges ,
485+ }
486+ err := handler .sketchToBuildPathTextDocumentIdentifier (& cppReq .TextDocument .TextDocumentIdentifier )
487+ return cppReq , err
486488}
487489
488490func (handler * InoHandler ) updateFileData (ctx context.Context , data * FileData , change * lsp.TextDocumentContentChangeEvent ) (err error ) {
0 commit comments