@@ -1047,7 +1047,7 @@ func (ls *INOLanguageServer) TextDocumentDidChangeNotifFromIDE(logger jsonrpc.Fu
10471047 return
10481048 } else {
10491049 ls .trackedIdeDocs [trackedIdeDocID ] = updatedDoc
1050- logger .Logf ("Tracked SKETCH file: ----------+ \n " + updatedDoc .Text + "\n ----------------------" )
1050+ logger .Logf ("----- Tracked SKETCH file-----\n " + updatedDoc .Text + "\n ------- ----------------------" )
10511051 }
10521052
10531053 clangChanges := []lsp.TextDocumentContentChangeEvent {}
@@ -1129,21 +1129,41 @@ func (ls *INOLanguageServer) TextDocumentDidCloseNotifFromIDE(logger jsonrpc.Fun
11291129
11301130 ls .triggerRebuild ()
11311131
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 ())
11381135 } 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
11451149 }
11461150 }
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+ }
11471167}
11481168
11491169func (ls * INOLanguageServer ) PublishDiagnosticsNotifFromClangd (logger jsonrpc.FunctionLogger , clangParams * lsp.PublishDiagnosticsParams ) {
@@ -1319,32 +1339,6 @@ func (ls *INOLanguageServer) extractDataFolderFromArduinoCLI(logger jsonrpc.Func
13191339 }
13201340}
13211341
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-
13481342func (ls * INOLanguageServer ) clang2IdeCodeAction (logger jsonrpc.FunctionLogger , clangCodeAction lsp.CodeAction , origIdeURI lsp.DocumentURI ) * lsp.CodeAction {
13491343 ideCodeAction := & lsp.CodeAction {
13501344 Title : clangCodeAction .Title ,
0 commit comments