@@ -611,24 +611,22 @@ func (ls *INOLanguageServer) TextDocumentDocumentHighlightReqFromIDE(ctx context
611611 return ideHighlights , nil
612612}
613613
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 ) {
615615 ls .readLock (logger , true )
616616 defer ls .readUnlock (logger )
617+ ideTextDocument := ideParams .TextDocument
617618
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 )
623621 if err != nil {
624622 logger .Logf ("Error: %s" , err )
625623 return nil , nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : err .Error ()}
626624 }
625+ clangParams := * ideParams
626+ clangParams .TextDocument = cppTextDocument
627627
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 )
632630 if err != nil {
633631 logger .Logf ("clangd connectiono error: %v" , err )
634632 ls .Close ()
@@ -639,17 +637,16 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
639637 return nil , nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : clangErr .AsError ().Error ()}
640638 }
641639
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 )
646644 }
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 )
651648 }
652- return inoDocSymbols , inoSymbolInformation , nil
649+ return ideDocSymbols , ideSymbolsInformation , nil
653650}
654651
655652func (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
12211218 return res , err
12221219}
12231220
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-
12361221func (ls * INOLanguageServer ) cpp2inoLocationArray (logger jsonrpc.FunctionLogger , cppLocations []lsp.Location ) ([]lsp.Location , error ) {
12371222 inoLocations := []lsp.Location {}
12381223 for _ , cppLocation := range cppLocations {
@@ -1402,50 +1387,6 @@ func (ls *INOLanguageServer) cpp2inoTextEdit(logger jsonrpc.FunctionLogger, cppU
14021387 return inoURI , inoEdit , inPreprocessed , err
14031388}
14041389
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-
14491390type UnknownURI struct {
14501391 URI lsp.DocumentURI
14511392}
0 commit comments