-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
feat: vim.inspect_pos()
, vim.show_pos()
and :Inspect
#21393
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
Conversation
vim.highlight.show
shows the highlights under the cursor
Could it display them in ascending order of priority? That would be pretty neat! Could easily visualize which highlights override others. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very useful! However I'm thinking this is a bigger bucket than "highlights". I see two problems being solved here:
- we want a way to "give me all the things at this position"
- I propose this lives at
vim.get_at_pos(pos, filter)
which returns a dict of all the various things that may decorate a buffer position. (virtual text? decorations? etc.)- doesn't need to implement everything initially, we can add more later.
- (future?)
filter
arg could be similar to that ofvim.lsp.get_active_clients()
- I propose this lives at
- display the result in a nice way
- Not sure what to do with this. Perhaps we should start with just a command, like
:Inspect
(could also claimzS
, in analogy to scriptease)- If it's meant to be interactive, not programmatically used, shouldn't it be a command?
- The idea is, we want to have this useful thing,
but I'm not sure we want a bunch ofEdit:foo.show_x
everywhere with randomly different behavior. At least, not yet?vim.inspect_pos()
vim.show_pos()
- Not sure what to do with this. Perhaps we should start with just a command, like
Just a note: It'd be good to distinguish here between LSP semantic token type and token modifiers. (The exact source of these highlights is important information.) |
For |
yes, for sure! Haven't looked closely yet at the new Semantic Tokens API. Will look into it and add the changes |
@justinmk where do you propose to add |
ad15e88
to
543d53b
Compare
vim.highlight.show
shows the highlights under the cursorvim.inspector
to get/show items at a given buffer position
not sure |
@max397574 wasn't sure what the concensus is right now. Maybe @justinmk can chime in on this? |
a5f6b82
to
ccefbd3
Compare
4ade9ca
to
fbbb847
Compare
I suggest
confused by the question because |
I don't think it's necessary to duplicate the semantic tokens under the |
@clason wasn't sure about the extmarks. Might make sense to include them there too, since they are effectively extmarks, but that's indeed duplication. Treesitter is different since those extmarks are ephemeral, so they are not visible as an extmark. But you're right. Will exclude the semantic token ones. I still haven't fully looked into the semantic tokens. Can a modifier be used as a hl group on its own? Or is it always in combination with the token type? Like |
@justinmk api indexing is normally 0-0 based, but some functions are indeed 1-0 mark based. Editor vim.fn functions are 1-1 based. Currently I used 0-0 api indexing, because i thought that's what all the new things use but i might be wrong. Treesitter, semantic tokens etc all use api indexing as well, so 0-0 based. @clason what do you think? |
Semantic tokens API is 0-0 based |
Currently they are added as their own highlight group, but eventually we’ll be updating the way they work to somehow allow combinations of types with modifiers (potentially like |
b06d0fc
to
120ecd6
Compare
120ecd6
to
1f9cf56
Compare
@clason updated! |
1f9cf56
to
ef91146
Compare
I wants it, I merges it -- further changes can be made in the follow-up PR. Noice job, @folke! |
@clason awesome, thanks! |
Neat stuff. But aren't core commands supposed to start with a small letter? |
Yes, but this is not a core command. It's provided by a (bundled) runtime plugin, same as |
Inspect might be a good addition to the default mouse right-click menu. |
|
I was curious what happens if I do |
This PR adds
vim.inspect_pos()
,vim.show_pos()
and:Inspect
to get/show the items at a given buffer position.This PR includes 2e328ba
vim.semantic_tokens.get_at_pos
Right now, the function uses
nvim_echo
, but I can change it to use a floating window if that would be better suited.Todo
nvim_create_user_command
somewhere. What would be the best place for this?_editor.lua
?plugin/inspector.lua
?news.txt
Included Items
Implementation details
runtime/lua/vim/_inspector.lua
_init_packages.lua
, so there's no impact on performancenil
, meaning the position under the cursorUser Commands
:Inspect
is the same asvim.show_pos()
:Inspect!
is the same asvim.pretty_print(vim.inspect_pos())
vim.show_pos(bufnr, row, col, filter)
vim.inspect_pos(bufnr, row, col, filter)