@@ -132,50 +132,53 @@ func (ls *INOLanguageServer) clang2IdeDiagnosticRelatedInformationArray(logger j
132
132
return ideInfos , nil
133
133
}
134
134
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 ))
142
137
143
138
ideSymbols := []lsp.DocumentSymbol {}
144
139
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" )
148
147
continue
149
148
}
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 )
158
151
continue
159
152
}
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 )
163
161
continue
164
162
}
165
163
164
+ ideChildren , err := ls .clang2IdeDocumentSymbols (logger , clangSymbol .Children , clangURI , origIdeURI )
165
+ if err != nil {
166
+ return nil , err
167
+ }
168
+
166
169
ideSymbols = append (ideSymbols , lsp.DocumentSymbol {
167
170
Name : clangSymbol .Name ,
168
171
Detail : clangSymbol .Detail ,
169
172
Deprecated : clangSymbol .Deprecated ,
170
173
Kind : clangSymbol .Kind ,
171
174
Range : ideRange ,
172
175
SelectionRange : ideSelectionRange ,
173
- Children : ls . clang2IdeDocumentSymbols ( logger , clangSymbol . Children , ideRequestedURI ) ,
176
+ Children : ideChildren ,
174
177
Tags : ls .clang2IdeSymbolTags (logger , clangSymbol .Tags ),
175
178
})
176
179
}
177
180
178
- return ideSymbols
181
+ return ideSymbols , nil
179
182
}
180
183
181
184
func (ls * INOLanguageServer ) cland2IdeTextEdits (logger jsonrpc.FunctionLogger , clangURI lsp.DocumentURI , clangTextEdits []lsp.TextEdit ) (map [lsp.DocumentURI ][]lsp.TextEdit , error ) {
0 commit comments