@@ -32,21 +32,21 @@ type INOLanguageServer struct {
32
32
IDE * IDELSPServer
33
33
Clangd * ClangdLSPClient
34
34
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
50
50
}
51
51
52
52
// Config describes the language server configuration.
@@ -115,10 +115,10 @@ func (ls *INOLanguageServer) readUnlock(logger jsonrpc.FunctionLogger) {
115
115
func NewINOLanguageServer (stdin io.Reader , stdout io.Writer , config * Config ) * INOLanguageServer {
116
116
logger := NewLSPFunctionLogger (color .HiWhiteString , "LS: " )
117
117
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 ,
122
122
}
123
123
ls .clangdStarted = sync .NewCond (& ls .dataMux )
124
124
ls .sketchRebuilder = NewSketchBuilder (ls )
@@ -641,7 +641,7 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
641
641
var inoSymbolInformation []lsp.SymbolInformation
642
642
if cppSymbolInformation != nil {
643
643
logger .Logf (" <-- documentSymbol(%d symbol information)" , len (cppSymbolInformation ))
644
- inoSymbolInformation = ls .cpp2inoSymbolInformation (cppSymbolInformation )
644
+ inoSymbolInformation = ls .clang2IdeSymbolInformation (cppSymbolInformation )
645
645
}
646
646
return inoDocSymbols , inoSymbolInformation , nil
647
647
}
@@ -762,7 +762,7 @@ func (ls *INOLanguageServer) TextDocumentRangeFormattingReqFromIDE(ctx context.C
762
762
// Method: "textDocument/rangeFormatting"
763
763
logger .Logf ("%s" , inoParams .TextDocument )
764
764
inoURI := inoParams .TextDocument .URI
765
- cppParams , err := ls .ino2cppDocumentRangeFormattingParams (logger , inoParams )
765
+ cppParams , err := ls .ide2ClangDocumentRangeFormattingParams (logger , inoParams )
766
766
if err != nil {
767
767
logger .Logf ("Error: %s" , err )
768
768
return nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : err .Error ()}
@@ -937,7 +937,7 @@ func (ls *INOLanguageServer) PublishDiagnosticsNotifFromClangd(logger jsonrpc.Fu
937
937
938
938
// the diagnostics on sketch.cpp.ino once mapped into their
939
939
// .ino counter parts may span over multiple .ino files...
940
- allInoParams , err := ls .cpp2inoDiagnostics (logger , cppParams )
940
+ allInoParams , err := ls .clang2IdeDiagnostics (logger , cppParams )
941
941
if err != nil {
942
942
logger .Logf ("Error converting diagnostics to .ino: %s" , err )
943
943
return
@@ -1195,16 +1195,16 @@ func (ls *INOLanguageServer) ino2cppVersionedTextDocumentIdentifier(logger jsonr
1195
1195
return res , err
1196
1196
}
1197
1197
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 )
1200
1200
if err != nil {
1201
- return lsp .NilURI , lsp.Range {}, err
1201
+ return lsp.DocumentURI {} , lsp.Range {}, err
1202
1202
}
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
1206
1206
}
1207
- return cppURI , inoRange , nil
1207
+ return clangURI , ideRange , nil
1208
1208
}
1209
1209
1210
1210
func (ls * INOLanguageServer ) cpp2inoLocationArray (logger jsonrpc.FunctionLogger , cppLocations []lsp.Location ) ([]lsp.Location , error ) {
@@ -1220,17 +1220,18 @@ func (ls *INOLanguageServer) cpp2inoLocationArray(logger jsonrpc.FunctionLogger,
1220
1220
return inoLocations , nil
1221
1221
}
1222
1222
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 )
1225
1225
if err != nil {
1226
1226
return nil , err
1227
1227
}
1228
1228
1229
- _ , cppRange , err := ls .ino2cppRange (logger , inoParams .TextDocument .URI , inoParams .Range )
1229
+ _ , clangRange , err := ls .ide2ClangRange (logger , ideParams .TextDocument .URI , ideParams .Range )
1230
1230
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 ,
1234
1235
}, err
1235
1236
}
1236
1237
@@ -1406,85 +1407,6 @@ func (ls *INOLanguageServer) cpp2inoDocumentSymbols(logger jsonrpc.FunctionLogge
1406
1407
return inoSymbols
1407
1408
}
1408
1409
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
-
1488
1410
func unknownURI (uri lsp.DocumentURI ) error {
1489
1411
return errors .New ("Document is not available: " + uri .String ())
1490
1412
}
0 commit comments