resession.nvim icon indicating copy to clipboard operation
resession.nvim copied to clipboard

`utils.get_session_file` have error with path have `_`

Open Parsifa1 opened this issue 5 months ago • 4 comments

https://github.com/stevearc/resession.nvim/blob/84c81e5fd8a94dc85a60b97089536174e558e288/lua/resession/util.lua#L142-L146

if there is an path named /foo/bar/foo_bar/ ,then it will transform into _foo_bor_foo_bar_.

i'm trying to write a wrapper of resession and i encounter problems here:

i need to re-transform the _foo_bar_foo_bar_ to /foo/bar/foo_bar/ and this will cause error.

can we have an api in config to set the separator for user them self? i'd like to using __ for / and ++ for :

if it's ok, i can make an pr for it.

Parsifa1 avatar Sep 04 '25 07:09 Parsifa1

++  local filename = string.format("%s.json", name:gsub("_", "++"):gsub(files.sep, "_"):gsub(":", "_")) 
--  local filename = string.format("%s.json", name:gsub(files.sep, "_"):gsub(":", "_")) 

or maybe like this?

/foo/bar/foo_bar/ -> /foo/bar/foo++bar/ -> _foo_bar_foo++bar_ _foo_bar_foo++bar_ -> /foo/bar/foo++bar/ -> /foo/bar/foo_bar/

Parsifa1 avatar Sep 04 '25 08:09 Parsifa1

or maybe we need a more proper transform way and make a handler to update user's old session_filaname?

maybe vim.uri_decode ?

Parsifa1 avatar Sep 04 '25 08:09 Parsifa1

maybe vim.uri_decode ?

Good point! Maybe we could provide a hook to detect the old pattern and automatically update to vim.uri_(en|de)code and remove it when bumping major version.

PS: I am not sure if it's a breaking change when we provide a smooth update mechanism.

chemio9 avatar Sep 04 '25 15:09 chemio9

If you just need the path back, you can get it from the session JSON file.

local files = require('resession.files')
local util  = require('resession.util')
local data  = files.load_json_file(util.get_session_file(SESSION_FILE, SESSION_DIR))
local path  = data.global.cwd

gj86 avatar Nov 06 '25 15:11 gj86