!NRhNKUEoESUdXFNGzc:matrix.org

LuaSnip

71 Members
A Neovim snippet engine in Lua | https://github.com/L3MON4D3/LuaSnip10 Servers

Load older messages


SenderMessageTime
8 Jan 2024
@l3mon4d3:matrix.orgL3MON4D3
In reply to @maxigaz:matrix.org

However, I still couldn't figure out how to make it work with a text node, where the each choice that is inserted is highlighted in select mode.

You mentioned storing the results of vim.fn.getreg('"') in a local variable and then applying :gsub on it (if I understood correctly), but I don't know how to do that.

So, the issue is that gsub returns 2 values, and these are unpacked into two arguments to t, which caused your first issue (t expects a table as the second argument)
What you can do to fix this is write something like local gsubbed_text = ...:gsub(...) and then pass gsubbed_text to t.
18:15:40
@maxigaz:matrix.orgmaxigaz
In reply to @l3mon4d3:matrix.org
So, the issue is that gsub returns 2 values, and these are unpacked into two arguments to t, which caused your first issue (t expects a table as the second argument)
What you can do to fix this is write something like local gsubbed_text = ...:gsub(...) and then pass gsubbed_text to t.

Oh, I see it now. I wasn't sure where to define that variable, but I changed my original snippet like this:

    c(1, {
      d(1, function()
          local gsubbed_text = vim.fn.getreg('"'):gsub("\n", "")
          return sn(1, fmt("{}", { i(1, gsubbed_text ) }))
        end, {}),
      d(2, function()
          local gsubbed_text = vim.fn.getreg('+'):gsub("\n", "")
          return sn(1, fmt("{}", { i(1, gsubbed_text ) }))
        end, {}),
    }),

It's working now. Thank you very much!

20:21:10
@maxigaz:matrix.orgmaxigaz
In reply to @l3mon4d3:matrix.org
So, the issue is that gsub returns 2 values, and these are unpacked into two arguments to t, which caused your first issue (t expects a table as the second argument)
What you can do to fix this is write something like local gsubbed_text = ...:gsub(...) and then pass gsubbed_text to t.
*

Oh, I see it now. I wasn't sure where to define that variable, but with your help, I changed my original snippet like this:

    c(1, {
      d(1, function()
          local gsubbed_text = vim.fn.getreg('"'):gsub("\n", "")
          return sn(1, fmt("{}", { i(1, gsubbed_text ) }))
        end, {}),
      d(2, function()
          local gsubbed_text = vim.fn.getreg('+'):gsub("\n", "")
          return sn(1, fmt("{}", { i(1, gsubbed_text ) }))
        end, {}),
    }),

It's working now. Thank you very much!

20:22:17
@l3mon4d3:matrix.orgL3MON4D3You're welcome :)20:52:45
10 Jan 2024
@mddj23wm:envs.net@mddj23wm:envs.net joined the room.10:46:27
14 Jan 2024
@hiweed:matrix.orghiweed joined the room.13:07:36
20 Jan 2024
@ludv:matrix.org@ludv:matrix.org left the room.09:20:15
12 Feb 2024
@bennypowers:matrix.orgBenny Powers changed their profile picture.07:08:56
27 Feb 2024
@muniter:matrix.orgmuniter changed their display name from muniter to Javier López.12:29:54
16 Mar 2024
@muniter:matrix.orgmuniter changed their display name from Javier López to muniter.15:58:34
26 Mar 2024
@neurognostic:kde.orgNeurognostic joined the room.17:53:53
3 Apr 2024
@gambhir_sharma:matrix.orgGambhir ⚡image.png
Download image.png
08:38:42
@gambhir_sharma:matrix.orgGambhir ⚡I want to extend the javascript snip to typescript, typescriptreact, javascriptreact and vue. How can I write this in a better way. 08:39:48
@l3mon4d3:matrix.orgL3MON4D3That's the best way :P11:22:09
19 Apr 2024
@gokberkgunes:matrix.orggokberkgunes joined the room.08:27:43
@gokberkgunes:matrix.orggokberkgunesHello08:27:52
@l3mon4d3:matrix.orgL3MON4D3Hi :)08:35:10
@gokberkgunes:matrix.orggokberkgunes L3MON4D3: I am the one reported the exit node issues, can I talk to you about the approach you suggested here? I am trying to implement it but have some questions. 08:43:33
@l3mon4d3:matrix.orgL3MON4D3Oh yeah, feel free to08:43:52
@gokberkgunes:matrix.orggokberkgunes
function ExitNode:jump_into(dir, no_move, dry_run)
	if not session.config.history then
		local next_node = util.ternary(dir == 1, self.next, self.prev)
		if dir == 1 and next_node then
			vim.print("")
			self:input_enter(no_move, dry_run)
			return next_node
		end

		-- If exiting node from the end
		if (dir == 1 and not self.next) then
			self:input_enter(no_move, dry_run)
			return nil
		elseif (dir == -1 and not self.prev) then
			self:input_enter(no_move, dry_run)
			return self
		end
	end
	return self
end


I've started by such a function, this is how you suggested, right?

08:46:17
@gokberkgunes:matrix.orggokberkgunesI'm using vim.print("text") to debug the code. I don't know any better way please ignore them08:47:03
@l3mon4d3:matrix.orgL3MON4D3Ah no: I meant in `init.lua`, there's `jump(dir)`, where the next current_nide would be set. There, you could check whether it is a $0 (node.pos==0 and whether it belongs to a root-snippet (node.parent.snippet.parent_node == nil), and then just set the current_node to nil08:50:54
@gokberkgunes:matrix.orggokberkgunesOh okay, I'll take a look.08:58:12
@gokberkgunes:matrix.orggokberkgunes
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..6533815 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -159,6 +159,10 @@ end
 local function jump(dir)
 	local current = session.current_nodes[vim.api.nvim_get_current_buf()]
 	if current then
+		if (current.pos == 0 and current.parent.snippet.parent_node == nil) then
+			session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+			return false
+		end
 		session.current_nodes[vim.api.nvim_get_current_buf()] =
 			util.no_region_check_wrap(safe_jump_current, dir)
 		return true

I think this is what you told me, right? This function should return false when we're at $0 and it is root snippet

09:13:24
@l3mon4d3:matrix.orgL3MON4D3Almost, the new node is returned by safe_jump_current, we'd have to handle it's return-value09:15:42
@l3mon4d3:matrix.orgL3MON4D3Ah, and the `.snippet` can even be omitted, if pos is 0 the parent already is the snippet09:17:02
@gokberkgunes:matrix.orggokberkgunes Do you mean current.parent.snippet.parent_node == nil can be omitted? Without this, snippets exit inside the child too. 09:19:03
@l3mon4d3:matrix.orgL3MON4D3Just the .snippet in that chain, current.parent.parent_node is enough09:19:57
@gokberkgunes:matrix.orggokberkgunesah alright.09:20:05
@gokberkgunes:matrix.orggokberkgunes
In reply to @l3mon4d3:matrix.org
Almost, the new node is returned by safe_jump_current, we'd have to handle it's return-value
can we use return jump_destination(dir)?
09:25:09

Show newer messages


Back to Room ListRoom Version: 6