@@ -132,50 +132,53 @@ func (ls *INOLanguageServer) clang2IdeDiagnosticRelatedInformationArray(logger j
132132 return ideInfos , nil
133133}
134134
135- func (ls * INOLanguageServer ) clang2IdeDocumentSymbols (logger jsonrpc.FunctionLogger , clangSymbols []lsp.DocumentSymbol , ideRequestedURI lsp.DocumentURI ) []lsp.DocumentSymbol {
136- logger .Logf ("documentSymbol(%d document symbols)" , len (clangSymbols ))
137- ideRequestedPath := ideRequestedURI .AsPath ().String ()
138- logger .Logf (" filtering for requested ino file: %s" , ideRequestedPath )
139- if ideRequestedURI .Ext () != ".ino" || len (clangSymbols ) == 0 {
140- return clangSymbols
141- }
135+ func (ls * INOLanguageServer ) clang2IdeDocumentSymbols (logger jsonrpc.FunctionLogger , clangSymbols []lsp.DocumentSymbol , clangURI lsp.DocumentURI , origIdeURI lsp.DocumentURI ) ([]lsp.DocumentSymbol , error ) {
136+ logger .Logf ("%s (%d document symbols)" , clangURI , len (clangSymbols ))
142137
143138 ideSymbols := []lsp.DocumentSymbol {}
144139 for _ , clangSymbol := range clangSymbols {
145- logger .Logf (" > convert %s %s" , clangSymbol .Kind , clangSymbol .Range )
146- if ls .sketchMapper .IsPreprocessedCppLine (clangSymbol .Range .Start .Line ) {
147- logger .Logf (" symbol is in the preprocessed section of the sketch.ino.cpp" )
140+ logger .Logf (" > convert %s %s" , clangSymbol .Kind , clangSymbol .Range )
141+ ideURI , ideRange , isPreprocessed , err := ls .clang2IdeRangeAndDocumentURI (logger , clangURI , clangSymbol .Range )
142+ if err != nil {
143+ return nil , err
144+ }
145+ if isPreprocessed {
146+ logger .Logf (" symbol is in the preprocessed section of the sketch.ino.cpp, skipping" )
148147 continue
149148 }
150-
151- idePath , ideRange := ls .sketchMapper .CppToInoRange (clangSymbol .Range )
152- ideSelectionPath , ideSelectionRange := ls .sketchMapper .CppToInoRange (clangSymbol .SelectionRange )
153-
154- if idePath != ideSelectionPath {
155- logger .Logf (" ERROR: symbol range and selection belongs to different URI!" )
156- logger .Logf (" symbol %s != selection %s" , clangSymbol .Range , clangSymbol .SelectionRange )
157- logger .Logf (" %s:%s != %s:%s" , idePath , ideRange , ideSelectionPath , ideSelectionRange )
149+ if ideURI != origIdeURI {
150+ logger .Logf (" filtering out symbol related to %s" , ideURI )
158151 continue
159152 }
160-
161- if idePath != ideRequestedPath {
162- logger .Logf (" skipping symbol related to %s" , idePath )
153+ ideSelectionURI , ideSelectionRange , isSelectionPreprocessed , err := ls .clang2IdeRangeAndDocumentURI (logger , clangURI , clangSymbol .SelectionRange )
154+ if err != nil {
155+ return nil , err
156+ }
157+ if ideSelectionURI != ideURI || isSelectionPreprocessed {
158+ logger .Logf (" ERROR: doc of symbol-selection-range does not match doc of symbol-range" )
159+ logger .Logf (" range %s > %s:%s" , clangSymbol .Range , ideURI , ideRange )
160+ logger .Logf (" selection %s > %s:%s" , clangSymbol .SelectionRange , ideSelectionURI , ideSelectionRange )
163161 continue
164162 }
165163
164+ ideChildren , err := ls .clang2IdeDocumentSymbols (logger , clangSymbol .Children , clangURI , origIdeURI )
165+ if err != nil {
166+ return nil , err
167+ }
168+
166169 ideSymbols = append (ideSymbols , lsp.DocumentSymbol {
167170 Name : clangSymbol .Name ,
168171 Detail : clangSymbol .Detail ,
169172 Deprecated : clangSymbol .Deprecated ,
170173 Kind : clangSymbol .Kind ,
171174 Range : ideRange ,
172175 SelectionRange : ideSelectionRange ,
173- Children : ls . clang2IdeDocumentSymbols ( logger , clangSymbol . Children , ideRequestedURI ) ,
176+ Children : ideChildren ,
174177 Tags : ls .clang2IdeSymbolTags (logger , clangSymbol .Tags ),
175178 })
176179 }
177180
178- return ideSymbols
181+ return ideSymbols , nil
179182}
180183
181184func (ls * INOLanguageServer ) cland2IdeTextEdits (logger jsonrpc.FunctionLogger , clangURI lsp.DocumentURI , clangTextEdits []lsp.TextEdit ) (map [lsp.DocumentURI ][]lsp.TextEdit , error ) {
0 commit comments