Closed RichestHumanAlive closed 1 year ago
My fault. I will overhaul the JSON file format entirely.
This is too ugly to work with.
[{"path":{"path":"C:\/Users\/USERNAME\/AppData\/Local\/nvim"},"patterns":[".git",".svn",".hg"]}]
Should be,
[{"C:\/Users\/USERNAME\/AppData\/Local\/nvim", [".git",".svn",".hg"]}]
or at least,
[{"path": "C:\/Users\/USERNAME\/AppData\/Local\/nvim","patterns":[".git",".svn",".hg"]}]
The format will be updated, and this issue will be solved in the process by tomorrow.
This one looks really intuitive
[{"path": "C:\/Users\/USERNAME\/AppData\/Local\/nvim","patterns":[".git",".svn",".hg"]}]
If had to choose it will be this one.
Thanks
@RichestHumanAlive You are right. That indeed looks the the most idiomatic json.
I have fixed this in workspaces_json_overhaul
branch. Can you check if your issue is also fixed? Please, redo the AddWorkspace command or edit the json file appropriately.
Will merge after testing a bit
@GnikDroy I just tried the workspaces_json_overhaul
branch but seems still not working fine.
This is how I loaded the target branch using Packer
use {
'gnikdroy/projections.nvim', branch = 'workspaces_json_overhaul'
}
I deleted first the content of the projects file stdpath('data') .. 'projections_workspaces.json
to avoid any previous installation impact (as I was not sure if the file will be deleted automatically when Packer
uninstall the plugin)
I have achieved the exact same steps :
C:\/Users\/USERNAME\/AppData\/Local\/nvim
nvim
command:AddWorkspace
command. C:\/Users\/USERNAME\/AppData\/Local\/nvim
was added successfully to workspaces file as expected.NOTE: My configs still default. I just Customized the
AddWorspace
function a bit to be sure that everything was working well at this step.
I kept the most important part Workspace.add(vim.loop.cwd())
untouched.
-- Check if notify plugin is available
local notify_available, notify = pcall(require, "notify")
-- Create AddWorkspace command
local Workspace = require("projections.workspace")
-- Add workspace command
vim.api.nvim_create_user_command(
"AddWorkspace",
function()
Workspace.add(vim.loop.cwd())
local historyfile = vim.fn.stdpath('data') .. '\\projections_workspaces.json'
local curr_directory = vim.fn.expand("%:p:h")
if notify_available then
notify("[" .. curr_directory .. "] added successfully to history file [" .. historyfile .. "]", "info")
else
vim.cmd("!echo " .. curr_directory .. " >> " .. historyfile)
end
end,
{})
stdpath('data') .. 'projections_workspaces.json
file content:
[{"patterns":[".git",".svn",".hg"],"path":"C:\/Users\/USERNAME\/AppData\/Local\/nvim"}]
The json structure is exactly as expected.
But...
:Telescope projections
in order to show workspacesNOTE : I don't know if by any chance it's related but when I displayed the success message I realized that the path to the configuration file was wrong.
I got C:\Users\WALTEROOT\AppData\Local\nvim-dataprojections_workspaces.json
instead of C:\Users\WALTEROOT\AppData\Local\nvim-data\projections_workspaces.json
It was explicitly necessary to add the backslash \\
as you saw in the snippet of code above to have a correct output of the project's file path.
Firstly,
run :Telescope projections in order to show workspaces
:Telescope projections
lists projects, not workspaces. So, the above output is possible is no projects are present in the workspace.
It was explicitly necessary to add the backslash \ as you saw in the snippet of code above to have a correct output of the project's file path.
local historyfile = vim.fn.stdpath('data') .. '\\projections_workspaces.json'
This is expected. This is not projections' code, and you need the double backslash to escape the backslash.
The first question is, are there subdirectories of containing ".git", ".svn" and ".hg" in "path":"C:\/Users\/USERNAME\/AppData\/Local\/nvim"
? If not, then this is explained.
At least on my machine, there are some treesitter directories that get listed when I follow your instructions.
Maybe try with "patterns": []
to list all subdirectories. And provide me the directory structure in "C:\/Users\/USERNAME\/AppData\/Local\/nvim"
Also, local notify_available, notify = pcall(require, "notify")
isn't necessary.
You can use vim.notify
and the notify
plugin will pick it up if available. That has the additional advantage of working with other notify plugin as well, if you someday decide to switch.
So instead of,
local notify_available, notify = pcall(require, "notify")
if notify_available then
notify("[" .. curr_directory .. "] added successfully to history file [" .. historyfile .. "]", "info")
else
vim.cmd("!echo " .. curr_directory .. " >> " .. historyfile)
end
you can directly use vim.notify(...)
, vim.notify
will print with echo!
if no handler is set. So the behaviour should be exactly the same.
Followed your instructions and everything works fine now.
Huge Thanks for Tips 💯
Basic checklist
:h session
,:h mksession
, and:h sessionoptions
Expected vs Actual behavior Expected to see through
Telescope
list of workspaces I just added usingAddWorkspace
command (mentioned in the README) But I get an error after trying to show my very first workspace added.Environment information
NVIM v0.8.0
Windows 10:
Projections branch/commit hash: Main
Projections config:
Projections workspace file (find this at
stdpath('data') .. 'projections_workspaces.json'
:Result of
ls -lah
from projection sessions folder (find this atstdpath('cache') .. 'projections_sessions/'
. Remove personal information as needed.Result of
tree -a -L 2
from every configured workspace (both config and workspace json file). Remove personal and unnecessary information as needed.To Reproduce Steps to reproduce the behavior:
C:\/Users\/USERNAME\/AppData\/Local\/nvim
nvim
command:AddWorkspace
command. Receive notification thatC:\/Users\/USERNAME\/AppData\/Local\/nvim
was added successfully to workspaces as expected:Telescope projections
in order to show workspacesStack traceback
Thanks for your attention.