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

Added smart_path option for file name getters. #1

Closed
wants to merge 3 commits into from
Closed

Added smart_path option for file name getters. #1

wants to merge 3 commits into from

Conversation

qualious
Copy link

tom-anders/telescope-vim-bookmarks.nvim#2

Hey!

So I've done this after the discussion with @Conni2461 and how this would overall benefit the project.

Placing myself at mercy, I've also decided to change the enum logic as well. So that a user doesn't have to deal with importing/exporting/creating enums but configure the options as it is (ie. smart_path = true)

Just to have the preview here as well:

Screenshot 2021-05-24 at 13 21 28

Let me know what you think!

Copy link
Owner

@caojoshua caojoshua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Before I look too deep into code, can you explain what exactly is a smart path? From your examples in File paths are relatively shown depending on other files tom-anders/telescope-vim-bookmarks.nvim#2, it looks like smart relative paths. Could we come up with a more specific name?
  2. Still not exactly sure how we are going to do enums, but TJ just responded in Consistent filepath display and code cleanup. nvim-telescope/telescope.nvim#839, so I'm gonna let that play out first
  3. Since I still don't fully understand, depending on how complicated this is, I might just let the current PR merge first, and then we can create this as a separate PR

@qualious
Copy link
Author

  1. I think the naming is reasonable. as you said, it's smart relative paths that are calculated based on other files names in the context. I wanted to keep the <>_path naming convention.
  2. Well, this was just a suggestion. Continue as you were
  3. I can comment out the code line by line here to make it more understandable. But basically it saves all files within the context and for each new file function looks at the difference between saved filepaths and current file. then according to their difference, it takes the biggest difference it can take (as in if a/b/c/d, a/b/d differs at index 1) and then adjusts the filenames according to the biggest index it can find, taking the one before it to give context. (../b/c/d/, ../b/d)

I thought it should be a separate implementation as well but I was directed to this by one of the main contributors - which makes it safe to merge in my mind. The function itself can benefit from open source community as well.

@caojoshua
Copy link
Owner

I updated my pull request in the main repo to not use enums: nvim-telescope#839

I think these changes would benefit Telescope, but I think these should be merged as a separate PR in the main repo in favor of smaller PRs. @Conni2461 would you prefer combining into one PR, or try to merge this separately after the current PR is merged? I can work with either way.

@Conni2461
Copy link

I don't really prefer one over the other. I am fine with both, tbh.

Note: we are squashing PRs so if you want full commit credit you probably want to make a separate PR to telescope :)

@qualious
Copy link
Author

Hey!

Wanted to say I don’t really care about that when it’s improving the product I’m using day to day. Thanks for y’all’s effort.

I can do the PR creation after this PR is merged if the owner prefers that way because I feel like that’s the case. Also maybe I can improve it in the meanwhile.

I’ve been using it locally for a while now and it’s working accordingly. there is a bug that happens every once in a while - the second file in the results shows up as full path sometimes when there are 4+ results. (i’m suspecting that there is a bug with initial loop logic) but if you hover over it, it corrects itself (i’m assuming because of rerender).

i can make the logic more solid to prevent such a thing and make it “production ready”. but we are going to go in a release cycle at work in a month or so — but i can make time here and there.

if you guys can give me an approximate merge time that’d be perfect for my planning.

also if things comes down to it @Conni2461 you can copy my code and improve it and push to the main repo. you have my explicit permission.

@@ -147,6 +148,83 @@ utils.path_tail = (function()
end
end)()

utils.slice = function(tbl, s, e)
local pos, new = 1, {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually want to copy all elements between s and e into a new table? Thats not great.

Maybe this plenary module can help https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/iterators.lua
No idea how it works tho. But i saw a range function. This is the spec file https://github.com/nvim-lua/plenary.nvim/blob/master/tests/plenary/iterators_spec.lua




PATHS = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a global right?

Comment on lines +191 to +192
final = utils.slice(initial_path, length - 1, length)
final = table.concat(final, "/")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are only using slice for create a string afterwards you should look for a different method.

Copy link
Author

@qualious qualious May 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i figured that but i was like “i’m already using it 🤷🏻‍♀️“.

it’s a quick hack, not production ready at all. i’ll fix these if i’m going to open the pr on the main repo. i appreciate the feedback

edit: and i honestly wasn’t hopeful about the initial PR. i didn’t know we would get you involved

@caojoshua
Copy link
Owner

Hey!

Wanted to say I don’t really care about that when it’s improving the product I’m using day to day. Thanks for y’all’s effort.

I can do the PR creation after this PR is merged if the owner prefers that way because I feel like that’s the case. Also maybe I can improve it in the meanwhile.

I’ve been using it locally for a while now and it’s working accordingly. there is a bug that happens every once in a while - the second file in the results shows up as full path sometimes when there are 4+ results. (i’m suspecting that there is a bug with initial loop logic) but if you hover over it, it corrects itself (i’m assuming because of rerender).

i can make the logic more solid to prevent such a thing and make it “production ready”. but we are going to go in a release cycle at work in a month or so — but i can make time here and there.

if you guys can give me an approximate merge time that’d be perfect for my planning.

also if things comes down to it @Conni2461 you can copy my code and improve it and push to the main repo. you have my explicit permission.

Maybe can merge in a week-ish.

I've linked to this pull request as a TODO from this Telescope wiki, to make sure this is on our radars.

@menash134
Copy link

Hi, I also looking for smart file paths. My idea would be naive and simple. could you just allow me to configure the depths of the file path to be displayed? This would be ideal for my usecase. may be before the depth it could be "hidden/shorten"!!!

@caojoshua
Copy link
Owner

Hey, this is my fork that I use for my own pull requests. You might want to check nvim-telescope#914, although seems that pull request is not active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants