@@ -32,21 +32,21 @@ type INOLanguageServer struct {
3232 IDE * IDELSPServer
3333 Clangd * ClangdLSPClient
3434
35- progressHandler * ProgressProxyHandler
36- closing chan bool
37- clangdStarted * sync.Cond
38- dataMux sync.RWMutex
39- compileCommandsDir * paths.Path
40- buildPath * paths.Path
41- buildSketchRoot * paths.Path
42- buildSketchCpp * paths.Path
43- sketchRoot * paths.Path
44- sketchName string
45- sketchMapper * sourcemapper.SketchMapper
46- sketchTrackedFilesCount int
47- trackedIDEDocs map [string ]lsp.TextDocumentItem
48- inoDocsWithDiagnostics map [lsp.DocumentURI ]bool
49- sketchRebuilder * SketchRebuilder
35+ progressHandler * ProgressProxyHandler
36+ closing chan bool
37+ clangdStarted * sync.Cond
38+ dataMux sync.RWMutex
39+ compileCommandsDir * paths.Path
40+ buildPath * paths.Path
41+ buildSketchRoot * paths.Path
42+ buildSketchCpp * paths.Path
43+ sketchRoot * paths.Path
44+ sketchName string
45+ sketchMapper * sourcemapper.SketchMapper
46+ sketchTrackedFilesCount int
47+ trackedIDEDocs map [string ]lsp.TextDocumentItem
48+ ideInoDocsWithDiagnostics map [lsp.DocumentURI ]bool
49+ sketchRebuilder * SketchRebuilder
5050}
5151
5252// Config describes the language server configuration.
@@ -115,10 +115,10 @@ func (ls *INOLanguageServer) readUnlock(logger jsonrpc.FunctionLogger) {
115115func NewINOLanguageServer (stdin io.Reader , stdout io.Writer , config * Config ) * INOLanguageServer {
116116 logger := NewLSPFunctionLogger (color .HiWhiteString , "LS: " )
117117 ls := & INOLanguageServer {
118- trackedIDEDocs : map [string ]lsp.TextDocumentItem {},
119- inoDocsWithDiagnostics : map [lsp.DocumentURI ]bool {},
120- closing : make (chan bool ),
121- config : config ,
118+ trackedIDEDocs : map [string ]lsp.TextDocumentItem {},
119+ ideInoDocsWithDiagnostics : map [lsp.DocumentURI ]bool {},
120+ closing : make (chan bool ),
121+ config : config ,
122122 }
123123 ls .clangdStarted = sync .NewCond (& ls .dataMux )
124124 ls .sketchRebuilder = NewSketchBuilder (ls )
@@ -641,7 +641,7 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
641641 var inoSymbolInformation []lsp.SymbolInformation
642642 if cppSymbolInformation != nil {
643643 logger .Logf (" <-- documentSymbol(%d symbol information)" , len (cppSymbolInformation ))
644- inoSymbolInformation = ls .cpp2inoSymbolInformation (cppSymbolInformation )
644+ inoSymbolInformation = ls .clang2IdeSymbolInformation (cppSymbolInformation )
645645 }
646646 return inoDocSymbols , inoSymbolInformation , nil
647647}
@@ -762,7 +762,7 @@ func (ls *INOLanguageServer) TextDocumentRangeFormattingReqFromIDE(ctx context.C
762762 // Method: "textDocument/rangeFormatting"
763763 logger .Logf ("%s" , inoParams .TextDocument )
764764 inoURI := inoParams .TextDocument .URI
765- cppParams , err := ls .ino2cppDocumentRangeFormattingParams (logger , inoParams )
765+ cppParams , err := ls .ide2ClangDocumentRangeFormattingParams (logger , inoParams )
766766 if err != nil {
767767 logger .Logf ("Error: %s" , err )
768768 return nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : err .Error ()}
@@ -937,7 +937,7 @@ func (ls *INOLanguageServer) PublishDiagnosticsNotifFromClangd(logger jsonrpc.Fu
937937
938938 // the diagnostics on sketch.cpp.ino once mapped into their
939939 // .ino counter parts may span over multiple .ino files...
940- allInoParams , err := ls .cpp2inoDiagnostics (logger , cppParams )
940+ allInoParams , err := ls .clang2IdeDiagnostics (logger , cppParams )
941941 if err != nil {
942942 logger .Logf ("Error converting diagnostics to .ino: %s" , err )
943943 return
@@ -1195,16 +1195,16 @@ func (ls *INOLanguageServer) ino2cppVersionedTextDocumentIdentifier(logger jsonr
11951195 return res , err
11961196}
11971197
1198- func (ls * INOLanguageServer ) ino2cppRange (logger jsonrpc.FunctionLogger , inoURI lsp.DocumentURI , inoRange lsp.Range ) (lsp.DocumentURI , lsp.Range , error ) {
1199- cppURI , err := ls .ide2ClangDocumentURI (logger , inoURI )
1198+ func (ls * INOLanguageServer ) ide2ClangRange (logger jsonrpc.FunctionLogger , ideURI lsp.DocumentURI , ideRange lsp.Range ) (lsp.DocumentURI , lsp.Range , error ) {
1199+ clangURI , err := ls .ide2ClangDocumentURI (logger , ideURI )
12001200 if err != nil {
1201- return lsp .NilURI , lsp.Range {}, err
1201+ return lsp.DocumentURI {} , lsp.Range {}, err
12021202 }
1203- if cppURI .AsPath ().EquivalentTo (ls .buildSketchCpp ) {
1204- cppRange := ls .sketchMapper .InoToCppLSPRange (inoURI , inoRange )
1205- return cppURI , cppRange , nil
1203+ if clangURI .AsPath ().EquivalentTo (ls .buildSketchCpp ) {
1204+ cppRange := ls .sketchMapper .InoToCppLSPRange (ideURI , ideRange )
1205+ return clangURI , cppRange , nil
12061206 }
1207- return cppURI , inoRange , nil
1207+ return clangURI , ideRange , nil
12081208}
12091209
12101210func (ls * INOLanguageServer ) cpp2inoLocationArray (logger jsonrpc.FunctionLogger , cppLocations []lsp.Location ) ([]lsp.Location , error ) {
@@ -1220,17 +1220,18 @@ func (ls *INOLanguageServer) cpp2inoLocationArray(logger jsonrpc.FunctionLogger,
12201220 return inoLocations , nil
12211221}
12221222
1223- func (ls * INOLanguageServer ) ino2cppDocumentRangeFormattingParams (logger jsonrpc.FunctionLogger , inoParams * lsp.DocumentRangeFormattingParams ) (* lsp.DocumentRangeFormattingParams , error ) {
1224- cppTextDocument , err := ls .ide2ClangTextDocumentIdentifier (logger , inoParams .TextDocument )
1223+ func (ls * INOLanguageServer ) ide2ClangDocumentRangeFormattingParams (logger jsonrpc.FunctionLogger , ideParams * lsp.DocumentRangeFormattingParams ) (* lsp.DocumentRangeFormattingParams , error ) {
1224+ clangTextDocumentIdentifier , err := ls .ide2ClangTextDocumentIdentifier (logger , ideParams .TextDocument )
12251225 if err != nil {
12261226 return nil , err
12271227 }
12281228
1229- _ , cppRange , err := ls .ino2cppRange (logger , inoParams .TextDocument .URI , inoParams .Range )
1229+ _ , clangRange , err := ls .ide2ClangRange (logger , ideParams .TextDocument .URI , ideParams .Range )
12301230 return & lsp.DocumentRangeFormattingParams {
1231- TextDocument : cppTextDocument ,
1232- Range : cppRange ,
1233- Options : inoParams .Options ,
1231+ WorkDoneProgressParams : ideParams .WorkDoneProgressParams ,
1232+ Options : ideParams .Options ,
1233+ TextDocument : clangTextDocumentIdentifier ,
1234+ Range : clangRange ,
12341235 }, err
12351236}
12361237
@@ -1406,85 +1407,6 @@ func (ls *INOLanguageServer) cpp2inoDocumentSymbols(logger jsonrpc.FunctionLogge
14061407 return inoSymbols
14071408}
14081409
1409- func (ls * INOLanguageServer ) cpp2inoSymbolInformation (syms []lsp.SymbolInformation ) []lsp.SymbolInformation {
1410- panic ("not implemented" )
1411- }
1412-
1413- func (ls * INOLanguageServer ) cpp2inoDiagnostics (logger jsonrpc.FunctionLogger , cppDiagsParams * lsp.PublishDiagnosticsParams ) ([]* lsp.PublishDiagnosticsParams , error ) {
1414-
1415- cppURI := cppDiagsParams .URI
1416- isSketch := cppURI .AsPath ().EquivalentTo (ls .buildSketchCpp )
1417-
1418- if ! isSketch {
1419- inoURI , _ , err := ls .clang2IdeRangeAndDocumentURI (logger , cppURI , lsp .NilRange )
1420- if err != nil {
1421- return nil , err
1422- }
1423- inoDiags := []lsp.Diagnostic {}
1424- for _ , cppDiag := range cppDiagsParams .Diagnostics {
1425- inoURIofConvertedRange , inoRange , err := ls .clang2IdeRangeAndDocumentURI (logger , cppURI , cppDiag .Range )
1426- if err != nil {
1427- return nil , err
1428- }
1429- if inoURIofConvertedRange .String () == sourcemapper .NotInoURI .String () {
1430- continue
1431- }
1432- if inoURIofConvertedRange .String () != inoURI .String () {
1433- return nil , fmt .Errorf ("unexpected inoURI %s: it should be %s" , inoURIofConvertedRange , inoURI )
1434- }
1435- inoDiag := cppDiag
1436- inoDiag .Range = inoRange
1437- inoDiags = append (inoDiags , inoDiag )
1438- }
1439- return []* lsp.PublishDiagnosticsParams {
1440- {
1441- URI : inoURI ,
1442- Diagnostics : inoDiags ,
1443- },
1444- }, nil
1445- }
1446-
1447- allInoDiagsParams := map [lsp.DocumentURI ]* lsp.PublishDiagnosticsParams {}
1448- for inoURI := range ls .inoDocsWithDiagnostics {
1449- allInoDiagsParams [inoURI ] = & lsp.PublishDiagnosticsParams {
1450- URI : inoURI ,
1451- Diagnostics : []lsp.Diagnostic {},
1452- }
1453- }
1454- ls .inoDocsWithDiagnostics = map [lsp.DocumentURI ]bool {}
1455-
1456- for _ , cppDiag := range cppDiagsParams .Diagnostics {
1457- inoURI , inoRange , err := ls .clang2IdeRangeAndDocumentURI (logger , cppURI , cppDiag .Range )
1458- if err != nil {
1459- return nil , err
1460- }
1461- if inoURI .String () == sourcemapper .NotInoURI .String () {
1462- continue
1463- }
1464-
1465- inoDiagsParams , ok := allInoDiagsParams [inoURI ]
1466- if ! ok {
1467- inoDiagsParams = & lsp.PublishDiagnosticsParams {
1468- URI : inoURI ,
1469- Diagnostics : []lsp.Diagnostic {},
1470- }
1471- allInoDiagsParams [inoURI ] = inoDiagsParams
1472- }
1473-
1474- inoDiag := cppDiag
1475- inoDiag .Range = inoRange
1476- inoDiagsParams .Diagnostics = append (inoDiagsParams .Diagnostics , inoDiag )
1477-
1478- ls .inoDocsWithDiagnostics [inoURI ] = true
1479- }
1480-
1481- inoDiagParams := []* lsp.PublishDiagnosticsParams {}
1482- for _ , v := range allInoDiagsParams {
1483- inoDiagParams = append (inoDiagParams , v )
1484- }
1485- return inoDiagParams , nil
1486- }
1487-
14881410func unknownURI (uri lsp.DocumentURI ) error {
14891411 return errors .New ("Document is not available: " + uri .String ())
14901412}
0 commit comments