Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E492: Not an editor command: require("telescope").extensions.possession.list() #64

Closed
tiagoprn opened this issue Jun 12, 2024 · 11 comments · Fixed by #65
Closed

E492: Not an editor command: require("telescope").extensions.possession.list() #64

tiagoprn opened this issue Jun 12, 2024 · 11 comments · Fixed by #65

Comments

@tiagoprn
Copy link

tiagoprn commented Jun 12, 2024

I have been running this plugin for about a week.

I build nvim everyday from master and I am facing this error when I try to trigger the command to load the list of sessions:


E492: Not an editor command: require("telescope").extensions.possession.list()
E5108: Error executing lua: ....local/share/nvim/lazy/plenary.nvim/lua/plenary/path.lua:749: EISDIR: illegal operation on a directory
stack traceback:
	[C]: in function 'assert'
	....local/share/nvim/lazy/plenary.nvim/lua/plenary/path.lua:749: in function 'read'
	...are/nvim/lazy/possession.nvim/lua/possession/session.lua:380: in function 'list'
	...share/nvim/lazy/possession.nvim/lua/possession/query.lua:11: in function 'as_list'
	...e/nvim/lazy/possession.nvim/lua/possession/telescope.lua:82: in function 'get_finder'
	...e/nvim/lazy/possession.nvim/lua/possession/telescope.lua:112: in function 'list'
	/home/tds/.config/nvim/lua/plugins.lua:95: in function </home/tds/.config/nvim/lua/plugins.lua:94>

I think maybe require("telescope").extensions.possession.list() changed on a recent update?

Relevant context:

version: NVIM v0.11.0-dev-226+g721551210
package manager: lazy.nvim
configuration:

	-- Session manager
	{
		"jedrzejboczar/possession.nvim",
		event = "BufReadPre",
		cmd = { "PossessionLoad", "PossessionList" },
		keys = {
			{
				"<leader>Sl",
				function()
					require("telescope").extensions.possession.list()
				end,
				desc = "List Sessions",
			},
			{
				"<leader>Ss",
				function()
					-- Get the current working directory
					local cwd = vim.fn.getcwd()
					-- Extract the root directory from the CWD
					local root_dir = cwd:match("([^/]+)$")
					-- Get user input for the session name
					local input = vim.fn.input("Enter the session name: ")
					-- Check if the user provided an input
					if input ~= "" then
						-- Concatenate root directory with user input as the session name
						local session_name = root_dir .. "." .. input
						-- Save the session with the new name
						require("possession.session").save(session_name)
					else
						print("No input provided.")
					end
				end,
				desc = "Save Session",
			},
		},
		opts = {
			telescope = {
				list = {
					default_action = "load",
					mappings = {
						delete = { n = "d", i = "<c-d>" },
						rename = { n = "r", i = "<c-r>" },
					},
				},
			},
		},
	},
...
require("telescope").load_extension("possession")
...

@tiagoprn
Copy link
Author

tiagoprn commented Jun 12, 2024

I searched the source code and I think I found the correct namespace of the list command (which is require("possession.telescope").list()), but I think not 😓 , since after changing that I now am facing a new error:

E5108: Error executing lua: ....local/share/nvim/lazy/plenary.nvim/lua/plenary/path.lua:749: EISDIR: illegal operation on a directory
stack traceback:
	[C]: in function 'assert'
	....local/share/nvim/lazy/plenary.nvim/lua/plenary/path.lua:749: in function 'read'
	...are/nvim/lazy/possession.nvim/lua/possession/session.lua:380: in function 'list'
	...share/nvim/lazy/possession.nvim/lua/possession/query.lua:11: in function 'as_list'
	...e/nvim/lazy/possession.nvim/lua/possession/telescope.lua:82: in function 'get_finder'
	...e/nvim/lazy/possession.nvim/lua/possession/telescope.lua:112: in function 'list'
	/home/tds/.config/nvim/lua/plugins.lua:96: in function </home/tds/.config/nvim/lua/plugins.lua:94>

So, I think I had a bad guess 😝

@jedrzejboczar
Copy link
Owner

Hmm, the first error E492: Not an editor command: require("telescope").extensions.possession.list() looks as if you entered :require("telescope").extensions.possession.list() instead of :lua require("telescope").extensions.possession.list().

