!NRhNKUEoESUdXFNGzc:matrix.org

LuaSnip

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

Load older messages


SenderMessageTime
19 Apr 2024
@gokberkgunes:matrix.orggokberkgunes There is a problem using that function. jump_destination function is defined after jump function. 09:27:01
@l3mon4d3:matrix.orgL3MON4D3Jump has to modify the snippet-tree, and jump_destination does not, we have to stick with safe_jump_current for this09:31:20
@l3mon4d3:matrix.orgL3MON4D3What's the problem?09:31:29
@l3mon4d3:matrix.orgL3MON4D3* What's the problem with safe_jump_current?09:31:48
@gokberkgunes:matrix.orggokberkgunes Nothing, I'm trying to understand how safe_jump_current works. Does this snippet-tree modification appear due to { active = {} }? 09:33:52
@gokberkgunes:matrix.orggokberkgunes So, return safe_jump_current(dir, true, {}) should work? 09:35:19
@l3mon4d3:matrix.orgL3MON4D3Ah alright :D The tree is modified because we don't pass no_move and that other key to jump_from09:35:40
@gokberkgunes:matrix.orggokberkgunes I am not sure about if we should pass active or not such that return safe_jump_current(dir, true, { active }) 09:36:46
@l3mon4d3:matrix.orgL3MON4D3I think I don't know what you're figuring out just now 😅 I would've put the return-value from util.no_region_check_wrap(safe_jump...) into a temporary variable node, check whether it's the $0 of a root, if it is, set nil for current_node else set node as current_node09:38:11
@l3mon4d3:matrix.orgL3MON4D3Ah! If I write current_node, I meant session.current_nodes[vim.api...], srry for that09:38:44
@gokberkgunes:matrix.orggokberkgunes Sorry, I'm pretty foreign how luasnip works. Since you suggested that we should use safe_jump_current to figure of return value of jump function. I wanted to see which parameters should I pass to safe_jump_current. 09:48:06
@l3mon4d3:matrix.orgL3MON4D3Oh, you can leave the safe_jump_current-call as-is09:56:10
@l3mon4d3:matrix.orgL3MON4D3Right now, we'd do the jump and always store the jumped-to node in session.current_nodes. I'd propose to instead do the jump and only conditionally store the node in current_nodes, ie. don't store if it is the $0 of a root-snippet09:58:28
@gokberkgunes:matrix.orggokberkgunes
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..4183df9 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,6 +158,12 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
 	local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+	if (current.pos == 0 and current.parent.parent_node == nil) then
+		session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+		return true
+	end
+
 	if current then
 		session.current_nodes[vim.api.nvim_get_current_buf()] =
 			util.no_region_check_wrap(safe_jump_current, dir)

This should work then, nope?

I got confused because you mentioned we should decide the return value by usign safe_jump_current

10:02:46
@gokberkgunes:matrix.orggokberkgunesForgive me if this is getting too vexing, I am not sure what is needed to be done.10:04:29
@l3mon4d3:matrix.orgL3MON4D3Almost, only do that check on the value returned by `util.no_region_check_wrap(safe_jump_current, dir)`, that's the node we would jump from next10:06:56
@l3mon4d3:matrix.orgL3MON4D3
In reply to @gokberkgunes:matrix.org
Forgive me if this is getting too vexing, I am not sure what is needed to be done.
I could also implement this, only I'm not at home right now, so it'll be a bit
10:07:53
@gokberkgunes:matrix.orggokberkgunes
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..1a9a2cb 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,6 +158,13 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
 	local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+	local next_node = util.no_region_check_wrap(safe_jump_current, dir)
+	if (next_node.pos == 0 and next_node.parent.parent_node == nil) then
+		session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+		return true
+	end
+
 	if current then
 		session.current_nodes[vim.api.nvim_get_current_buf()] =
 			util.no_region_check_wrap(safe_jump_current, dir)

I don't know if this is what you meant, but this does not work properly.

10:19:17
@gokberkgunes:matrix.orggokberkgunes *
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..1a9a2cb 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,6 +158,13 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
 	local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+	local next_node = util.no_region_check_wrap(safe_jump_current, dir)
+	if (next_node.pos == 0 and next_node.parent.parent_node == nil) then
+		session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+		return true
+	end
+
 	if current then
 		session.current_nodes[vim.api.nvim_get_current_buf()] =
 			util.no_region_check_wrap(safe_jump_current, dir)

I don't know if this is what you meant, but this does not work properly.

