@@ -611,24 +611,22 @@ func (ls *INOLanguageServer) TextDocumentDocumentHighlightReqFromIDE(ctx context
611
611
return ideHighlights , nil
612
612
}
613
613
614
- func (ls * INOLanguageServer ) TextDocumentDocumentSymbolReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , inoParams * lsp.DocumentSymbolParams ) ([]lsp.DocumentSymbol , []lsp.SymbolInformation , * jsonrpc.ResponseError ) {
614
+ func (ls * INOLanguageServer ) TextDocumentDocumentSymbolReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.DocumentSymbolParams ) ([]lsp.DocumentSymbol , []lsp.SymbolInformation , * jsonrpc.ResponseError ) {
615
615
ls .readLock (logger , true )
616
616
defer ls .readUnlock (logger )
617
+ ideTextDocument := ideParams .TextDocument
617
618
618
- inoTextDocument := inoParams .TextDocument
619
- inoURI := inoTextDocument .URI
620
- logger .Logf ("--> %s" )
621
-
622
- cppTextDocument , err := ls .ide2ClangTextDocumentIdentifier (logger , inoTextDocument )
619
+ // Convert request for clang
620
+ cppTextDocument , err := ls .ide2ClangTextDocumentIdentifier (logger , ideTextDocument )
623
621
if err != nil {
624
622
logger .Logf ("Error: %s" , err )
625
623
return nil , nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : err .Error ()}
626
624
}
625
+ clangParams := * ideParams
626
+ clangParams .TextDocument = cppTextDocument
627
627
628
- cppParams := * inoParams
629
- cppParams .TextDocument = cppTextDocument
630
- logger .Logf (" --> documentSymbol(%s)" , cppTextDocument )
631
- cppDocSymbols , cppSymbolInformation , clangErr , err := ls .Clangd .conn .TextDocumentDocumentSymbol (ctx , & cppParams )
628
+ // Send request to clang
629
+ clangDocSymbols , clangSymbolsInformation , clangErr , err := ls .Clangd .conn .TextDocumentDocumentSymbol (ctx , & clangParams )
632
630
if err != nil {
633
631
logger .Logf ("clangd connectiono error: %v" , err )
634
632
ls .Close ()
@@ -639,17 +637,16 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
639
637
return nil , nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : clangErr .AsError ().Error ()}
640
638
}
641
639
642
- var inoDocSymbols []lsp. DocumentSymbol
643
- if cppDocSymbols != nil {
644
- logger . Logf ( " <-- documentSymbol(%d document symbols)" , len ( cppDocSymbols ))
645
- inoDocSymbols = ls .cpp2inoDocumentSymbols (logger , cppDocSymbols , inoURI )
640
+ // Convert response for IDE
641
+ var ideDocSymbols []lsp. DocumentSymbol
642
+ if clangDocSymbols != nil {
643
+ ideDocSymbols = ls .clang2IdeDocumentSymbols (logger , clangDocSymbols , ideTextDocument . URI )
646
644
}
647
- var inoSymbolInformation []lsp.SymbolInformation
648
- if cppSymbolInformation != nil {
649
- logger .Logf (" <-- documentSymbol(%d symbol information)" , len (cppSymbolInformation ))
650
- inoSymbolInformation = ls .clang2IdeSymbolInformation (cppSymbolInformation )
645
+ var ideSymbolsInformation []lsp.SymbolInformation
646
+ if clangSymbolsInformation != nil {
647
+ ideSymbolsInformation = ls .clang2IdeSymbolsInformation (logger , clangSymbolsInformation )
651
648
}
652
- return inoDocSymbols , inoSymbolInformation , nil
649
+ return ideDocSymbols , ideSymbolsInformation , nil
653
650
}
654
651
655
652
func (ls * INOLanguageServer ) TextDocumentCodeActionReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , inoParams * lsp.CodeActionParams ) ([]lsp.CommandOrCodeAction , * jsonrpc.ResponseError ) {
@@ -1221,18 +1218,6 @@ func (ls *INOLanguageServer) ino2cppVersionedTextDocumentIdentifier(logger jsonr
1221
1218
return res , err
1222
1219
}
1223
1220
1224
- func (ls * INOLanguageServer ) ide2ClangRange (logger jsonrpc.FunctionLogger , ideURI lsp.DocumentURI , ideRange lsp.Range ) (lsp.DocumentURI , lsp.Range , error ) {
1225
- clangURI , err := ls .ide2ClangDocumentURI (logger , ideURI )
1226
- if err != nil {
1227
- return lsp.DocumentURI {}, lsp.Range {}, err
1228
- }
1229
- if clangURI .AsPath ().EquivalentTo (ls .buildSketchCpp ) {
1230
- cppRange := ls .sketchMapper .InoToCppLSPRange (ideURI , ideRange )
1231
- return clangURI , cppRange , nil
1232
- }
1233
- return clangURI , ideRange , nil
1234
- }
1235
-
1236
1221
func (ls * INOLanguageServer ) cpp2inoLocationArray (logger jsonrpc.FunctionLogger , cppLocations []lsp.Location ) ([]lsp.Location , error ) {
1237
1222
inoLocations := []lsp.Location {}
1238
1223
for _ , cppLocation := range cppLocations {
@@ -1402,50 +1387,6 @@ func (ls *INOLanguageServer) cpp2inoTextEdit(logger jsonrpc.FunctionLogger, cppU
1402
1387
return inoURI , inoEdit , inPreprocessed , err
1403
1388
}
1404
1389
1405
- func (ls * INOLanguageServer ) cpp2inoDocumentSymbols (logger jsonrpc.FunctionLogger , cppSymbols []lsp.DocumentSymbol , inoRequestedURI lsp.DocumentURI ) []lsp.DocumentSymbol {
1406
- inoRequested := inoRequestedURI .AsPath ().String ()
1407
- logger .Logf (" filtering for requested ino file: %s" , inoRequested )
1408
- if inoRequestedURI .Ext () != ".ino" || len (cppSymbols ) == 0 {
1409
- return cppSymbols
1410
- }
1411
-
1412
- inoSymbols := []lsp.DocumentSymbol {}
1413
- for _ , symbol := range cppSymbols {
1414
- logger .Logf (" > convert %s %s" , symbol .Kind , symbol .Range )
1415
- if ls .sketchMapper .IsPreprocessedCppLine (symbol .Range .Start .Line ) {
1416
- logger .Logf (" symbol is in the preprocessed section of the sketch.ino.cpp" )
1417
- continue
1418
- }
1419
-
1420
- inoFile , inoRange := ls .sketchMapper .CppToInoRange (symbol .Range )
1421
- inoSelectionURI , inoSelectionRange := ls .sketchMapper .CppToInoRange (symbol .SelectionRange )
1422
-
1423
- if inoFile != inoSelectionURI {
1424
- logger .Logf (" ERROR: symbol range and selection belongs to different URI!" )
1425
- logger .Logf (" symbol %s != selection %s" , symbol .Range , symbol .SelectionRange )
1426
- logger .Logf (" %s:%s != %s:%s" , inoFile , inoRange , inoSelectionURI , inoSelectionRange )
1427
- continue
1428
- }
1429
-
1430
- if inoFile != inoRequested {
1431
- logger .Logf (" skipping symbol related to %s" , inoFile )
1432
- continue
1433
- }
1434
-
1435
- inoSymbols = append (inoSymbols , lsp.DocumentSymbol {
1436
- Name : symbol .Name ,
1437
- Detail : symbol .Detail ,
1438
- Deprecated : symbol .Deprecated ,
1439
- Kind : symbol .Kind ,
1440
- Range : inoRange ,
1441
- SelectionRange : inoSelectionRange ,
1442
- Children : ls .cpp2inoDocumentSymbols (logger , symbol .Children , inoRequestedURI ),
1443
- })
1444
- }
1445
-
1446
- return inoSymbols
1447
- }
1448
-
1449
1390
type UnknownURI struct {
1450
1391
URI lsp.DocumentURI
1451
1392
}
0 commit comments