@@ -1047,7 +1047,7 @@ func (ls *INOLanguageServer) TextDocumentDidChangeNotifFromIDE(logger jsonrpc.Fu
1047
1047
return
1048
1048
} else {
1049
1049
ls .trackedIdeDocs [trackedIdeDocID ] = updatedDoc
1050
- logger .Logf ("Tracked SKETCH file: ----------+ \n " + updatedDoc .Text + "\n ----------------------" )
1050
+ logger .Logf ("----- Tracked SKETCH file-----\n " + updatedDoc .Text + "\n ------- ----------------------" )
1051
1051
}
1052
1052
1053
1053
clangChanges := []lsp.TextDocumentContentChangeEvent {}
@@ -1129,21 +1129,41 @@ func (ls *INOLanguageServer) TextDocumentDidCloseNotifFromIDE(logger jsonrpc.Fun
1129
1129
1130
1130
ls .triggerRebuild ()
1131
1131
1132
- logger .Logf ("didClose(%s)" , ideParams .TextDocument )
1133
-
1134
- if clangParams , err := ls .didClose (logger , ideParams ); err != nil {
1135
- logger .Logf ("--E Error: %s" , err )
1136
- } else if clangParams == nil {
1137
- logger .Logf ("--X Notification is not propagated to clangd" )
1132
+ inoIdentifier := ideParams .TextDocument
1133
+ if _ , exist := ls .trackedIdeDocs [inoIdentifier .URI .AsPath ().String ()]; exist {
1134
+ delete (ls .trackedIdeDocs , inoIdentifier .URI .AsPath ().String ())
1138
1135
} else {
1139
- logger .Logf ("--> CL NOTIF didClose(%s)" , clangParams .TextDocument )
1140
- if err := ls .Clangd .conn .TextDocumentDidClose (clangParams ); err != nil {
1141
- // Exit the process and trigger a restart by the client in case of a severe error
1142
- logger .Logf ("Error sending notification to clangd server: %v" , err )
1143
- logger .Logf ("Please restart the language server." )
1144
- ls .Close ()
1136
+ logger .Logf ("didClose of untracked document: %s" , inoIdentifier .URI )
1137
+ return
1138
+ }
1139
+
1140
+ // If we are tracking a .ino...
1141
+ if inoIdentifier .URI .Ext () == ".ino" {
1142
+ ls .sketchTrackedFilesCount --
1143
+ logger .Logf ("decreasing .ino tracked files count: %d" , ls .sketchTrackedFilesCount )
1144
+
1145
+ // notify clang that sketch.cpp.ino has been closed only once all .ino are closed
1146
+ if ls .sketchTrackedFilesCount != 0 {
1147
+ logger .Logf ("--X Notification is not propagated to clangd" )
1148
+ return
1145
1149
}
1146
1150
}
1151
+
1152
+ clangIdentifier , err := ls .ide2ClangTextDocumentIdentifier (logger , inoIdentifier )
1153
+ if err != nil {
1154
+ logger .Logf ("Error: %s" , err )
1155
+ }
1156
+ clangParams := & lsp.DidCloseTextDocumentParams {
1157
+ TextDocument : clangIdentifier ,
1158
+ }
1159
+
1160
+ logger .Logf ("--> didClose(%s)" , clangParams .TextDocument )
1161
+ if err := ls .Clangd .conn .TextDocumentDidClose (clangParams ); err != nil {
1162
+ // Exit the process and trigger a restart by the client in case of a severe error
1163
+ logger .Logf ("Error sending notification to clangd server: %v" , err )
1164
+ logger .Logf ("Please restart the language server." )
1165
+ ls .Close ()
1166
+ }
1147
1167
}
1148
1168
1149
1169
func (ls * INOLanguageServer ) PublishDiagnosticsNotifFromClangd (logger jsonrpc.FunctionLogger , clangParams * lsp.PublishDiagnosticsParams ) {
@@ -1319,32 +1339,6 @@ func (ls *INOLanguageServer) extractDataFolderFromArduinoCLI(logger jsonrpc.Func
1319
1339
}
1320
1340
}
1321
1341
1322
- func (ls * INOLanguageServer ) didClose (logger jsonrpc.FunctionLogger , ideParams * lsp.DidCloseTextDocumentParams ) (* lsp.DidCloseTextDocumentParams , error ) {
1323
- inoIdentifier := ideParams .TextDocument
1324
- if _ , exist := ls .trackedIdeDocs [inoIdentifier .URI .AsPath ().String ()]; exist {
1325
- delete (ls .trackedIdeDocs , inoIdentifier .URI .AsPath ().String ())
1326
- } else {
1327
- logger .Logf (" didClose of untracked document: %s" , inoIdentifier .URI )
1328
- return nil , & UnknownURI {inoIdentifier .URI }
1329
- }
1330
-
1331
- // If we are tracking a .ino...
1332
- if inoIdentifier .URI .Ext () == ".ino" {
1333
- ls .sketchTrackedFilesCount --
1334
- logger .Logf (" decreasing .ino tracked files count: %d" , ls .sketchTrackedFilesCount )
1335
-
1336
- // notify clang that sketch.cpp.ino has been closed only once all .ino are closed
1337
- if ls .sketchTrackedFilesCount != 0 {
1338
- return nil , nil
1339
- }
1340
- }
1341
-
1342
- cppIdentifier , err := ls .ide2ClangTextDocumentIdentifier (logger , inoIdentifier )
1343
- return & lsp.DidCloseTextDocumentParams {
1344
- TextDocument : cppIdentifier ,
1345
- }, err
1346
- }
1347
-
1348
1342
func (ls * INOLanguageServer ) clang2IdeCodeAction (logger jsonrpc.FunctionLogger , clangCodeAction lsp.CodeAction , origIdeURI lsp.DocumentURI ) * lsp.CodeAction {
1349
1343
ideCodeAction := & lsp.CodeAction {
1350
1344
Title : clangCodeAction .Title ,
0 commit comments