playground icon indicating copy to clipboard operation
playground copied to clipboard

Support offset! query directive

Open dvdsk opened this issue 2 years ago • 4 comments

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

dvdsk avatar Oct 24 '21 12:10 dvdsk

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.

theHamsta avatar Oct 24 '21 18:10 theHamsta

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?

kaddkaka avatar Sep 28 '23 20:09 kaddkaka

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.)

clason avatar Sep 28 '23 21:09 clason

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+)

kaddkaka avatar Sep 29 '23 04:09 kaddkaka