Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Support offset! query directive #58

Open
dvdsk opened this issue Oct 24, 2021 · 4 comments
Open

Support offset! query directive #58

dvdsk opened this issue Oct 24, 2021 · 4 comments

Comments

@dvdsk
Copy link
Contributor

dvdsk commented Oct 24, 2021

The offset directive (see :h offset!) is very useful for adjust a captures range however it does not change the range directly but instead adds a adjusted range to the content field to the metadata of the capture. Example query:

((string) @capture (#offset! @capture 0 1 0 -1))

This will adjust the range in the metadata to start one column later and end one column earlier. In python this gets the range of the string without the "

Currently the playground does not support this (probably because it uses node:range()). I think this could trivially be supported using:

local function range(node, meta)
	if meta.content ~= nil then
		return unpack(meta.content[1])
	else
		return node:range()
	end
end

I do not have the time right now but if you point me to where the query highlighting range is called I will drop in the change tomorrow and test it

@theHamsta
Copy link
Member

offset! directive is just a hack to make it work with injections and only with one capture. It would be better to implement offset in a proper way. E.g. to modify the node directly maybe a standardized way to set range metadata per node. But it shouldn't be a something just for offset! especially since offset! itself was just a temporary replacement for strip! @steelsojka

I don't think that the playground should manifest this temporary solution even further (why was offset! even documented?). I think implementing range modifications in core so that all plugins understand them would be a better solution.

If your PR is just about a request to show all metadata in playground, this would be perfectly feasible.

@kaddkaka
Copy link

kaddkaka commented Sep 28, 2023

offset! directive is just a hack to make it work with injections and only with one capture. It would be better to implement offset in a proper way. E.g. to modify the node directly maybe a standardized way to set range metadata per node. But it shouldn't be a something just for offset! especially since offset! itself was just a temporary replacement for strip! @steelsojka

I don't think that the playground should manifest this temporary solution even further (why was offset! even documented?). I think implementing range modifications in core so that all plugins understand them would be a better solution.

If your PR is just about a request to show all metadata in playground, this would be perfectly feasible.

You seem like you knew a lot about this. Do you think this can be improved?
Has there been any progress since 2 years ago?

@clason
Copy link
Contributor

clason commented Sep 28, 2023

Certainly not here; the only reason this repo is not archived is that the README may have to be updated (again) before the 0.10 release.

(This comment is two years old, and #offset! is now in Neovim core.)

@kaddkaka
Copy link

kaddkaka commented Sep 29, 2023

Is playground also in neovim core? Answer seems to be yes:

This plugin is deprecated since the functionality is included in Neovim: Use

:Inspect to show the highlight groups under the cursor
:InspectTree to show the parsed syntax tree ("TSPlayground")
:EditQuery to open the Live Query Editor (Nvim 0.10+)

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

No branches or pull requests

4 participants