But the second looks like there is a directory inside your session_dir (defaults to something like :echo stdpath('data') .. '/' .. 'possession', so on Linux it's usually ~/.local/share/nvim/possession/). Is this the case? Can you check what kind of files/directories are there?

Anyway, this is a bug, we should only consider files when reading, so it needs to be fixed.

@jedrzejboczar
Copy link
Owner

Can you check if this helps? #65

@tiagoprn
Copy link
Author

Hey @jedrzejboczar !

Yes, I have a directory there (I copied it from the old session manager I used, so to have them archived case I need).

I restored the plugin from a previous version manually and locked it on lazy.nvim, but I can remove the lock and try to update. I'll do that in a few hours and get back here to confirm, thank you for now!

@tiagoprn
Copy link
Author

tiagoprn commented Jun 13, 2024

After your update, I have a new error. Below is a screenshot:

2024-06-13_16-28

I have the following characters on session file names:

. (period)
- (hyphen) 

Does that help? Thanks!

@josh-nz
Copy link
Contributor

josh-nz commented Jun 14, 2024

@tiagoprn

Yes, I have a directory there (I copied it from the old session manager I used, so to have them archived case I need).

Can you clarify this a little more? What files do you have in ~/.local/share/nvim/possession/? You say you copied something from another session manager?

Be aware that Possession, while still using the built in Vim mksession, wraps this in a JSON object. So regular mksession files are not directly readable by Possession. The stacktrace of your error suggests that it is trying to JSON decode a file that is not valid JSON. Which suggests to me it might be trying to decode a Vim mksession file instead.

You could try the :PossessionMigrate command to migrate these session files to the correct JSON format.

@jedrzejboczar
I wonder if in session.list local glob = (Path:new(config.session_dir) / '*'):absolute() should limit to *.json to try and be a little more defensive in case there are additional files present.

@tiagoprn
Copy link
Author

Oh, I see @josh-nz ! Inside ~/.local/share/nvim/possession/ I have a folder named '_old_plugin', which in turn has sessions files I used on the plugin https://github.com/Shatur/neovim-session-manager - which is a wrapper to mksession.

If your plugin is trying to read files from the folder '_old_plugin' or .git [1] , that can indeed be the cause. Sorry if that is the reason, I assumed you had safeguards to only read json files on the folder ~/.local/share/nvim/possession/ (didn't look at your code).

Your suggestion to limit to *.json files and also restrict to the folder (don't recurse) is great to safeguard from someone that tinkers with that directory as I did.

[1] I source controlled this directory because the sessions are valuable to me when I need to revisit files I may be interested in. Your json files are the reason I switched to this plugin, you all did great work here! ;)

@josh-nz
Copy link
Contributor

josh-nz commented Jun 14, 2024

I want to be very clear that this is not my plugin. The credit for this work belongs to @jedrzejboczar. I have made a few very small contributions only.

I'm not very familiar with Vim globs and if they are different from other forms of globbing, but a quick test doesn't seem to suggest it is recursing into your _old_plugin folder. Do you have any non *.json files directly in the ~/.local/share/nvim/possession/ folder?

@tiagoprn
Copy link
Author

tiagoprn commented Jun 14, 2024

Sorry for the confusion @josh-nz , I have mistaken you for the author, my bad. I need more coffee 🤣

So, about files, there is indeed a shell script on the same folder.

The files I have are the ones on the screenshot I shared here (it is on the lower half of the screenshot): #64 (comment)

Let me know if there is anything else you need. Thank you!

@josh-nz
Copy link
Contributor

josh-nz commented Jun 14, 2024

Ah, I missed your ls output in that screenshot. Thanks. I can confirm that if I make a non JSON file and add non-JSON content to it that I get the same error as you do (invalid token), and that change suggested here fixes the issue.

If you understand how Neovim plugins work, you can make this change locally until a fix is landed, or otherwise temporarily move that shell script out of this folder.

I'll leave the fix up to @jedrzejboczar since it's probably more work for them to manage a pull request from me for such a simple change. In session.lua in M.list:

-    local glob = (Path:new(config.session_dir) / '*'):absolute()
+    local glob = (Path:new(config.session_dir) / '*.json'):absolute()

@jedrzejboczar
Copy link
Owner

Thanks for analyzing this. Indeed using '*.json' seems like the correct way to handle this. When writing this plugin I didn't imaging people adding their own files to that directory and tracking it in source control, but this sounds perfectly reasonable! I'll update #65 and merge it.

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

Successfully merging a pull request may close this issue.

3 participants