10:19:27
@gokberkgunes:matrix.orggokberkgunesShould I give up? lol10:19:39
@gokberkgunes:matrix.orggokberkgunesDownload lst.mp410:20:50
@gokberkgunes:matrix.orggokberkgunes *
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..1a9a2cb 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,6 +158,13 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
 	local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+	local next_node = util.no_region_check_wrap(safe_jump_current, dir)
+	if (next_node.pos == 0 and next_node.parent.parent_node == nil) then
+		session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+		return true
+	end
+
 	if current then
 		session.current_nodes[vim.api.nvim_get_current_buf()] =
 			util.no_region_check_wrap(safe_jump_current, dir)

I don't know if this is what you meant, but this does not work properly. The previous one appeared as working correctly.

10:24:20
@gokberkgunes:matrix.orggokberkgunes
In reply to @l3mon4d3:matrix.org
I could also implement this, only I'm not at home right now, so it'll be a bit
I would like to contribute and learn how luasnip works. It's just I am worried that I am spending your time with my newbie attempts.
10:25:23
@l3mon4d3:matrix.orgL3MON4D3
In reply to @gokberkgunes:matrix.org
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..1a9a2cb 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,6 +158,13 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
 	local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+	local next_node = util.no_region_check_wrap(safe_jump_current, dir)
+	if (next_node.pos == 0 and next_node.parent.parent_node == nil) then
+		session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+		return true
+	end
+
 	if current then
 		session.current_nodes[vim.api.nvim_get_current_buf()] =
 			util.no_region_check_wrap(safe_jump_current, dir)

I don't know if this is what you meant, but this does not work properly. The previous one appeared as working correctly.

Oh almost correct: in the not-$0 branch, assign next_node to session.current_nodes, don't "jump again"
10:32:34
@l3mon4d3:matrix.orgL3MON4D3
In reply to @gokberkgunes:matrix.org
I would like to contribute and learn how luasnip works. It's just I am worried that I am spending your time with my newbie attempts.
Nah, so far you haven't spent that much of my time, don't worry :)
10:33:41
@gokberkgunes:matrix.orggokberkgunesalright then xD10:34:09
@gokberkgunes:matrix.orggokberkgunes
In reply to @l3mon4d3:matrix.org
Oh almost correct: in the not-$0 branch, assign next_node to session.current_nodes, don't "jump again"
okay, this makes perfect sense now. all good.
10:36:29
@gokberkgunes:matrix.orggokberkgunes
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..4d4d4ae 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,9 +158,15 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
        local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+       local next_node = util.no_region_check_wrap(safe_jump_current, dir)
+       if (next_node.pos == 0 and next_node.parent.parent_node == nil) then
+               session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+               return false
+       end
+
        if current then
-               session.current_nodes[vim.api.nvim_get_current_buf()] =
-                       util.no_region_check_wrap(safe_jump_current, dir)
+               session.current_nodes[vim.api.nvim_get_current_buf()] = next_node
                return true
        else
                return false

I am pushing this as the previous pull request, all good?

10:37:44
@gokberkgunes:matrix.orggokberkgunes *
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..4d4d4ae 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,9 +158,15 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
        local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+       local next_node = util.no_region_check_wrap(safe_jump_current, dir)
+       if (next_node.pos == 0 and next_node.parent.parent_node == nil) then
+               session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+               return true
+       end
+
        if current then
-               session.current_nodes[vim.api.nvim_get_current_buf()] =
-                       util.no_region_check_wrap(safe_jump_current, dir)
+               session.current_nodes[vim.api.nvim_get_current_buf()] = next_node
                return true
        else
                return false

I am pushing this as the previous pull request, all good?

10:38:20
@gokberkgunes:matrix.orggokberkgunes *
diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua
index 5ec2a93..4d4d4ae 100644
--- a/lua/luasnip/init.lua
+++ b/lua/luasnip/init.lua
@@ -158,9 +158,15 @@ local function safe_jump_current(dir, no_move, dry_run)
 end
 local function jump(dir)
        local current = session.current_nodes[vim.api.nvim_get_current_buf()]
+
+       local next_node = util.no_region_check_wrap(safe_jump_current, dir)
+       if (next_node.pos == 0 and next_node.parent.parent_node == nil) then
+               session.current_nodes[vim.api.nvim_get_current_buf()] = nil
+               return true
+       end
+
        if current then
-               session.current_nodes[vim.api.nvim_get_current_buf()] =
-                       util.no_region_check_wrap(safe_jump_current, dir)
+               session.current_nodes[vim.api.nvim_get_current_buf()] = next_node
                return true
        else
                return false

returning true is correct, right?

If so, I am pushing this as the previous pull request, is all good?

10:38:58

Show newer messages


Back to Room ListRoom Version: 6