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

fix(picker): set current_line state earlier #3052

Merged
merged 1 commit into from
May 16, 2024

Conversation

jamestrew
Copy link
Contributor

Sets the current_line global state earlier in the event loop rather than in get_results_completor. This makes it safer to access current_line earlier (eg. for building an entry).

closes #3051

I'm not super confident this is safe to do without some unintended side effects. I've experienced some finicky race conditions with the picker:_get_prompt before so I'll use this branch for a bit.

Sets the `current_line` global state earlier in the event loop rather
than in `get_results_completor`. This makes it safer to access
`current_line` earlier (eg. for building an entry).
@schoblaska
Copy link

Thanks for the quick patch! I'll run this branch in my config as well.

@jamestrew
Copy link
Contributor Author

I haven't come across any issues myself but I wanna double check with @Conni2461 before merging this. Maybe there's some good reason not obvious to me for why we previously set current_line pretty late in our picker event loop.

@schoblaska
Copy link

schoblaska commented May 16, 2024

I've been running this branch for a month now with no issues. Is there anything I can do to help get it merged?

For some more context, I'm using this feature to implement a limited depth file tree browser that switches to default paths when you start typing.

Screen.Recording.2024-05-15.at.7.08.03.PM.mov
extensions = {
  file_browser = {
    path_display = function(opts, path)
      local action_state = require("telescope.actions.state")
      local current_line = action_state.get_current_line()

      if current_line == "" and opts.finder.files and path:match("%w+/%w+") then
        return path:gsub("^.+/", "  ")
      else
        return path
      end
    end,
    wrap_results = false,
    depth = 2,
  },
}

@jamestrew
Copy link
Contributor Author

ok let's merge this then before I forget about it.

@jamestrew jamestrew merged commit 52f5001 into nvim-telescope:master May 16, 2024
8 checks passed
@jamestrew jamestrew deleted the fix/set-current-line branch May 16, 2024 01:09
Conni2461 pushed a commit that referenced this pull request May 20, 2024
Sets the `current_line` global state earlier in the event loop rather
than in `get_results_completor`. This makes it safer to access
`current_line` earlier (eg. for building an entry).

(cherry picked from commit 52f5001)
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.

actions.state.get_current_line() is incorrect inside path_display function
2 participants