Skip to content

Home Variable Expansion on Windows When Loading A Session Results in Malformed Path #395

@Sealatron

Description

@Sealatron

Bug description
On Windows, I have my HOME environment variable set to "HOME=D:\". When reloading a CMake project session via Lazyvim, cmake-tools attempted to mkdir a malformed path to store/access session data.

I believe the culprit to be cmake-tools.nvim/lua/cmake-tools/session.lua:8:

    win = vim.fn.expand("~") .. "/AppData/Local/cmake_tools_nvim/",

Steps to reproduce

Minimal configuration Set Environment variable HOME=D:\ A session exists in a CMake project directory.
1. Attempt to load a CMake session, such that `init_cache` is called.

Expected behavior

  1. I would expect cmake_tools to use the nvim-data directory, which could be accesed via vim.fn.stdpath("data") .. "/cmake_tools_nvim" instead of attempting to create another folder in my User area.
  2. Failing that, instead of doing vim.fn.expand("~") on Windows, the Users Local AppData directory can be accessed via the environment variable %LOCALAPPDATA%.
  3. Failing either of those, perhaps the cmake_tools_nvim directory could be specified by users in the config.

Screenshots

The error stacktrace:

   Error  13:08:31 msg_show.lua_error Error executing vim.schedule lua callback: DirChanged Autocommands for "*": Vim(append):Error executing lua callback: ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: We couldn't mkdir: D:\/AppData/Local/cmake_tools_nvim/
stack traceback:
	[C]: in function 'error'
	...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: in function 'mkdir'
	...vim-data/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:48: in function 'mkdir'
	...m-data/lazy/cmake-tools.nvim/lua/cmake-tools/session.lua:39: in function 'init_cache'
	...m-data/lazy/cmake-tools.nvim/lua/cmake-tools/session.lua:45: in function 'init_session'
	...m-data/lazy/cmake-tools.nvim/lua/cmake-tools/session.lua:95: in function 'save'
	...nvim-data/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:1764: in function <...nvim-data/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:1757>
	[C]: in function 'chdir'
	...nvim-data/lazy/persistence.nvim/lua/persistence/init.lua:131: in function 'on_choice'
	.../nvim-data/lazy/snacks.nvim/lua/snacks/picker/select.lua:59: in function <.../nvim-data/lazy/snacks.nvim/lua/snacks/picker/select.lua:58>
stack traceback:
	[C]: in function 'chdir'
	...nvim-data/lazy/persistence.nvim/lua/persistence/init.lua:131: in function 'on_choice'
	.../nvim-data/lazy/snacks.nvim/lua/snacks/picker/select.lua:59: in function <.../nvim-data/lazy/snacks.nvim/lua/snacks/picker/select.lua:58>

Environment

  • OS: Windows 11
  • Desktop environment: N/A
  • Plugins commit hash: 38f320f

Contents in the *cmake-tools* buffer

Sorry, not sure where this buffer is? I can update with that info if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions