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

Changed the results window highlight to always be full width #1312

Merged
merged 11 commits into from Oct 29, 2021

Conversation

TC72
Copy link
Contributor

@TC72 TC72 commented Oct 6, 2021

Thought it was easier to submit this to show the effect working than describe it.
Making the selection movement easier on the eye by staying full width, not sticking to the content width.

Normal Width

Full Width

The code I've written is a very quick hack, it just adds spaces to the end of a line to pad it out.
This can probably be done in a much nicer way using virtual text which could allow it to happen on the previewer as well.
I've also had to add an extra 2 to the width for the math to work correctly, still looking at why.

I'm looking into what's going on with the = not being highlighted, don't think it's related to this code.

@fdschmidt93
Copy link
Member

fdschmidt93 commented Oct 6, 2021

I'm personally happy to have full line highlighting, though as you've said, better to use extmarks.

a.nvim_buf_add_highlight(results_bufnr, ns_telescope_selection, "TelescopeSelection", row, #caret, -1)

would have to be changed to

  a.nvim_buf_set_extmark(
    results_bufnr,
    ns_telescope_selection,
    row,
    #caret,
    { end_line = row + 1, hl_eol = true, hl_group = "TelescopeSelection" }
  )

In telescope/previewers/buffer_previewer.lua all nvim_buf_add_highlight with TelescopePreviewLine would have to be changed accordingly I think.

@TC72
Copy link
Contributor Author

TC72 commented Oct 7, 2021

@fdschmidt93 Thanks for explaining how to use extmark.
Something very strange is happening though. If I use that code and then use find_files, if I filter the results to only have 1 anf then select it I get a segfault every time.

So if I start in the directory telescope.nvim/lua/telescope then run :Telescope find_files then type buffer so the only result is buffer_previewer.lua then press enter to select it, segfault every time..

Sometimes it throws some error info on the screen:

nvim(82111,0x105103d40) malloc: *** error for object 0x106780d00: pointer being freed was not allocated
nvim(82111,0x105103d40) malloc: *** set a breakpoint in malloc_error_break

@fdschmidt93
Copy link
Member

That's strange, doesn't seem to be happening for me and works just as expected.. mhm, could you paste the output of nvim -v please (wondering if your neovim is linked against the right luajit)? In any case, I think that would be an upstream issue.

@TC72
Copy link
Contributor Author

TC72 commented Oct 7, 2021

I can fix it using either nvim_buf_clear_namespace or nvim_buf_del_extmark.
When we teardown preview windows we us nvim_buf_clear_namespace so we should be doing the same for the results window?

Here's the version info:

NVIM v0.6.0-dev+191d3e6af
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210709-33080-1swmtjw/build/config -I/tmp/neovim-20210709-33080-1swmtjw/src -I/opt/homebrew/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/opt/homebrew/opt/gettext/include -I/tmp/neovim-20210709-33080-1swmtjw/build/src/nvim/auto -I/tmp/neovim-20210709-33080-1swmtjw/build/include
Compiled by julianf@Mac-mini.local

Features: +acl +iconv +tui
See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/HEAD-191d3e6/share/nvim"

Run :checkhealth for more info
%

@fdschmidt93
Copy link
Member

Ok luajit shouldn't be an issue.

I can fix it using either nvim_buf_clear_namespace or nvim_buf_del_extmark.

Could you please push the commit? Then I can more easily follow 😅

@clason
Copy link
Contributor

clason commented Oct 7, 2021

possibly related: neovim/neovim#15940

@TC72
Copy link
Contributor Author

TC72 commented Oct 7, 2021

Could you please push the commit? Then I can more easily follow 😅

Sorry, that's done.

@fdschmidt93
Copy link
Member

fdschmidt93 commented Oct 7, 2021

Just to make sure, I've just now cleanly rebuild neovim on latest master (with clean runtime files etc) and checked out your PR. Still works for me as expected. I guess must be something upstream that has unexpected local interactions ala above linked issue?

@TC72
Copy link
Contributor Author

TC72 commented Oct 7, 2021

Thanks for checking, I'll change to using that one.

In general should we be clearing the namespace when we close the results window, in the same way we do for previews? Or is it just that previews are a special case because you could switch between different previewers?

@fdschmidt93
Copy link
Member

fdschmidt93 commented Oct 7, 2021

In general should we be clearing the namespace when we close the results window, in the same way we do for previews? Or is it just that previews are a special case because you could switch between different previewers?

At first glance, I'm not so concerned about this. Extmarks are attached to buffers and the telescope buffers get wiped (brr, actually they just get deleted, something I think we should change, as in why only delete and not wipe? why not with api? commented that on another PR as well). I guess for previewers it's more that we have to clean up a lot more buffers, and therefore we have a dedicated clean up function.

Hopefully your segfault gets fixed with: neovim/neovim#15932

@fdschmidt93
Copy link
Member

I think the relevant PRs got merged, does the error get fixed for you after clean recompilation?

@TC72
Copy link
Contributor Author

TC72 commented Oct 8, 2021

Hi @fdschmidt93 yes, the latest build fixes the issue.
I'll get the code done for the preview as well.

@TC72
Copy link
Contributor Author

TC72 commented Oct 14, 2021

I've been testing this for the preview window but there's an issue.
It throws error messages because I'm trying to use a line number that doesn't exist when the previewer shows "Previewer timed out".
I'm sure I can detect that but why are previewers now showing that message? I've searched through issues and don't find anyone else talking about this. It's not related to my code as I can still get that message after removing my code.

@TC72
Copy link
Contributor Author

TC72 commented Oct 14, 2021

@fdschmidt93 would it be possible to merge this and I'll add the same for the preview window in a separate PR?

@fdschmidt93
Copy link
Member

I've been testing this for the preview window but there's an issue.
It throws error messages because I'm trying to use a line number that doesn't exist when the previewer shows "Previewer timed out".
I'm sure I can detect that but why are previewers now showing that message? I've searched through issues and don't find anyone else talking about this. It's not related to my code as I can still get that message after removing my code.

Did you wrap it in a pcall similar as it's done for the vimgrep previewer?

pcall(vim.api.nvim_buf_add_highlight, bufnr, ns_previewer, "TelescopePreviewLine", lnum - 1, 0, -1)

you'd be happy to push your WIP :) then I can more easily comment.

would it be possible to merge this and I'll add the same for the preview window in a separate PR?

It's a cosmetic change I personally like. Not sure how other team members feel about this ;) I'd also prefer to merge it just at once as it otherwise might have an odd look and feel to be honest.

@TC72
Copy link
Contributor Author

TC72 commented Oct 14, 2021

Yes, it's in a pcall().
I just moved back to master and I can still get the preview to show "Previewer timed out", so it's unrelated.

I've pushed it now, it's just the previewers.vimgrep preview right now.
Thanks again for your help on this.

-- nvim_buf_add_highlight({buffer}, {ns_id}, {hl_group}, {line}, {col_start}, {col_end})
-- nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {*opts})

