@@ -160,6 +160,19 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
160
160
params = res
161
161
}
162
162
163
+ case * lsp.DidCloseTextDocumentParams :
164
+ // Method: "textDocument/didClose"
165
+ inoURI = p .TextDocument .URI
166
+ log .Printf ("--> didClose(%s)" , p .TextDocument .URI )
167
+
168
+ if res , e := handler .didClose (p ); e != nil {
169
+ } else if res == nil {
170
+ log .Println (" --X notification is not propagated to clangd" )
171
+ return nil , nil // do not propagate to clangd
172
+ } else {
173
+ log .Printf (" --> didClose(%s)" , res .TextDocument .URI )
174
+ params = res
175
+ }
163
176
164
177
case * lsp.DidChangeTextDocumentParams :
165
178
// notification "textDocument/didChange"
@@ -285,12 +298,6 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
285
298
}
286
299
log .Printf (" --> %s(%s)" , req .Method , p .TextDocument .URI )
287
300
288
- case * lsp.DidCloseTextDocumentParams : // "textDocument/didClose":
289
- log .Printf ("--X " + req .Method )
290
- return nil , nil
291
- // uri = p.TextDocument.URI
292
- // err = handler.sketchToBuildPathTextDocumentIdentifier(&p.TextDocument)
293
- // handler.deleteFileData(uri)
294
301
case * lsp.ReferenceParams : // "textDocument/references":
295
302
log .Printf ("--X " + req .Method )
296
303
return nil , nil
@@ -557,6 +564,32 @@ func (handler *InoHandler) didOpen(inoDidOpen *lsp.DidOpenTextDocumentParams) (*
557
564
}, err
558
565
}
559
566
567
+ func (handler * InoHandler ) didClose (inoDidClose * lsp.DidCloseTextDocumentParams ) (* lsp.DidCloseTextDocumentParams , error ) {
568
+ inoIdentifier := inoDidClose .TextDocument
569
+ if _ , exist := handler .docs [inoIdentifier .URI ]; exist {
570
+ delete (handler .docs , inoIdentifier .URI )
571
+ } else {
572
+ log .Printf (" didClose of untracked document: %s" , inoIdentifier .URI )
573
+ return nil , unknownURI (inoIdentifier .URI )
574
+ }
575
+
576
+ // If we are tracking a .ino...
577
+ if inoIdentifier .URI .Ext () == ".ino" {
578
+ handler .sketchTrackedFilesCount --
579
+ log .Printf (" decreasing .ino tracked files count: %d" , handler .sketchTrackedFilesCount )
580
+
581
+ // notify clang that sketchCpp has been close only once all .ino are closed
582
+ if handler .sketchTrackedFilesCount != 0 {
583
+ return nil , nil
584
+ }
585
+ }
586
+
587
+ cppIdentifier , err := handler .ino2cppTextDocumentIdentifier (inoIdentifier )
588
+ return & lsp.DidCloseTextDocumentParams {
589
+ TextDocument : cppIdentifier ,
590
+ }, err
591
+ }
592
+
560
593
func (handler * InoHandler ) ino2cppTextDocumentItem (inoItem lsp.TextDocumentItem ) (cppItem lsp.TextDocumentItem , err error ) {
561
594
cppURI , err := handler .ino2cppDocumentURI (inoItem .URI )
562
595
if err != nil {
0 commit comments