Skip to content

Commit

Permalink
feat: support NVIM_APPNAME (#139)
Browse files Browse the repository at this point in the history
* feat: support NVIM_APPNAME

* chore(build): auto-generate vimdoc

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
amitds1997 and github-actions[bot] committed May 26, 2024
1 parent aadb0a0 commit 4460db7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Please read the associated comments before changing the value.

-- Remote configuration
remote = {
app_name = "nvim", -- This directly maps to the value NVIM_APPNAME. If you use any other paths for configuration, also make sure to set this.
-- List of directories that should be copied over
copy_dirs = {
-- What to copy to remote's Neovim config directory
Expand Down
9 changes: 7 additions & 2 deletions doc/remote-nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*remote-nvim.txt* For Neovim >= 0.9.0 Last change: 2024 May 22
*remote-nvim.txt* For Neovim >= 0.9.0 Last change: 2024 May 26

==============================================================================
Table of Contents *remote-nvim-table-of-contents*
Expand Down Expand Up @@ -96,7 +96,8 @@ LOCAL MACHINE ~
- Binaries
- `curl`
- `tar` (optional; if you use compressed uploads)
- `devpod` >= 0.5.0 (optional; if you want to use devcontainer)
- `devpod` <https://devpod.sh/docs/getting-started/install#optional-install-devpod-cli> >= 0.5.0 (optional;
if you want to use devcontainer)
- Connectivity to neovim repo <https://github.com/neovim/neovim> on GitHub

Connectivity to neovim repo <https://github.com/neovim/neovim> on GitHub is not
Expand Down Expand Up @@ -134,6 +135,9 @@ Using lazy.nvim <https://github.com/folke/lazy.nvim>
}
<

_Ensure you have devpod >= 0.5.0 installed for any devcontainer-related
features to work_

If you use any other plugin manager, ensure that you call
`require("remote-nvim").setup()`.

Expand Down Expand Up @@ -225,6 +229,7 @@ value.

-- Remote configuration
remote = {
app_name = "nvim", -- This directly maps to the value NVIM_APPNAME. If you use any other paths for configuration, also make sure to set this.
-- List of directories that should be copied over
copy_dirs = {
-- What to copy to remote's Neovim config directory
Expand Down
10 changes: 6 additions & 4 deletions lua/remote-nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ local utils = require("remote-nvim.utils")
---@field compression remote-nvim.provider.Executor.JobOpts.CompressionOpts? Should the transfer be compressed or uncompressed

---@class remote-nvim.config.PluginConfig.Remote.CopyDirs
---@field config remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_CONFIG_HOME/neovim. Default is output of :lua= vim.fn.stdpath("config"). Default `base` when not specified is vim.fn.stdpath("config").
---@field data remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_DATA_HOME/neovim. Default is nothing. If base is not specified, it is assumed to be :lua= vim.fn.stdpath("data")
---@field state remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_STATE_HOME/neovim. Default is nothing. If base is not specified, it is assumed to be :lua= vim.fn.stdpath("state")
---@field cache remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_CACHE_HOME/neovim. Default is nothing. If base is not specified, it is assumed to be :lua= vim.fn.stdpath("cache")
---@field config remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_CONFIG_HOME/nvim. Default is output of :lua= vim.fn.stdpath("config"). Default `base` when not specified is vim.fn.stdpath("config").
---@field data remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_DATA_HOME/nvim. Default is nothing. If base is not specified, it is assumed to be :lua= vim.fn.stdpath("data")
---@field state remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_STATE_HOME/nvim. Default is nothing. If base is not specified, it is assumed to be :lua= vim.fn.stdpath("state")
---@field cache remote-nvim.config.PluginConfig.Remote.CopyDirs.FolderStructure Directory to copy over into remote XDG_CACHE_HOME/nvim. Default is nothing. If base is not specified, it is assumed to be :lua= vim.fn.stdpath("cache")

---@class remote-nvim.config.PluginConfig.Remote
---@field copy_dirs remote-nvim.config.PluginConfig.Remote.CopyDirs Which directories should be copied over to the remote
---@field app_name string Neovim app name which should be used throughout

---@class remote-nvim.config.PluginConfig
---@field devpod remote-nvim.config.PluginConfig.DevpodConfig Devcontainer configuration
Expand Down Expand Up @@ -143,6 +144,7 @@ M.default_opts = {
},
},
remote = {
app_name = "nvim",
copy_dirs = {
config = {
---@diagnostic disable-next-line:assign-type-mismatch
Expand Down
20 changes: 13 additions & 7 deletions lua/remote-nvim/providers/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ function Provider:_setup_workspace_variables()
self["_remote_xdg_" .. xdg_name .. "_path"] =
utils.path_join(self._remote_is_windows, self._remote_workspace_id_path, path)
end
self._remote_neovim_config_path = utils.path_join(self._remote_is_windows, self._remote_xdg_config_path, "nvim")
self._remote_neovim_config_path =
utils.path_join(self._remote_is_windows, self._remote_xdg_config_path, remote_nvim.config.remote.app_name)

self:_add_session_info()
end
Expand Down Expand Up @@ -560,10 +561,10 @@ function Provider:_setup_remote()
-- Create necessary directories
local necessary_dirs = {
self._remote_scripts_path,
utils.path_join(self._remote_is_windows, self._remote_xdg_config_path, "nvim"),
utils.path_join(self._remote_is_windows, self._remote_xdg_cache_path, "nvim"),
utils.path_join(self._remote_is_windows, self._remote_xdg_state_path, "nvim"),
utils.path_join(self._remote_is_windows, self._remote_xdg_data_path, "nvim"),
utils.path_join(self._remote_is_windows, self._remote_xdg_config_path, remote_nvim.config.remote.app_name),
utils.path_join(self._remote_is_windows, self._remote_xdg_cache_path, remote_nvim.config.remote.app_name),
utils.path_join(self._remote_is_windows, self._remote_xdg_state_path, remote_nvim.config.remote.app_name),
utils.path_join(self._remote_is_windows, self._remote_xdg_data_path, remote_nvim.config.remote.app_name),
self:_remote_neovim_binary_dir(),
}
local mkdirs_cmds = {}
Expand Down Expand Up @@ -659,7 +660,11 @@ function Provider:_setup_remote()
if not vim.tbl_isempty(value) then
self:upload(
value,
utils.path_join(self._remote_is_windows, self["_remote_xdg_" .. key .. "_path"], "nvim"),
utils.path_join(
self._remote_is_windows,
self["_remote_xdg_" .. key .. "_path"],
remote_nvim.config.remote.app_name
),
("Copying over Neovim '%s' directories onto remote"):format(key),
remote_nvim.config.remote.copy_dirs[key].compression
)
Expand Down Expand Up @@ -696,11 +701,12 @@ function Provider:_launch_remote_neovim_server()

-- Launch Neovim server and port forward
local port_forward_opts = ([[-t -L %s:localhost:%s]]):format(self._local_free_port, remote_free_port)
local remote_server_launch_cmd = ([[XDG_CONFIG_HOME=%s XDG_DATA_HOME=%s XDG_STATE_HOME=%s XDG_CACHE_HOME=%s %s --listen 0.0.0.0:%s --headless]]):format(
local remote_server_launch_cmd = ([[XDG_CONFIG_HOME=%s XDG_DATA_HOME=%s XDG_STATE_HOME=%s XDG_CACHE_HOME=%s NVIM_APPNAME=%s %s --listen 0.0.0.0:%s --headless]]):format(
self._remote_xdg_config_path,
self._remote_xdg_data_path,
self._remote_xdg_state_path,
self._remote_xdg_cache_path,
remote_nvim.config.remote.app_name,
self:_remote_neovim_binary_path(),
remote_free_port
)
Expand Down
4 changes: 2 additions & 2 deletions tests/remote-nvim/providers/provider_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ describe("Provider", function()
assert.stub(local_free_port_stub).was.called()
assert.stub(run_command_stub).was.called_with(
match.is_ref(provider),
"XDG_CONFIG_HOME=~/.remote-nvim/workspaces/ajfdalfj/.config XDG_DATA_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/share XDG_STATE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/state XDG_CACHE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.cache ~/.remote-nvim/nvim-downloads/stable/bin/nvim --listen 0.0.0.0:32123 --headless",
"XDG_CONFIG_HOME=~/.remote-nvim/workspaces/ajfdalfj/.config XDG_DATA_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/share XDG_STATE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/state XDG_CACHE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.cache NVIM_APPNAME=nvim ~/.remote-nvim/nvim-downloads/stable/bin/nvim --listen 0.0.0.0:32123 --headless",
match.is_string(),
"-t -L 52232:localhost:32123",
match.is_function()
Expand All @@ -845,7 +845,7 @@ describe("Provider", function()
assert.stub(local_free_port_stub).was.called()
assert.stub(run_command_stub).was.called_with(
match.is_ref(provider),
"XDG_CONFIG_HOME=~/.remote-nvim/workspaces/ajfdalfj/.config XDG_DATA_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/share XDG_STATE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/state XDG_CACHE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.cache ~/.remote-nvim/nvim-downloads/stable/bin/nvim --listen 0.0.0.0:32123 --headless --cmd ':cd /home/test-user'",
"XDG_CONFIG_HOME=~/.remote-nvim/workspaces/ajfdalfj/.config XDG_DATA_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/share XDG_STATE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.local/state XDG_CACHE_HOME=~/.remote-nvim/workspaces/ajfdalfj/.cache NVIM_APPNAME=nvim ~/.remote-nvim/nvim-downloads/stable/bin/nvim --listen 0.0.0.0:32123 --headless --cmd ':cd /home/test-user'",
match.is_string(),
"-t -L 52232:localhost:32123",
match.is_function()
Expand Down

0 comments on commit 4460db7

Please sign in to comment.