@@ -206,6 +206,14 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
206
206
err = handler .ino2cppTextDocumentPositionParams (doc )
207
207
log .Printf (" --> hover(%s:%d:%d)\n " , doc .TextDocument .URI , doc .Position .Line , doc .Position .Character )
208
208
209
+ case * lsp.DocumentSymbolParams :
210
+ // method "textDocument/documentSymbol"
211
+ uri = p .TextDocument .URI
212
+ log .Printf ("--> documentSymbol(%s)" , p .TextDocument .URI )
213
+
214
+ err = handler .sketchToBuildPathTextDocumentIdentifier (& p .TextDocument )
215
+ log .Printf (" --> documentSymbol(%s)" , p .TextDocument .URI )
216
+
209
217
case * lsp.DidSaveTextDocumentParams : // "textDocument/didSave":
210
218
log .Printf ("--X " + req .Method )
211
219
return nil , nil
@@ -250,11 +258,6 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
250
258
return nil , nil
251
259
uri = p .TextDocument .URI
252
260
err = handler .ino2cppDocumentOnTypeFormattingParams (p )
253
- case * lsp.DocumentSymbolParams : // "textDocument/documentSymbol":
254
- log .Printf ("--X " + req .Method )
255
- return nil , nil
256
- uri = p .TextDocument .URI
257
- err = handler .sketchToBuildPathTextDocumentIdentifier (& p .TextDocument )
258
261
case * lsp.RenameParams : // "textDocument/rename":
259
262
log .Printf ("--X " + req .Method )
260
263
return nil , nil
@@ -725,6 +728,19 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
725
728
log .Printf ("<-- completion(%d items)" , len (r .Items ))
726
729
return r
727
730
731
+ case * lsp.DocumentSymbolArrayOrSymbolInformationArray :
732
+ // method "textDocument/documentSymbol"
733
+
734
+ if r .DocumentSymbolArray != nil {
735
+ // Treat the input as []DocumentSymbol
736
+ return handler .cpp2inoDocumentSymbols (* r .DocumentSymbolArray , uri )
737
+ } else if r .SymbolInformationArray != nil {
738
+ // Treat the input as []SymbolInformation
739
+ return handler .cpp2inoSymbolInformation (* r .SymbolInformationArray )
740
+ } else {
741
+ // Treat the input as null
742
+ }
743
+
728
744
case * []* lsp.CommandOrCodeAction :
729
745
// method "textDocument/codeAction"
730
746
// TODO: implement response
@@ -764,28 +780,6 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
764
780
for index := range * r {
765
781
handler .cpp2inoTextEdit (& (* r )[index ], uri )
766
782
}
767
- case * []* lsp.DocumentSymbolOrSymbolInformation : // "textDocument/documentSymbol":
768
- if len (* r ) == 0 {
769
- return result
770
- }
771
-
772
- slice := * r
773
- if slice [0 ].DocumentSymbol != nil {
774
- // Treat the input as []DocumentSymbol
775
- symbols := make ([]lsp.DocumentSymbol , len (slice ))
776
- for index := range slice {
777
- symbols [index ] = * slice [index ].DocumentSymbol
778
- }
779
- return handler .cpp2inoDocumentSymbols (symbols , uri )
780
- }
781
- if slice [0 ].SymbolInformation != nil {
782
- // Treat the input as []SymbolInformation
783
- symbols := make ([]* lsp.SymbolInformation , len (slice ))
784
- for i , s := range slice {
785
- symbols [i ] = s .SymbolInformation
786
- }
787
- return handler .cpp2inoSymbolInformation (symbols )
788
- }
789
783
case * lsp.WorkspaceEdit : // "textDocument/rename":
790
784
return handler .cpp2inoWorkspaceEdit (r )
791
785
case * []lsp.SymbolInformation : // "workspace/symbol":
@@ -859,44 +853,47 @@ func (handler *InoHandler) cpp2inoTextEdit(edit *lsp.TextEdit, uri lsp.DocumentU
859
853
// }
860
854
}
861
855
862
- func (handler * InoHandler ) cpp2inoDocumentSymbols (origSymbols []lsp.DocumentSymbol , uri lsp.DocumentURI ) []lsp.DocumentSymbol {
863
- panic ("not implemented" )
864
- // data, ok := handler.data[uri]
865
- // if !ok || len(origSymbols) == 0 {
866
- // return origSymbols
867
- // }
856
+ func (handler * InoHandler ) cpp2inoDocumentSymbols (origSymbols []lsp.DocumentSymbol , origURI lsp.DocumentURI ) []lsp.DocumentSymbol {
857
+ if origURI .AsPath ().Ext () != ".ino" || len (origSymbols ) == 0 {
858
+ return origSymbols
859
+ }
868
860
869
- // symbolIdx := make(map[string]*lsp.DocumentSymbol)
870
- // for i := 0; i < len(origSymbols); i++ {
871
- // symbol := &origSymbols[i]
872
- // _, symbol.Range = data.sourceMap.CppToInoRange(symbol.Range)
873
-
874
- // duplicate := false
875
- // other, duplicate := symbolIdx[symbol.Name]
876
- // if duplicate {
877
- // // We prefer symbols later in the file due to the function header generation. E.g. if one has a function `void foo() {}` somehwre in the code
878
- // // the code generation will add a `void foo();` header at the beginning of the cpp file. We care about the function body later in the file, not
879
- // // the header early on.
880
- // if other.Range.Start.Line < symbol.Range.Start.Line {
881
- // continue
882
- // }
883
- // }
861
+ inoSymbols := []lsp.DocumentSymbol {}
862
+ for _ , symbol := range origSymbols {
863
+ if handler .sketchMapper .IsPreprocessedCppLine (symbol .Range .Start .Line ) {
864
+ continue
865
+ }
884
866
885
- // _, symbol.SelectionRange = data.sourceMap.CppToInoRange(symbol.SelectionRange)
886
- // symbol.Children = handler.cpp2inoDocumentSymbols(symbol.Children, uri)
887
- // symbolIdx[symbol.Name] = symbol
888
- // }
867
+ inoFile , inoRange := handler .sketchMapper .CppToInoRange (symbol .Range )
868
+ inoSelectionURI , inoSelectionRange := handler .sketchMapper .CppToInoRange (symbol .SelectionRange )
889
869
890
- // newSymbols := make([]lsp.DocumentSymbol, len(symbolIdx))
891
- // j := 0
892
- // for _, s := range symbolIdx {
893
- // newSymbols[j] = *s
894
- // j++
895
- // }
896
- // return newSymbols
870
+ if inoFile != inoSelectionURI {
871
+ log .Printf (" ERROR: symbol range and selection belongs to different URI!" )
872
+ log .Printf (" > %s != %s" , symbol .Range , symbol .SelectionRange )
873
+ log .Printf (" > %s:%s != %s:%s" , inoFile , inoRange , inoSelectionURI , inoSelectionRange )
874
+ continue
875
+ }
876
+
877
+ if inoFile != origURI .Unbox () {
878
+ //log.Printf(" skipping symbol related to %s", inoFile)
879
+ continue
880
+ }
881
+
882
+ inoSymbols = append (inoSymbols , lsp.DocumentSymbol {
883
+ Name : symbol .Name ,
884
+ Detail : symbol .Detail ,
885
+ Deprecated : symbol .Deprecated ,
886
+ Kind : symbol .Kind ,
887
+ Range : inoRange ,
888
+ SelectionRange : inoSelectionRange ,
889
+ Children : handler .cpp2inoDocumentSymbols (symbol .Children , origURI ),
890
+ })
891
+ }
892
+
893
+ return inoSymbols
897
894
}
898
895
899
- func (handler * InoHandler ) cpp2inoSymbolInformation (syms []* lsp.SymbolInformation ) []lsp.SymbolInformation {
896
+ func (handler * InoHandler ) cpp2inoSymbolInformation (syms []lsp.SymbolInformation ) []lsp.SymbolInformation {
900
897
panic ("not implemented" )
901
898
// // Much like in cpp2inoDocumentSymbols we de-duplicate symbols based on file in-file location.
902
899
// idx := make(map[string]*lsp.SymbolInformation)
0 commit comments