@@ -892,12 +892,12 @@ func (ls *INOLanguageServer) TextDocumentDidSaveNotifFromIDE(logger jsonrpc.Func
892
892
ls .writeLock (logger , true )
893
893
defer ls .writeUnlock (logger )
894
894
895
- logger .Logf ("didSave(%s)" , inoParams .TextDocument )
895
+ logger .Logf ("didSave(%s) hasText=%v " , inoParams .TextDocument , inoParams . Text != "" )
896
896
if cppTextDocument , err := ls .ino2cppTextDocumentIdentifier (logger , inoParams .TextDocument ); err != nil {
897
897
logger .Logf ("--E Error: %s" , err )
898
898
} else if cppTextDocument .URI .AsPath ().EquivalentTo (ls .buildSketchCpp ) {
899
899
logger .Logf (" didSave(%s) equals %s" , cppTextDocument , ls .buildSketchCpp )
900
- logger .Logf ("--| didSave not forwarded to clangd" )
900
+ logger .Logf (" the notification will be not forwarded to clangd" )
901
901
} else {
902
902
logger .Logf ("LS --> CL NOTIF didSave(%s)" , cppTextDocument )
903
903
if err := ls .Clangd .conn .TextDocumentDidSave (& lsp.DidSaveTextDocumentParams {
@@ -938,7 +938,7 @@ func (ls *INOLanguageServer) PublishDiagnosticsNotifFromClangd(logger jsonrpc.Fu
938
938
ls .readLock (logger , false )
939
939
defer ls .readUnlock (logger )
940
940
941
- logger .Logf ("publishDiagnostics(%s ):" , cppParams .URI )
941
+ logger .Logf ("from clang %s (%d diagnostics ):" , cppParams .URI , cppParams . Diagnostics )
942
942
for _ , diag := range cppParams .Diagnostics {
943
943
logger .Logf ("> %d:%d - %v: %s" , diag .Range .Start .Line , diag .Range .Start .Character , diag .Severity , diag .Code )
944
944
}
@@ -953,12 +953,10 @@ func (ls *INOLanguageServer) PublishDiagnosticsNotifFromClangd(logger jsonrpc.Fu
953
953
954
954
// Push back to IDE the converted diagnostics
955
955
for _ , inoParams := range allInoParams {
956
- logger .Logf ("to IDE: publishDiagnostics(%s ):" , inoParams .URI )
956
+ logger .Logf ("to IDE: %s (%d diagnostics ):" , inoParams .URI , len ( inoParams . Diagnostics ) )
957
957
for _ , diag := range inoParams .Diagnostics {
958
- logger .Logf ("> %d:%d - %v: %s" , diag .Range .Start .Line , diag .Range .Start .Character , diag .Severity , diag .Code )
958
+ logger .Logf (" > %d:%d - %v: %s" , diag .Range .Start .Line , diag .Range .Start .Character , diag .Severity , diag .Code )
959
959
}
960
- logger .Logf ("IDE <-- LS NOTIF textDocument/publishDiagnostics:" )
961
-
962
960
if err := ls .IDE .conn .TextDocumentPublishDiagnostics (inoParams ); err != nil {
963
961
logger .Logf (" Error sending diagnostics to IDE: %s" , err )
964
962
return
@@ -1265,7 +1263,7 @@ func (ls *INOLanguageServer) didClose(logger jsonrpc.FunctionLogger, inoDidClose
1265
1263
ls .sketchTrackedFilesCount --
1266
1264
logger .Logf (" decreasing .ino tracked files count: %d" , ls .sketchTrackedFilesCount )
1267
1265
1268
- // notify clang that sketchCpp has been close only once all .ino are closed
1266
+ // notify clang that sketch.cpp.ino has been closed only once all .ino are closed
1269
1267
if ls .sketchTrackedFilesCount != 0 {
1270
1268
return nil , nil
1271
1269
}
@@ -1753,31 +1751,50 @@ func (ls *INOLanguageServer) cpp2inoSymbolInformation(syms []lsp.SymbolInformati
1753
1751
panic ("not implemented" )
1754
1752
}
1755
1753
1756
- func (ls * INOLanguageServer ) cpp2inoDiagnostics (logger jsonrpc.FunctionLogger , cppDiags * lsp.PublishDiagnosticsParams ) ([]* lsp.PublishDiagnosticsParams , error ) {
1757
- inoDiagsParam := map [lsp.DocumentURI ]* lsp.PublishDiagnosticsParams {}
1754
+ func (ls * INOLanguageServer ) cpp2inoDiagnostics (logger jsonrpc.FunctionLogger , cppDiagsParams * lsp.PublishDiagnosticsParams ) ([]* lsp.PublishDiagnosticsParams , error ) {
1758
1755
1759
- cppURI := cppDiags .URI
1756
+ cppURI := cppDiagsParams .URI
1760
1757
isSketch := cppURI .AsPath ().EquivalentTo (ls .buildSketchCpp )
1761
- if isSketch {
1762
- for inoURI := range ls .inoDocsWithDiagnostics {
1763
- inoDiagsParam [inoURI ] = & lsp.PublishDiagnosticsParams {
1764
- URI : inoURI ,
1765
- Diagnostics : []lsp.Diagnostic {},
1766
- }
1767
- }
1768
- ls .inoDocsWithDiagnostics = map [lsp.DocumentURI ]bool {}
1769
- } else {
1758
+
1759
+ if ! isSketch {
1770
1760
inoURI , _ , err := ls .cpp2inoDocumentURI (logger , cppURI , lsp .NilRange )
1771
1761
if err != nil {
1772
1762
return nil , err
1773
1763
}
1774
- inoDiagsParam [inoURI ] = & lsp.PublishDiagnosticsParams {
1764
+ inoDiags := []lsp.Diagnostic {}
1765
+ for _ , cppDiag := range cppDiagsParams .Diagnostics {
1766
+ inoURIofConvertedRange , inoRange , err := ls .cpp2inoDocumentURI (logger , cppURI , cppDiag .Range )
1767
+ if err != nil {
1768
+ return nil , err
1769
+ }
1770
+ if inoURIofConvertedRange .String () == sourcemapper .NotInoURI .String () {
1771
+ continue
1772
+ }
1773
+ if inoURIofConvertedRange .String () != inoURI .String () {
1774
+ return nil , fmt .Errorf ("unexpected inoURI %s: it should be %s" , inoURIofConvertedRange , inoURI )
1775
+ }
1776
+ inoDiag := cppDiag
1777
+ inoDiag .Range = inoRange
1778
+ inoDiags = append (inoDiags , inoDiag )
1779
+ }
1780
+ return []* lsp.PublishDiagnosticsParams {
1781
+ {
1782
+ URI : inoURI ,
1783
+ Diagnostics : inoDiags ,
1784
+ },
1785
+ }, nil
1786
+ }
1787
+
1788
+ allInoDiagsParams := map [lsp.DocumentURI ]* lsp.PublishDiagnosticsParams {}
1789
+ for inoURI := range ls .inoDocsWithDiagnostics {
1790
+ allInoDiagsParams [inoURI ] = & lsp.PublishDiagnosticsParams {
1775
1791
URI : inoURI ,
1776
1792
Diagnostics : []lsp.Diagnostic {},
1777
1793
}
1778
1794
}
1795
+ ls .inoDocsWithDiagnostics = map [lsp.DocumentURI ]bool {}
1779
1796
1780
- for _ , cppDiag := range cppDiags .Diagnostics {
1797
+ for _ , cppDiag := range cppDiagsParams .Diagnostics {
1781
1798
inoURI , inoRange , err := ls .cpp2inoDocumentURI (logger , cppURI , cppDiag .Range )
1782
1799
if err != nil {
1783
1800
return nil , err
@@ -1786,39 +1803,37 @@ func (ls *INOLanguageServer) cpp2inoDiagnostics(logger jsonrpc.FunctionLogger, c
1786
1803
continue
1787
1804
}
1788
1805
1789
- inoDiagParam , created := inoDiagsParam [inoURI ]
1790
- if ! created {
1791
- inoDiagParam = & lsp.PublishDiagnosticsParams {
1806
+ inoDiagsParams , ok := allInoDiagsParams [inoURI ]
1807
+ if ! ok {
1808
+ inoDiagsParams = & lsp.PublishDiagnosticsParams {
1792
1809
URI : inoURI ,
1793
1810
Diagnostics : []lsp.Diagnostic {},
1794
1811
}
1795
- inoDiagsParam [inoURI ] = inoDiagParam
1812
+ allInoDiagsParams [inoURI ] = inoDiagsParams
1796
1813
}
1797
1814
1798
1815
inoDiag := cppDiag
1799
1816
inoDiag .Range = inoRange
1800
- inoDiagParam .Diagnostics = append (inoDiagParam .Diagnostics , inoDiag )
1801
-
1802
- if isSketch {
1803
- ls .inoDocsWithDiagnostics [inoURI ] = true
1804
-
1805
- // If we have an "undefined reference" in the .ino code trigger a
1806
- // check for newly created symbols (that in turn may trigger a
1807
- // new arduino-preprocessing of the sketch).
1808
- var inoDiagCode string
1809
- if err := json .Unmarshal (inoDiag .Code , & inoDiagCode ); err != nil {
1810
- if inoDiagCode == "undeclared_var_use_suggest" ||
1811
- inoDiagCode == "undeclared_var_use" ||
1812
- inoDiagCode == "ovl_no_viable_function_in_call" ||
1813
- inoDiagCode == "pp_file_not_found" {
1814
- ls .queueCheckCppDocumentSymbols ()
1815
- }
1817
+ inoDiagsParams .Diagnostics = append (inoDiagsParams .Diagnostics , inoDiag )
1818
+
1819
+ ls .inoDocsWithDiagnostics [inoURI ] = true
1820
+
1821
+ // If we have an "undefined reference" in the .ino code trigger a
1822
+ // check for newly created symbols (that in turn may trigger a
1823
+ // new arduino-preprocessing of the sketch).
1824
+ var inoDiagCode string
1825
+ if err := json .Unmarshal (inoDiag .Code , & inoDiagCode ); err != nil {
1826
+ if inoDiagCode == "undeclared_var_use_suggest" ||
1827
+ inoDiagCode == "undeclared_var_use" ||
1828
+ inoDiagCode == "ovl_no_viable_function_in_call" ||
1829
+ inoDiagCode == "pp_file_not_found" {
1830
+ ls .queueCheckCppDocumentSymbols ()
1816
1831
}
1817
1832
}
1818
1833
}
1819
1834
1820
1835
inoDiagParams := []* lsp.PublishDiagnosticsParams {}
1821
- for _ , v := range inoDiagsParam {
1836
+ for _ , v := range allInoDiagsParams {
1822
1837
inoDiagParams = append (inoDiagParams , v )
1823
1838
}
1824
1839
return inoDiagParams , nil
0 commit comments