folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.62k stars 177 forks source link

feature: show directory relative to cwd or lsp root #571

Closed fent closed 1 month ago

fent commented 2 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

My previous issue https://github.com/folke/trouble.nvim/issues/330 got closed when Trouble v3 came out. But I still see absolute paths.

There doesn't seem to be an option to make the directory relative to either cwd or the lsp root, but I'm able to override the directory formatter with my own implementation

require("trouble.format").formatters.directory = function(ctx)
  if ctx.node:source() == "fs" then
    local directory = ctx.item.directory or ""
    local parent = ctx.node:parent_item()
    if parent and parent.directory then
      directory = directory:sub(#parent.directory + 1)
      return { text = directory, hl = "TroubleDirectory" }
    end

    -- Truncate cwd
    local cwd = (vim.uv or vim.loop).cwd()
    if cwd and string.find(directory, cwd .. "/", 0, true) == 1 then
      directory = directory:sub(#cwd + 2)
    end

    return { text = vim.fn.fnamemodify(directory, ":~"), hl = "TroubleDirectory" }
  end
end

Describe the solution you'd like

An option to display paths relative to the cwd or lsp root. Or an option to customize the formatters from format.lua, as the way I'm doing it seems hacky.

Describe alternatives you've considered

n/a

Additional context

No response

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 1 month ago

This issue was closed because it has been stalled for 7 days with no activity.