diff --git a/README.md b/README.md index 9b7d0f5..f289f19 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,12 @@ Also the corresponding Lua functions with the same names as the arguments are av To configure the plugin, you can call `require('cmake').setup(values)`, where `values` is a dictionary with the parameters you want to override. Here are the defaults: ```lua +local Path = require('plenary.path') require('cmake').setup({ parameters_file = 'neovim.json', -- JSON file to store information about selected target, run arguments and build type. - build_dir = '{cwd}/build/{os}-{build_type}', -- Build directory. The expressions `{cwd}`, `{os}` and `{build_type}` will be expanded with the corresponding text values. + build_dir = Path:new('{cwd}', 'build', '{os}-{build_type}'), -- Build directory. The expressions `{cwd}`, `{os}` and `{build_type}` will be expanded with the corresponding text values. samples_path = script_path:parent():parent():parent() / 'samples', -- Folder with samples. `samples` folder from the plugin directory is used by default. - default_projects_path = '~/Projects', -- Default folder for creating project. + default_projects_path = Path:new(vim.loop.os_homedir(), 'Projects'), -- Default folder for creating project. configure_arguments = '-D CMAKE_EXPORT_COMPILE_COMMANDS=1', -- Default arguments that will be always passed at cmake configure step. By default tells cmake to generate `compile_commands.json`. build_arguments = '', -- Default arguments that will be always passed at cmake build step. asyncrun_options = { save = 2 }, -- AsyncRun options that will be passed on cmake execution. See https://github.com/skywind3000/asyncrun.vim#manual diff --git a/lua/cmake/config.lua b/lua/cmake/config.lua index 5fc7baf..02e4e24 100644 --- a/lua/cmake/config.lua +++ b/lua/cmake/config.lua @@ -4,9 +4,9 @@ local script_path = Path:new(debug.getinfo(1).source:sub(2)) local config = { defaults = { parameters_file = 'neovim.json', - build_dir = '{cwd}/build/{os}-{build_type}', + build_dir = Path:new('{cwd}', 'build', '{os}-{build_type}'), samples_path = script_path:parent():parent():parent() / 'samples', - default_projects_path = '~/Projects', + default_projects_path = Path:new(vim.loop.os_homedir(), 'Projects'), configure_arguments = '-D CMAKE_EXPORT_COMPILE_COMMANDS=1', build_arguments = '', asyncrun_options = { save = 2 }, diff --git a/lua/cmake/utils.lua b/lua/cmake/utils.lua index 397279d..59c60bd 100644 --- a/lua/cmake/utils.lua +++ b/lua/cmake/utils.lua @@ -26,7 +26,7 @@ function utils.get_build_dir(parameters) parameters = utils.get_parameters() end - local build_dir = config.build_dir + local build_dir = tostring(config.build_dir) build_dir = build_dir:gsub('{cwd}', vim.fn.getcwd()) build_dir = build_dir:gsub('{os}', os) build_dir = build_dir:gsub('{build_type}', parameters['buildType']:lower()) @@ -34,7 +34,7 @@ function utils.get_build_dir(parameters) end function utils.get_reply_dir(build_dir) - return build_dir / '.cmake/api/v1/reply' + return build_dir / '.cmake' / 'api' / 'v1' / 'reply' end function utils.get_codemodel_targets(reply_dir) @@ -49,7 +49,7 @@ end -- Tell CMake to generate codemodel function utils.make_query_files(build_dir) - local query_dir = build_dir / '.cmake/api/v1/query' + local query_dir = build_dir / '.cmake' / 'api' / 'v1' / 'query' if not query_dir:mkdir({ parents = true }) then utils.notify('Unable to create folder ' .. query_dir.filename, vim.log.levels.ERROR) return false diff --git a/lua/telescope/_extensions/cmake.lua b/lua/telescope/_extensions/cmake.lua index 6cf0e11..20323bb 100644 --- a/lua/telescope/_extensions/cmake.lua +++ b/lua/telescope/_extensions/cmake.lua @@ -117,7 +117,7 @@ local function create_project(opts) return end - local project_location = vim.fn.input('Create in: ', Path:new(config.default_projects_path):expand(), 'file') + local project_location = vim.fn.input('Create in: ', tostring(config.default_projects_path), 'file') if #project_location == 0 then utils.notify('Project path cannot be empty', vim.log.levels.ERROR) return