natecraddock / workspaces.nvim Goto Github PK
View Code? Open in Web Editor NEWa simple plugin to manage workspace directories in neovim
License: MIT License
a simple plugin to manage workspace directories in neovim
License: MIT License
I did not find the discussions tab, so I apologize for raising an issue
I noticed a type field along with other relevant information in a single item from the table returned by require("workspaces").get()
:
{
last_opened = "2023-08-18T09:56:56",
name = "project",
path = "/home/user/code/project/",
type = ""
}
I wanted to know if this type
field was being used by workspaces.
If it wasn't, I'd want to:
I couldn't find the error in this function, but it didn't work properly on my device. When I entered nvim on the path of the existing Workspace, it couldn't automatically load the session:
local enable_autoload = function()
-- create autocmd for every file at the start of neovim that checks the current working directory
-- and if the cwd matches a workspace directory then activate the corresponding workspace
vim.api.nvim_create_autocmd({ "VimEnter" }, {
pattern = "*",
callback = function()
for _, workspace in pairs(get_workspaces_and_dirs().workspaces) do
if workspace.path == cwd() then
M.open(workspace.name)
end
end
end,
})
end
and this is my config:
return {
"natecraddock/workspaces.nvim",
dependencies = { "natecraddock/sessions.nvim" },
event = "VeryLazy",
config = function()
require("telescope").load_extension "workspaces"
require("sessions").setup {
events = { "WinEnter", "User", "VimLeavePre" },
absolute = true,
session_filepath = vim.fn.stdpath "data" .. "/sessions",
}
require("workspaces").setup {
auto_open = true,
sort = true,
mru_sort = true,
hooks = {
add = {
"SessionsSave",
},
open_pre = {
"SessionsStop",
"silent %bdelete!",
},
open = function()
require("sessions").load(nil, { silent = true })
end,
},
}
end,
}
As an aside, is it possible to add feature that automatically stop session recording when my current working directory is no longer the working path I set? Thank you very much. Your plug-in is very light and easy to use.
Hi! I hope you are all doing well!
I no longer use Neovim regularly, but I really would like to keep this plugin alive. It's been really simple to maintain, but I worry about the long-term.
So I'm looking for someone willing to step in and maintain this plugin. Either
I think the second is the simplest, and no one has to update their configs to point to a new repository.
If no one steps up, I will try my best to make sure this works for as long as possible. But I won't make any promises. If a future Neovim release would cause an unreasonable amount of work for me to update this plugin, I probably wouldn't update it.
Sorry if that's sad news for anyone, and I apologize if this breaks someone's workflow someday. I don't think this plugin will stop working anytime soon, but if it does... 😬
After a WorkspacesAdd or WorkspacesRemove a notification indicating success, and after WorkspacesList a notification warning if there are no workspaces.
Put this behind a configuration boolean.
Originally posted in #6 (comment)
Nice plugin! I have tried it out and prefer it over telescope-project as yours is more configurable.
One option I would like to see is to make the path change when opening a workspace local instead of global. I like to have one tab per project/workspace open in nvim, so global path changes are a bit of a nuisance to me.
It could be a plugin option à la use_local_path=True
. I saw that you're using nvim_set_current_dir
for the path changes, which does not seem to have a local
alternative, so maybe something like vim.cmd[[lcd path/to/workspace]]
?
I have :tcd
as a use-case instead of :cd
or :lcd
. The way this plugin is structured, it'd need to add something like a cd_cmd
to the options to accommodate the three cd commands. However, at that point, it would simplify the API to simply let the user cd themselves on a hook. Thoughts?
I'm working on a plugin that wraps your workspaces.nvim and sessions.nvim: https://github.com/ryansch/habitats.nvim
I'd like to add the ability to sort the list by most recently used and I think I have three options:
Would you be interested in either of options 1 or 2?
How I can rename my workspace from something like "name" to: "newname - [category]" etc.? It can't take spaces etc...
When the property auto_open
is set with value true
, and we open in a previous added project the telescope open with modifiable
off.
P.S. If it's not a workspaces bug, can someone give me a hand to fix it?
local vim = vim
local M = {}
local ok, package = pcall(require, "workspaces")
if not ok then
return vim.notify("Failed to require package `workspaces`")
end
package.setup({
auto_open = true, -- FIX: Cannot make changes, 'modifiable' is off
notify_info = false,
hooks = {
open = "Telescope find_files",
-- open = "NvimTreeOpen",
}
})
local telescope_ok, telescope = pcall(require, "telescope")
if not telescope_ok then
return vim.notify("Failed to require package `telescope`")
end
telescope.load_extension("workspaces")
M.open = function()
telescope.extensions.workspaces.workspaces()
end
return M
At first, thank you for this wonderful plugin, really appreciate it.
During my installation, I directly copied the configuration code from the "Installation" part. And this error emerged.
I am new to lua. Could you give me any hints about this?
Error detected while processing /Users/swellmai/.config/nvim/init.lua:
E5113: Error while calling lua chunk: .../swellmai/.config/nvim/lua/plugin_configs/workspaces.lua:5: attempt to index global 'util' (a nil value)
stack traceback:
.../swellmai/.config/nvim/lua/plugin_configs/workspaces.lua:5: in main chunk
[C]: in function 'require'
/Users/swellmai/.config/nvim/lua/plugin_configs/init.lua:6: in main chunk
[C]: in function 'require'
/Users/swellmai/.config/nvim/init.lua:8: in main chunk
Press ENTER or type command to continue
It looks like nvim can't find the location of "util".
Hi,
I recently had an issue opening workspaces using WorkspacesOpen
: nothing happened when selecting them from the telescope interface. Using :messages
, I saw that the workspace "does not exist" according to the plugin.
I checked the .local/share/nvim/workspaces
file and found the workspace. The directory exists as well. I dug into the plugin code and found that the workspace is given as non-existent as the type
attribute check added in #18 fails.
workspaces.nvim/lua/workspaces/init.lua
Line 208 in f74c1e8
It fails because my workspaces
file has no type
column yet and the workspace.type
attribute is nil
. The solution was to delete my workspaces
file and start a new one. Not pleasant, but not the end of the world either.
Leaving this here for anyone who might run into the same issue.
Hello,
First of all thanks for this useful plugin!!
I'm using it since few days and I really like it.
To explain my proposal first some context:
I'm used to store my projects in few places (like perso / pro)
And these folders are only composed of projects (or workspaces) but they change often, I clone a lot of projects, remove them etc.
And I noticed that I don't think to add them manually each time.
I don't want any automatic tracking like does project.nvim because I tried already and it ends with really weird unwanted projects in the list.
Based on that I think it would be really valuable, pretty easy to implement to add a list of folders in the config where each folder is a workspace.
To avoid logic to run at every nvim startup time we could just add a sync method for example that would sync workspaces based on what's currently in the folders workspaces.
Let me know what you think about it, if you ok with the idea I can give it a shot. ☮️
(In fact I thought this is the whole purpose of this plugin, to manage lsp workspace settings)
I failed to understand the purpose of listdir and syncdir. What is the point in assigning dirs to workspace?
Please improve the documentation. Thanks!
I would just write the purpose clearly:
Choosing workspace by default would just change the cwd, but you can add hooks. And additional functionality.
Hello, thanks for the great plugin! I have a question: there is a way to execute others commands, like, rename and delete, through Telescope? I can't found anything about this on documentation
When trying to add a workspace using workspaces.add(path: string, name: string)
, using a full path, the path is modified and it doesn't work.
For example, when running
require('workspaces').add('/home/myuser/tmp', 'testname')
I get an error "Path '/home/myuser/testname' does not exist" (where /home/myuser
is my cwd in this case). However, if I swap the arguments (use "testname" as path, and "/home/myuser/tmp" as name), it works as intended.
Exist some way to refresh the nvimTree when I change in workspaces?
I need the both name and path when configing the open
hook.
workspaces.setup({
hooks = {
-- hooks run before change directory
open_pre = {
"SessionsStop",
"silent %bdelete!",
},
-- load any saved session from current directory
open = function()
require("sessions").load(nil, { silent = true })
end,
},
})
this config used to work before this commit b26f8720a4053af46a36d1e1ff110a647d66046f
and when i updated this plugin it doesn't, i think it has something to do with the path because when i do WorkspacesOpen something
the working directory doesn't change and it loads the same session.
Hello, I'm encountering an issue when trying to use WorkspaceListDirs. A warning is presented that no workspaces are registered. I know that they are because the WorkspaceList command functions as expected.
I normally use a single neovim instance and work in different projects (workspaces) in it.
This would present an issue when switching to a different pane/buffer belonging to a different workspace. The old workspace would still remain active, so any actions (such as telescope search) would be constrained to the other workspace, unless I were to manually switch.
So I created an autocommand to do this automatically when switching buffers, unless the file is already in the current active workspace. Please consider if this would be worthwile including in the wiki.
Implementation can be seen in my forked wiki repo.
Removing a workspace by executing :WorkspacesRemove WS_NAME
, sometimes removes the workspace with the path to the current working directory.
The bug seems to be at line 293 in remove_workspace_or_directory
workspaces.nvim/lua/workspaces/init.lua
Lines 291 to 314 in a6fb499
path
is set to current working directory even if name
is not nil
find
returns a workspace whose path matches the current working directoryProposed fix:
Change line 293 to
local path = (not name and cwd()) or nil
Hello, I use now your plugin as primary workspace jumping, and it works very well, congrats, and thanks !
It seems that keep_insert
is not working, this is my telescope config and my workspace one:
use({
"nvim-telescope/telescope.nvim",
config = function()
local actions = require("telescope.actions")
require("telescope").setup({
defaults = require("telescope.themes").get_ivy({
winblend = 10,
mappings = {
i = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
["<C-a>"] = actions.send_to_qflist + actions.open_qflist,
},
n = {
["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
["<C-a>"] = actions.send_to_qflist + actions.open_qflist,
},
},
}),
extensions = {
["ui-select"] = require("telescope.themes").get_cursor(),
workspaces = {
keep_insert = true,
},
},
})
require("telescope").load_extension("ui-select")
require("telescope").load_extension("fzf")
require("telescope").load_extension("workspaces")
end,
requires = {
"nvim-lua/popup.nvim",
"nvim-telescope/telescope-ui-select.nvim",
"nvim-telescope/telescope-fzf-native.nvim",
"natecraddock/workspaces.nvim",
},
})
use({
"natecraddock/workspaces.nvim",
config = function()
require("workspaces").setup({
hooks = {
open = { "Telescope find_files" },
},
})
end,
})
PS: not related to this issue, but I don't feel like creating an other issue for this:
Would it be possible to provide vim.notify
messages after a WorkspaceAdd
, WorkspaceRemove
, WorkspaceList (if no workspaces)
?
Hi! Nice plugin 👍
Could you make load_workspaces
function public or add to api something similar like get_workspaces
? I started using this as section in https://github.com/sidebar-nvim/sidebar.nvim but I had to replicate that function as there is no way to get list of workspaces. Only print them. :)
When I have multiple splits, and I do :WorkspacesOpen [name]
in one of the splits, it changes cwd
for all the splits, which is not desired, because semantically it should only do :lcd
instead of :cd
.
Another bug is: if I cancel in telescope's popup window, cwd
still changes, which is also not desired.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.