@@ -179,19 +179,23 @@ local function call_hierarchy_handler(opts, cb, _, result, ctx, _)
179179end
180180
181181-- Copied from vim.lsp.util.symbols_to_items, then added space prefix to child symbols.
182- local function symbols_to_items (symbols , bufnr , child_prefix )
182+ local function symbols_to_items (opts , symbols , bufnr , child_prefix )
183183 --- @private
184- local function _symbols_to_items (_symbols , _items , _bufnr , prefix )
184+ local function _symbols_to_items (_symbols , _items , _bufnr , prefix , parents )
185+ parents = parents or {}
185186 for _ , symbol in ipairs (_symbols ) do
186187 local kind = vim .lsp .protocol .SymbolKind [symbol .kind ] or " Unknown"
188+ local name = opts .parent_postfix and not utils .tbl_isempty (parents )
189+ and table.concat (parents , opts .parent_postfix ) .. opts .parent_postfix .. symbol .name
190+ or symbol .name
187191 if symbol .location then -- SymbolInformation type
188192 local range = symbol .location .range
189193 table.insert (_items , {
190194 filename = vim .uri_to_fname (symbol .location .uri ),
191195 lnum = range .start .line + 1 ,
192196 col = range .start .character + 1 ,
193197 kind = kind ,
194- text = prefix .. " [" .. kind .. " ] " .. symbol . name ,
198+ text = prefix .. " [" .. kind .. " ] " .. name ,
195199 })
196200 elseif symbol .selectionRange then -- DocumentSymbole type
197201 table.insert (_items , {
@@ -200,14 +204,18 @@ local function symbols_to_items(symbols, bufnr, child_prefix)
200204 lnum = symbol .selectionRange .start .line + 1 ,
201205 col = symbol .selectionRange .start .character + 1 ,
202206 kind = kind ,
203- text = prefix .. " [" .. kind .. " ] " .. symbol . name ,
207+ text = prefix .. " [" .. kind .. " ] " .. name ,
204208 })
205209 if symbol .children then
206- for _ , v in ipairs (_symbols_to_items (symbol .children , _items , _bufnr , prefix .. child_prefix )) do
210+ table.insert (parents , symbol .name )
211+ for _ , v in ipairs (
212+ _symbols_to_items (symbol .children , _items , _bufnr , prefix .. child_prefix , parents ))
213+ do
207214 for _ , s in ipairs (v ) do
208215 table.insert (_items , s )
209216 end
210217 end
218+ table.remove (parents )
211219 end
212220 end
213221 end
@@ -220,7 +228,7 @@ local function symbol_handler(opts, cb, _, result, ctx, _)
220228 result = utils .tbl_islist (result ) and result or { result }
221229 local items
222230 if opts .child_prefix then
223- items = symbols_to_items (result , utils .CTX ().bufnr ,
231+ items = symbols_to_items (opts , result , utils .CTX ().bufnr ,
224232 opts .child_prefix == true and string.rep (" " , 2 ) or opts .child_prefix )
225233 else
226234 local encoding = vim .lsp .get_client_by_id (ctx .client_id ).offset_encoding
0 commit comments