pcall(
Copy link
Member

Choose a reason for hiding this comment

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

Slight syntactical error.

It should be

pcall(
  vim.api.nvim_buf_set_extmark,
  bufnr,
  ns_previewer,
  lnum - 1,
  0,
  { end_line = lnum, hl_eol = true, hl_group = "TelescopePreviewLine"}
)

(hoping to have set the commas etc here correctly). Compare it to how it was before in the diff.

pcall(function, ...) where ... are you function arguments. What happens in your case that you call pcall(extmark_id) essentially.

That explains why it works when it should and doesn't call nvim_buf_set_extmark in protected fashion, when it shouldn't work :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DOH!!

Thanks for setting me back on track.

@Conni2461
Copy link
Member

Can someone get me up to date? I think this PR achieves what it tries to achieve: "Changed the results window highlight to always be full width". Changing every vim.api.nvim_buf_add_highlight to extmark is out of scope in my opinion and should happen in a different PR.

Also i dont think its worth the effort to do it for every Previewer line highlight. Its one line for each selection change. I dont think this is bottle necking.

We could talk about making the full line optional or we just merge full line and then see if anyone complains.

@TC72
Copy link
Contributor Author

TC72 commented Oct 24, 2021

@Conni2461 the highlight for the results window works and I'd done the same just for the vimgrep previewer.

I'd be happy to just do this for the results window now and come back to the previews.

@Conni2461
Copy link
Member

Conni2461 commented Oct 24, 2021

I felt like this previewer work is unrelated and just "blocking" this PR so we can do it in two separate PRs. Can you clean up this PR after that we decide what we should do regarding the preferences from users. full line vs only highlight text.

@TC72
Copy link
Contributor Author

TC72 commented Oct 24, 2021

@Conni2461 I've pushed a clean version with just the single change in pickers/highlights.lua

@Conni2461
Copy link
Member

Are you sure? 0ca7c58

@TC72
Copy link
Contributor Author

TC72 commented Oct 26, 2021

@Conni2461 that's done.
Am I OK to trust that telescope.confiv.values.hl_result_eol will always have a value because I've given it an entry in config.lua?

@TC72
Copy link
Contributor Author

TC72 commented Oct 29, 2021

@Conni2461 I've tried pushing this to run the tests again but it's failing with issues due to tar and zip that I can't do anything about.

@Conni2461
Copy link
Member

Conni2461 commented Oct 29, 2021

Sorry. Busy week (which isnt really a excuse i know, i am still sorry).

Code LGTM now thanks :)

