@@ -150,17 +150,16 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
150
150
log .Printf (" > %s -> '%s'" , change .Range , strconv .Quote (change .Text ))
151
151
}
152
152
153
- res , err := handler .didChange (ctx , p )
154
- if err != nil {
153
+ if res , err := handler .didChange (ctx , p ); err != nil {
155
154
log .Printf (" --E error: %s" , err )
156
155
return nil , err
157
- }
158
- if res == nil {
156
+ } else if res == nil {
159
157
log .Println (" --X notification is not propagated to clangd" )
160
158
return nil , err // do not propagate to clangd
159
+ } else {
160
+ p = res
161
161
}
162
162
163
- p = res
164
163
log .Printf (" --> didChange(%s@%d)" , p .TextDocument .URI , p .TextDocument .Version )
165
164
for _ , change := range p .ContentChanges {
166
165
log .Printf (" > %s -> '%s'" , change .Range , strconv .Quote (change .Text ))
@@ -432,11 +431,13 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
432
431
if trackedDoc .Version + 1 != doc .Version {
433
432
return nil , errors .Errorf ("document out-of-sync: expected version %d but got %d" , trackedDoc .Version + 1 , doc .Version )
434
433
}
435
- trackedDoc .Version ++
434
+ for _ , change := range req .ContentChanges {
435
+ textutils .ApplyLSPTextDocumentContentChangeEvent (trackedDoc , & change )
436
+ }
436
437
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.
437
440
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.
440
441
441
442
cppChanges := []lsp.TextDocumentContentChangeEvent {}
442
443
for _ , inoChange := range req .ContentChanges {
@@ -475,14 +476,15 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
475
476
},
476
477
}
477
478
return cppReq , nil
478
- } else {
479
-
480
- // TODO
481
- return nil , unknownURI (doc .URI )
482
-
483
479
}
484
480
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
486
488
}
487
489
488
490
func (handler * InoHandler ) updateFileData (ctx context.Context , data * FileData , change * lsp.TextDocumentContentChangeEvent ) (err error ) {
0 commit comments