SmiteshP / nvim-navic

Simple winbar/statusline plugin that shows your current code context
Apache License 2.0
1.35k stars 49 forks source link

Allow custom text formatting #135

Closed davidmh closed 7 months ago

davidmh commented 9 months ago

Hi @SmiteshP,

I've been enjoying your plugin for a while, and I would like to add customize the segments returned by the LSP client.

For example, when working with test suites, the navigation looks like

describe('something') callback > describe ('subcategory') callback > it('can do things') callback

The text is useful, but it can be a bit too verbose.

It would be great if we could shape the segments to be something like this:

describe something > describe subcategory > it can do things

Which can be achieved by reading an optional format_text function to treat each segment of the result:

navic.setup({
  format_text = function(text)
    if (text:match("^it%(") or text:match("^describe%(")) then
      return text:gsub("^it%('", "it ")
                 :gsub("^describe%('", "describe ")
                 :gsub("'%) callback$", "")
    end
    return text
  end
})
SmiteshP commented 7 months ago

This looks nice, thanks for the PR! 😄 Apologizes for so much delay in reviewing it 😞