I gonna try it out and generate the docs :)

Thanks for the PR :) i probably merge in the next 10 minutes

Edit: CI failure is unrelated. Please ignore that failure. Its most likely github doing weird things because its happening only sometimes.

@Conni2461 Conni2461 merged commit 3b9ac8e into nvim-telescope:master Oct 29, 2021
@SwenChan
Copy link

SwenChan commented Oct 29, 2021

Excuse me, I have updated to the newest version of tel and I have found that my nvim will crash after I select an item from selections.
Here:
image
or when I tap Esc twice when I'm in insert mod, got this:
image

And after I use last commit, neovim become normal(means that the appearance above disappear)
here is my config:

return require('packer').startup({function(use)
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'
  use {
    'nvim-treesitter/nvim-treesitter',
    run = ':TSUpdate'
  }
  -- stdlib for lua
  use 'nvim-lua/plenary.nvim'
  use {
    'nvim-telescope/telescope.nvim',
    commit = "02a02f7bcdfb1f207de6649c00701ee1fe13a420",
    requires = { {'nvim-lua/plenary.nvim'} },
    config = function ()
      require("lua.plugin_config.telescope")
    end
  }


  use {
    'EdenEast/nightfox.nvim',
    config = function ()
      require('lua.plugin_config.nightfox')
    end
  }

  use {
    'goolord/alpha-nvim',
    config = function ()
        require("lua.plugin_config.alpha")
    end
  }

  use {'neoclide/coc.nvim', branch = 'master', run = 'yarn install --frozen-lockfile'}
end,
config = {
  display = {
   open_fn = function()
   return require('packer.util').float({ border = 'single' })
   end,
   }
  }
})
NVIM v0.5.0
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210702-21950-fs4dxz/neovim-0.5.0/build/config -I/tmp/neovim-20210702-21950-fs4dxz/neovim-0.5.0/src -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210702-21950-fs4dxz/neovim-0.5.0/build/src/nvim/auto -I/tmp/neovim-20210702-21950-fs4dxz/neovim-0.5.0/build/include
Compiled by brew@iMac-Pro

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.5.0/share/nvim"

Run :checkhealth for more info
tmux 3.2a

@Conni2461
Copy link
Member

Conni2461 commented Oct 29, 2021

