Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate or fold file paths if out of bounds #895

Closed
vuki656 opened this issue Jun 5, 2021 · 13 comments
Closed

Truncate or fold file paths if out of bounds #895

vuki656 opened this issue Jun 5, 2021 · 13 comments
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@vuki656
Copy link

vuki656 commented Jun 5, 2021

Is your feature request related to a problem? Please describe.
Yes, in a large project, there are often deeply nested files leading to file paths going out of bounds and file names not being visible:

image

Here a part of the file name is cut off, and if there was another file 1 level deeper, its name wouldn't be visible at all. This makes it difficult to spot what you are looking for.

Describe the solution you'd like
Not 100% sure but either to truncate the file path if too long, or fold it.

Another potential solution to this would be to display only file names in the list and the path next to them, similarly to how IntelliJ does it.

image

Thanks for the amazing plugin!

@vuki656 vuki656 added the enhancement Enhancement to performance, inner workings or existent features label Jun 5, 2021
@Conni2461
Copy link
Member

Telescope find_files shorten_path=true but note there will be a overhaul of how the filepath display options work: #839 this will also be cool #886

For making it dynamic there is a little bit missing because currently we don't know the result window width, when we calculate the display string, but i have an idea how we could do this.

@vuki656
Copy link
Author

vuki656 commented Jun 6, 2021

Telescope find_files shorten_path=true but note there will be a overhaul of how the filepath display options work: #839 this will also be cool #886

For making it dynamic there is a little bit missing because currently we don't know the result window width, when we calculate the display string, but i have an idea how we could do this.

That helps, thanks. Although I'm still looking forward as to what they will come up with in #839.

Also, not sure if I'm doing something wrong, but when I launch Telescope find_files shorten_path=true it works as expected, but If I set it in the config like so it doesn't work. Am I doing something wrong?

require('telescope').setup{
    shorten_path=true
}

@Conni2461
Copy link
Member

Yeah currently it doesn't work in the setup table (even tho the readme says so, no idea why it does in the first place) but #839 tries to fix this issue.

@vuki656
Copy link
Author

vuki656 commented Jun 6, 2021

Oh okay, feel free to close this issue if it's not going to be used for tracking as I would consider my problem solved.

Thanks for the help.

@l-kershaw
Copy link
Contributor

I am closing this now as path_display={"truncate"} has been implemented.

@rklak
Copy link

rklak commented Jan 26, 2022

It should goes like this in config, if you dont know how to setup it:

require('telescope').setup{
	defaults = {
		path_display={"smart"} 
	}
}

Check:
:help telescope.setup()

@nicos68
Copy link

nicos68 commented Aug 10, 2022

It should goes like this in config, if you dont know how to setup it:

require('telescope').setup{
	defaults = {
		path_display={"smart"} 
	}
}

Check: :help telescope.setup()

Thanks, it worked with find_files! However I tried the setting with Telescope lsp_references, it doesn't seem to work.

@arnevm123
Copy link
Contributor

I have the same issue aas @nicos68, this works for find_files, but not for lsp_references or git_status, did anyone find a solution for this?

@BlakeLeBlancGuernsey
Copy link

Similar results to @nicos68

In the uses I've tested, it seems that some of the options ("smart", "shorten", etc)

Do work with

  • builtin.buffers
  • builtin.find_files
  • builtin.live_grep

Do NOT work with

  • builtin.oldfiles
  • builtin.gitfiles

Perhaps there is something I haven't configured properly?

This is what I'm currently rocking in my init.lua:

  -- telescope
  {
    'nvim-telescope/telescope.nvim',
    config = function()
      require("telescope").setup({
        defaults = {
          layout_config = {
            vertical = {
              width = 0.95
            },
            horizontal = {
              width = 0.95
            },
          },
          path_display = {
            "shorten"
          },
        },
      })
    end
  },

@searleser97
Copy link

Similar results to @nicos68

In the uses I've tested, it seems that some of the options ("smart", "shorten", etc)

Do work with

  • builtin.buffers
  • builtin.find_files
  • builtin.live_grep

Do NOT work with

  • builtin.oldfiles
  • builtin.gitfiles

Perhaps there is something I haven't configured properly?

This is what I'm currently rocking in my init.lua:

  -- telescope
  {
    'nvim-telescope/telescope.nvim',
    config = function()
      require("telescope").setup({
        defaults = {
          layout_config = {
            vertical = {
              width = 0.95
            },
            horizontal = {
              width = 0.95
            },
          },
          path_display = {
            "shorten"
          },
        },
      })
    end
  },

Agree with this and also it doesn't work with extensions

@mturoci
Copy link

mturoci commented Jan 5, 2024

Agree with this and also it doesn't work with extensions

Same here. Custom function for path_display works for builtin.find_files, but not for builtin.git_status.

@jamestrew
Copy link
Contributor

I fixed the path_display option for git_status here #2881

I tested out oldfiles and git_files, but they appear to be working. Also looking at the code, they should work as well.

@sassanh
Copy link

sassanh commented Nov 16, 2024

@jamestrew is there a reason why path_truncate is not exposed in utils api?
Third parties and custom pickers would really benefit from it, specially considering it is using calc_result_length and it is too complicated and hacky for other developers to come to the conclusion they can achieve line length like that, I made it public for myself and now I can truncate paths in my custom picker like this:

utils.path_truncate(display_filename, 1, {})

I can't imagine how I could achieve this myself without reusing path_truncate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests