telescope.nvim icon indicating copy to clipboard operation
telescope.nvim copied to clipboard

Provide option to allow path processing of URIs

Open miversen33 opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. Telescope Utils contains a function called transform_path that is utilized by various pieces of telescope (and telescope plugins such as telescope-file-browser) to determine how to format a string to be displayed within telescope. This function immediately escapes (via returning the provided path) if the function determines that the path is a "URI", artificially limiting support for nonlocal resources.

Describe the solution you'd like I think the above is a fine default, but consider allowing an option to be provided that can say "yes allow URIs to be processed as well" would enable further development of plugins that could better consume and manage remote resources. For example

utils.transform_path = function(opts, path)
  if path == nil then
    return
  end
  if not opts.allow_uris and is_uri(path) then
    return path
  end

Describe alternatives you've considered NA

Additional context For a concrete example, I have an issue on my project's issue board that would be able to be better handled if Telescope provided the ability to allow URI's to be processed by a provided display function. From looking at the source code for utils.transform, it appears the logic is already there to handle using a function to format the display string, as a URI is being passed in (in my case), the ability to format the string is completely negated.

Edit: Fixed formatting because formatting hard

miversen33 avatar May 18 '22 04:05 miversen33

Yes, we should enable such a use case (remote telescoping). Would you be willing to work towards a PR for that use case? Mostly because you'd be the first-mover actually using that functionality :)

fdschmidt93 avatar May 18 '22 10:05 fdschmidt93

I have no issue with it! I'll see if I can throw it together this weekend.

miversen33 avatar May 18 '22 11:05 miversen33

I am also facing the same issue, trying to simplify the uri to display it in a more readable way (e.g. the jdtls symbols). Turns out the transform path cuts too early, even before path display callback is called.

For now, what i did is something simple like that before configuring telescope

local path_transformer = utils.transform_path
utils.transform_path = function(opts, path)
    if path and string.match(path, "^%w+://") ~= nil then
        path = path:match("jdt://contents/[^/]*/(.*)?="):gsub("/", ".")
    end
    return path_transformer(opts, path)
end

asmodeus812 avatar Jan 29 '23 17:01 asmodeus812

Will also be awesome if you can give some actual documentation about the options that transform_path takes. It only mentions one property it will read, but nothing about what that property should be

danielo515 avatar Feb 01 '23 07:02 danielo515

@danielo515 the opts that transform path receives are the opts passed in to the picker it is invoked by. So opts contains pretty much everything, the previewer, finder etc. It is better if you don't mutate them in transform if you can avoid doing so, and just read them to accomplish your use case. The example above i gave is not the most robust, if the match fails, it will return nil and gsub will fail too but it was just a quick snippet.

asmodeus812 avatar Feb 01 '23 08:02 asmodeus812

Sorry, I was taking the context of the issue to propose to improve the current docs on path_display. Opening a new issue is such a big task for something this small that I took a shortcut. Sorry

On Wed, Feb 1, 2023 at 9:25 AM Svetlozar Iliev @.***> wrote:

@danielo515 https://github.com/danielo515 the opts that transform path receives are the opts passed in to the picker it is invoked by. So opts contains pretty much everything, the previewer, finder etc. It is better if you don't mutate them in transform if you can avoid doing so, and just read them to accomplish your use case. The example above i gave is not the most robust, if the match fails, it will return nil and gsub will fail too but it was just a quick snippet.

— Reply to this email directly, view it on GitHub https://github.com/nvim-telescope/telescope.nvim/issues/1942#issuecomment-1411645668, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWMQIKU4DFQCD3IR3CLWVIMYVANCNFSM5WHAD2BA . You are receiving this because you were mentioned.Message ID: @.***>

--

https://danielorodriguez.com

danielo515 avatar Feb 01 '23 09:02 danielo515