Can you update to neovim 0.5.1 (if that segfault is still happening there. I will revert).

Edit: I know the segfault is fixed in nightly.

@TC72
Copy link
Contributor Author

TC72 commented Oct 29, 2021

I was having that segfault when I 1st started working on this.
I just tried it with 0.5.1 and I do not get the segfault issue.

Sorry but I can see this being a pain in the ass.

@SwenChan
Copy link

Can you update to neovim 0.5.1 (if that segfault is still happening there. I will revert).

Edit: I know the segfault is fixed in nightly.

Thx. The issue was gone when I use neovim@0.5.1

@Conni2461
Copy link
Member

Sorry tc. I have to revert this :| I am not happy about this decision.

We should try to implement this feature without relying on nvim_buf_set_extmark and hl_eol

@TC72
Copy link
Contributor Author

TC72 commented Oct 31, 2021

@Conni2461 no problem, it has to be done right.

@fdschmidt93
Copy link
Member

fdschmidt93 commented Nov 1, 2021

no problem, it has to be done right.

Fwiw, this is the right solution. Extmarks are a critical API and segfaults were fixed super swiftly once they occurred upstream.

Maybe a working compromise would be to set hl_results_eol=false (or nil) via a version check, assuming the extmark api otherwise works. Probably much fewer headaches to just bump minimum version to 0.5.1 though and re-merge then, unless there's a material reason to support 0.5.0 in addition to current stable nvim release. Saves low leverage of resources trying to make this work.

@clason
Copy link
Contributor

clason commented Nov 1, 2021

FWIW, 0.6.0 is planned for the end of the month (if all goes according to plan, which it never does...)

And Neovim itself supports only two versions:

  1. the last stable (0.5.1 currently, 0.6.0 when that is released)
  2. the latest commit on master
    Plugins should do the same unless they have good reason.

@Conni2461
Copy link
Member

Fwiw, this is the right solution.

i know that. Just segfaulting 0.5.0

I didnt bump the version because VimR is still on 0.5.0: #1391 (comment)

@clason
Copy link
Contributor

clason commented Nov 1, 2021

didnt bump the version because VimR is still on 0.5.0

Yeah, but there's no indication that it will be updated anytime soon, if ever (great talk at vimconf notwithstanding). An unmaintained (or at least on hiatus) GUI should not hold back telescope development...

@TC72
Copy link
Contributor Author

TC72 commented Nov 1, 2021

no problem, it has to be done right.

Fwiw, this is the right solution. Extmarks are a critical API and segfaults were fixed super swiftly once they occurred upstream.

@fdschmidt93 just to be clear, I meant the way it gets released has to be right. Something so vital to telescope can't be causing problems for people running 0.5.0.

@clason
Copy link
Contributor

clason commented Nov 1, 2021

Disagree; people should be using 0.5.1; otherwise you have to keep supporting every release until eternity.

The right thing to do for a plugin would be to tag a commit before using 0.5.1 specifics so people who can't update can freeze the plugin at the last compatible state.

@Conni2461
Copy link
Member

Conni2461 commented Nov 1, 2021

people should be using 0.5.1

Yeah i agree, people should do that. If you guys wanna bump it for this feature then feel free. But we have to expect a lot of tickets. We still get tickets from people that have issues with the recent plenary.popup additions because they are using a 0.5.0-dev version (#1394, nvim-lua/plenary.nvim#219 and more)

I just dont have the time and will to deal with it.

@clason
Copy link
Contributor

clason commented Nov 1, 2021

Put a clear notice at the top of the readme and be done with it :) I'll be happy to step in and close any issues from people on unsupported versions :]

@Conni2461
Copy link
Member

@TC72 wanna do a new PR with a version bump ?

@TC72
Copy link
Contributor Author

TC72 commented Nov 1, 2021

@Conni2461 #1403
Is that OK?

razak17 pushed a commit to razak17/telescope.nvim that referenced this pull request Feb 1, 2022
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.

None yet

5 participants