Code Monkey home page Code Monkey logo

cmake-tools.nvim's Introduction

Hi, I'm Civitasv, a passionate C++ developer. 💬 Ask me about anything, I am happy to help.

Neovim Projects

cmake-tools.nvim: CMake integration in Neovim cmake-tools.nvim: CMake integration in Neovim   runvim: Beautiful, fast, functional Configuration for Neovim. runvim: Beautiful, fast, functional Configuration for Neovim.  

C++ Projects

asciichart: Nice-looking lightweight console ASCII line charts, using C++, no dependencies. asciichart: Nice-looking lightweight console ASCII line charts, using C++, no dependencies.   mini-json-parser: A Tiny Json Parser mini-json-parser: A Tiny Json Parser  

Other Projects

AMapPoi: POI 搜索工具、地理编码工具 AMapPoi: POI 搜索工具、地理编码工具  

Civitasv: Civitasv's GitHub Stats Civitasv: Civitasv's GitHub Stats  

cmake-tools.nvim's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cmake-tools.nvim's Issues

After set env variables, can't find CMAKE_ROOT

Hi,

Your commit 14603f0 broke the plugin, I can't use CMakeBuild, CMakeGenerate didn't test other commands, but I think they are on the same boat.

Error executing Lua callback: .../.nvim/plugged/cmake-tools.nvim/lua/cmake-tools/init.lua:99: attempt to index upvalue 'config' (a nil value)
stack traceback:
        .../.nvim/plugged/cmake-tools.nvim/lua/cmake-tools/init.lua:99: in function <.../.nvim/plugged/cmake-tools.nvim/lua/cmake-tools/init.lua:87>

Anyway, I really like your work, this excellent plugin :D

Regards,
Lucas

Telescope cmake_tools throws

Bug description

I'm not sure if there are some undocumented pre-reqs or anything?

Run :Telescope cmake_tools gives:

Error executing Lua callback: ...ta/lazy/cmake-tools.nvim/lua/cmake-tools/file_picker.lua:18: bad argument #1 to 'ipairs
' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        ...ta/lazy/cmake-tools.nvim/lua/cmake-tools/file_picker.lua:18: in function 'get_files_from_target'
        ...ta/lazy/cmake-tools.nvim/lua/cmake-tools/file_picker.lua:51: in function 'get_source_files'
        ...ake-tools.nvim/lua/telescope/_extensions/cmake_tools.lua:30: in function 'fn'
        ...ake-tools.nvim/lua/telescope/_extensions/cmake_tools.lua:16: in function <...ake-tools.nvim/lua/telescope/_ex
tensions/cmake_tools.lua:8>
        .../nvim-data/lazy/telescope.nvim/lua/telescope/command.lua:193: in function 'run_command'
        .../nvim-data/lazy/telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
        ...Local/nvim-data/lazy/telescope.nvim/plugin/telescope.lua:108: in function <...Local/nvim-data/lazy/telescope.
nvim/plugin/telescope.lua:107>

Steps to reproduce
I have telescope and cmake_tools plugins loaded. My current dir is a small c++/cmake repo. I run.
:Telescope cmake_tools

Minimal configuration

Expected behavior
The telescope command executed ok.

Screenshots

Environment

  • OS: Win10
  • Plugins commit hash: 8e8e952

cmake variant: cursed folder names

Bug description

I wrote a cmake-variants.yaml ...
then I tried to use it. CMakeSelectBuildType, set.

CMakeRun

then i discovered that no comment ( # line ) in yaml supported ( some really strange cmake errors ).

ok, delete comments, try again.

a lot of such CMake warnings:
image

and interesting new folder names ( cmake_build_Debug + ... ) :
image

Ok, let's rename options from "cpm_modules" to just cpm_modules.
Ok, it works.
image
Though, folder name is cursed.
Then, if type :CMakeRun and build an executable it will fail because of cursed names:
image

also it makes cpm_modules folder in the way: "cpm_modules and ;cpm_modules if it's written in cmake-variants.yaml as "cpm_modules" .

I'll put here my cmake-variants.yaml:

buildType:
  default: debug
  choices:
    debug:
      short: Debug
      long: Emit debug information
      buildType: Debug
    release:
      short: Release
      long: Optimize generated code
      buildType: Release
    asan:
      short: Asan
      long: Instrument with Address Sanitizer
      buildType: Asan
    tsan:
      short: Tsan
      long: Instrument with Thread Sanitizer
      buildType: Tsan
cacheCPMPackages:
  default: cpm_modules
  choices:
    dotcache:
      short: .cache_cpm_modules
      long: Save modules in .cache/cpm_modules
      settings:
        CPM_SOURCE_CACHE: .cache/cpm_modules
    cpm_modules:
      short: cpm_modules
      long: Save modules in cpm_modules
      settings:
        CPM_SOURCE_CACHE: cpm_modules

useLocalPackages:
  default: uselocal 
  choices:
    onlylocal:
      short: Onlylocal
      long: Use only local packages. (not recommended)
      settings:
        CPM_LOCAL_PACKAGES_ONLY: ON
        CPM_USE_LOCAL_PACKAGES: OFF
        CPM_DOWNLOAD_ALL: OFF
    uselocal:
      short: UseLocal
      long: Use local packages, if they exist on system, and if not, download them.
      settings:
        CPM_LOCAL_PACKAGES_ONLY: OFF
        CPM_USE_LOCAL_PACKAGES: ON
        CPM_DOWNLOAD_ALL: OFF
    downloadall:
      short: downloadAll
      long: Download all packages, no use of local packages ( except some CPMFindPackage stuff ).
      settings:
        CPM_LOCAL_PACKAGES_ONLY: OFF
        CPM_USE_LOCAL_PACKAGES: OFF
        CPM_DOWNLOAD_ALL: ON

I guess, this can be used at ModernCppStarter to reproduce

Expected behavior

  1. no cursed names of folders. replace " + " with "_" or something like. remove parentheses with details. ( at least )
    if not replace " + ", then change somehow command for cd : cd ./cmake_build_UseLocal\ +\ Debug\ +\ cpm_modules\(Use\ local\ packages,\ if\ they\ exist\ on\ sy...\)/ or something like.
  2. support for yaml comments ( maybe? )
  3. support for names of options inside of " " . (at least document that this is not supported )

Environment

  • OS: Gentoo
  • Desktop environment: KDE
  • Plugins commits: a previous and last one ( 5697db8 ) are tested

Question about autoloading cmake settings.

This is not a bug report but more of a question of whether the following is possible:

  1. Open a c++ project with CMakeLists.txt in the project root.
  2. Configure the build type, build target, and run target.
  3. Do some stuff in the project, then close it.
  4. Upon reopening, it would be nice if it would remember the previously assigned options in 2. So I would not have to reassign the same settings upon every relaunch.

Is this possible and something I missed?

shortcut button

May I ask which plugin is used for the build button in the demo video?

current working directory question

First: thanks for the plugin, love it 👍

Here my little issue:
I start neovim from my home directory, I open a c file from my dev folder (I use fzf-lua). I have an autocommand that change into this directory and !pwd is returning the right path.
But when I run Cmake generate, the build directory is created in home.
This behaviour does not occur with shaturs neovim-tasks. Here the build dir is always right.

Configure target specific environment variables

Describe the problem or limitation you are having
I sometimes need to run executables with specific environment variables.
This could also be useful for generating and building as some compilers (qnx?) require specific env-vars to compile.

Describe the solution you'd like
Inspired by how QtCreator handles environment variables I think it would be useful to be able to configure env-vars for the generate/configure/build step and for individual targets.

My idea is that the env-vars could be configured in a regular vim buffer using lua code. (Similar to the quick window of harpoon)

For example. CMakeConfigureBuildEnvironment would open up a floating window with:

return {
  env { 
    VERBOSE = 1,
  }
}

This would add VERBOSE=1 to env-vars for the generate and build steps

And CMakeConfigureRunEnvironment {target_or_current} for target specific env-vars.

return {
  inherit_build_environment = true,
  env { 
    log_file = "/tmp/log.txt",
    log_level = "trace",
  }
}

This would add VERBOSE=1 log_file = "/tmp/log.txt" log_level = "trace" to env-vars when running the specific target.

This would also be nice since cmake-tools could persist these similar to session.

Describe alternatives you've considered
I can just close nvim set env-vars.

Presets `binaryDir` is not honored

Given CMakePresets.json:

{
  "version": 3,
  "configurePresets": [
    {
      "name": "example",
      "binaryDir": "example_build_directory"
    }
  ]
}

Running:

:CMakeSelectConfigurePreset
" Select example
:CMakeBuild

Outputs:

      Error: could not load cache
      Error: could not load cache

cmake variants: default option support

Right now if use cmake-variants, you still is requested to choose among a lot of options, but there's no default option, though in cmake-variants we write it.

A possible solution: add the default option to the list from :CMakeSelectBuildType to position 1

Alternative solution: if entered no number, choose default.

Possible problems: checking if there's default for every choice.

Persistent output buffers

I have been working on a PR for two output buffers. One for all cmake tasks except run, and another exclusively for run/launch tasks.

The intention for this is to keep track of outputs from all the previous commands that cmake tools generates and provide an additonal way to view the outputs not just with quickfix lists.(... As nature intended.. XD)

I have setup the window/buffer handling in way that launches a buffer first (if not already exists) that has a unique id that persists across the neovim instance.

The following shortened piece of code is intended to launch a job (using native vim/neovim api) and append to an exisint buffer. Here, the problem is in sending lines to the job with stdin. I would appreciate it, if someone can help on this:

Kindly run it and see the output:

local function on_stdout(id, data, event) vim.fn.append(vim.fn.line('$') - 1, data) end
local job_id = vim.fn.jobstart({ "pwsh", "-noprofile" }, { on_stdout = on_stdout })

local function callback(input) vim.fn.chansend(job_id, { input, "" }) end

local function goto_buffer_across_all_tabs(bufname)
    for _, tabpage in ipairs(vim.api.nvim_list_tabpages()) do
        vim.api.nvim_set_current_tabpage(tabpage)
        for _, window in ipairs(vim.api.nvim_tabpage_list_wins(tabpage)) do
            local win_bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(window))
            if win_bufname:match(bufname) then
                vim.api.nvim_set_current_win(window)
                return
            end
        end
    end
end

-- vim.cmd([[command! -nargs=* WinGo2 lua goto_buffer_across_all_tabs(<q-args>)]])

local bufnr = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_name(bufnr, "new")
vim.cmd('vs' .. bufnr)
goto_buffer_across_all_tabs('new')

vim.bo.buftype = "prompt"
vim.api.nvim_get_current_buf()
vim.api.nvim_set_current_buf(bufnr)
vim.fn.prompt_setcallback(bufnr, callback)
vim.keymap.set("n", "<esc>", ":bw!<cr>")
vim.cmd.startinsert()

For testing in unix change pwsh to /bin/sh

Currently this is the output:

image.png

/usr/bin/cmake: Executable not found

Bug description
The following error appears when I run the CMakeGenerate command.

Steps to reproduce

  1. Set the current directory to where the CmakeLists.txt is located.
  2. Run the CMakeGenerate command .

I used the example config:

require("cmake-tools").setup {
  cmake_command = "cmake",
  cmake_build_directory = "",
  cmake_build_directory_prefix = "cmake_build_", -- when cmake_build_directory is "", this option will be activated
  cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1" },
  cmake_build_options = {},
  cmake_console_size = 10, -- cmake output window height
  cmake_show_console = "always", -- "always", "only_on_error"
  cmake_dap_configuration = { name = "cpp", type = "codelldb", request = "launch" }, -- dap configuration, optional
  cmake_variants_message = {
    short = { show = true },
    long = { show = true, max_length = 40 }
  }
}

I also tried setting cmake_command = "D:/Program Files/CMake/bin/cmake" but I get the same error.

Expected behavior
I expected the CMake executable to be found automatically from my PATH environment variable.
However it seems to try to search it in /usr/bin/cmake, but I'm on Windows and I don't see an option to set the CMake Executable path in the plugin config. Is there one?

Screenshots
image

Environment

  • OS: Windows 11 -->

Support flexible build directory naming & structure for enabling multiple build types

Currently, the build directory name needs to be hard coded in the configuration. It would be helpful to have a more flexible approach wherein a build_dir_prefix strings is provided to be user configurable. This will enable C++ developers to have access to multiple type of builds.

Examples:

  • build_dir_prefix: cmake_build_
    In the above example, the build directory will become cmake_build_Debug, cmake_build_Release, wherein the appropriate suffix is chosen by the build type

  • build_dir_prefix: build/
    In this above example with the trailing /, a classical nested hierarchical structure of various types of builds can be facilitated

build
├── Debug
├── MinRelease
├── Release
└── RelwithDebInfo

The above is a classical build tree for multiple type of builds, and is easily done through cmake invocations at the command-line, but this is not currently possible with this plugin.
The vimscript plugin, [cmake4vim](https://github.com/ilyachur/cmake4vim) already supports this, and I am using it now in my projects, but I'd like to move to this lua-based plugin, mainly for its integration with nvim-dap.

Of course, to prevent breaking changes to existing users' configurations, the build_dir_prefix behaviour should be activated only when cmake_build_directory is set explicitly to an empty string. Otherwise, we simply ignore the build_dir_prefix setting, and simply overwrite builds each time to the folder configured in cmake_build_directory (the current behaviour).

No output with CMakeRun in Windows 10.

Bug description

No output from Windows OS, but good output from WSL with the exact same config:

No Output from Windows

image

Good Output from WSL

image

Steps to reproduce

My full config: rohit-kumar-j/nvim

Possible Issue: On windows, the command is CMakeRun command is generated like this:

D:\VS2022\Koala\build\src/Debug/hello.exe
CMake Config (.lua)
require("cmake-tools").setup {

	cmake_command = "cmake",                                         -- cmake command path
	cmake_build_directory = "build",                                 -- cmake generate directory
	-- cmake_build_directory_prefix = "cmake_build_", -- when cmake_build_directory is "", this option will be activated
	cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- it will be activated when invoke `cmake.generate`
	cmake_build_options = {},                                        -- it will be activated when invoke `cmake.build`
	cmake_console_position = "belowright",                           -- "bottom", "top"
	cmake_console_size = 10,
	cmake_show_console = "always",                                   -- "always", "only_on_error"
	cmake_focus_on_console = false,                                  -- true, false
	cmake_variants_message = {
		short = { show = true },
		long = { show = true, max_length = 40 }
	},
	cmake_dap_configuration = {
		name = "cpp",
		type = "codelldb",
		request = "launch",
		stopOnEntry = false,
		runInTerminal = true,
		console = "integratedTerminal",
	},

}

Environment

  • OS: Windows 10
  • Plugins commit hash: d6cfcb2

Add setup of NvimTree in FAQs

I forgot to add this in the Multiple Buffers PR:

For users that are using nvim-tree, they need to add this for preserving the size of window when opening or closing the tree and avoid resizing. Otherwise the constant resizing can get very annoying.

require("nvim-tree").setup {
    --
    view = {
      preserve_window_proportions = true,
      ---
    },
}

Can you add this in the docs?

Question about CMakeLists

Hello, thank you for making this plugin! I am sure this is a super basic question, but I am very new to using VIM so please forgive me lol. I followed the instructions in the ReadMe, but I end up getting this error when I try to run CMake commands: " Cannot find CMakeLists.txt at cwd. Are we supposed to create the CMake files manually? Sorry again for the extremely basic question.

Quickfix: Only scroll to bottom if it was previously at the bottom

I think the quickfix window should stop auto scrolling if the window is currently not at the bottom.

For example while a longer operation is running I notice something and scroll up to take a look. But the window keeps scrolling down. I think the auto scrolling should stop in this case and only continue once I manually scroll back to bottom.

What do you think? I think it would be useful option (or even be the default)

Encoding issues and compilation type detection

  1. The first question, when I am in a Chinese environment, it will not be able to display Chinese, is there any way to deal with this?
    image

  2. When there are multiple compilers on my PC, such as the MSVC compiler and MinGW exist at the same time, I specify the MinGW compiler, but it cannot recognize it (MinGW has added environment variables and can be specified directly using the console)
    image

Execute directly using cmd:
image

Reopen output window after CMakeRun

After CMakeRun i see output on the bottom of output, but if i moved to "code window" my output closed.

Bug description:

I can escape from terminal mode in output window and then move to code window. But often i need to get rid of window for a while, write some code, and then return to it.

Expected behavior:
Toggle output window keymap

BTW
Thanks for an awesome plugin especially after 2 years vscode experience

Handle Preset include

Describe the problem or limitation you are having

CMakePresets.json and CMakeUserPresets.json can include other files with the include field in file version 4 and later. Files included by these files can also include other files. If CMakePresets.json and CMakeUserPresets.json are both present, CMakeUserPresets.json implicitly includes CMakePresets.json, even with no include field, in all versions of the format.
Users may leverage that feature to have common definitions across different projects.

See cmake-preset docs

The conan package manager uses that when generating multiple build configurations, for example:

CMakeUserPresets.json:

{
    "version": 4,
    "vendor": {
        "conan": {}
    },
    "include": [
        "~/project/build/CMakePresets.json"
    ]
}

~/project/build/CMakePresets.json:

{
    "version": 3,
    "vendor": {
        "conan": {}
    },
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 15,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "default",
            "displayName": "'default' config",
            "description": "'default' configure using 'Ninja Multi-Config' generator",
            "generator": "Ninja Multi-Config",
            "cacheVariables": {
                "CMAKE_POLICY_DEFAULT_CMP0091": "NEW"
            },
            "toolchainFile": "~/project/build/conan_toolchain.cmake",
            "binaryDir": "~/project/build"
        }
    ],
    "buildPresets": [
        {
            "name": "release",
            "configurePreset": "default",
            "configuration": "Release"
        },
        {
            "name": "debug",
            "configurePreset": "default",
            "configuration": "Debug"
        },
        {
            "name": "relwithdebinfo",
            "configurePreset": "default",
            "configuration": "RelWithDebInfo"
        }
    ],
    "testPresets": [
        {
            "name": "release",
            "configurePreset": "default",
            "configuration": "Release"
        },
        {
            "name": "debug",
            "configurePreset": "default",
            "configuration": "Debug"
        },
        {
            "name": "relwithdebinfo",
            "configurePreset": "default",
            "configuration": "RelWithDebInfo"
        }
    ]
}

The plugin current behavior cannot detect the presets coming from the included file.

Describe the solution you'd like

As a CMake user who often works with including presets into other presets file, I'd like to have at list the first inclusion handled automatically by the plugin, so that it can see and work with every preset defined in the files included in the top level CMake[User]Presets.json.

Describe alternatives you've considered

A more complete solution would be handling the inclusion recursively, but that would be more complicated. I guess most cases of preset inclusion happens on the first level only. I don't have data to support that assumption, though.

Additional context

Conan users will appreciate the solution.

Allow working directory to specified when running executables

Describe the problem or limitation you are having
I need to set the working directory of some cmake targets to something else. I'm not sure on how to do this right now as it will always choose the build folder where the executable is run with CMakeRun as the working directory.

Describe the solution you'd like
Something similiar to CMakeLaunchArgs, like CMakeLaunchDir where an absolute or relative (eg ../) path to the build folder can specified for both simply running the executable or debugging with nvim-dap.

Describe alternatives you've considered
Right now I have no real alternative but to manually run with the adopted working dir, but eg for debugging it would be really nice to have it just working out of the box.

Additional context

Support for Project Specific `CMakeSettings.json` or `CMakePresets.json`?

Describe the problem or limitation you are having

Sometimes we're configuring with certain project specific settings like -DXXX_ROOT=<...>. Such settings might be dependent on host computer environments therefore they are not suitable to directly hard coded in CMakeLists.txt.

Describe the solution you'd like

Support (partially) parsing CMakeSettings.json or CMakePresets.json like VS/VSC to add or override some global cmake settings.

Launch terminal command chaining issue.

In the Run/Launch terminal, when build commands are chained(default build before run), it does not move out of build directory to build, but builds in the same directory, and errors!

D:/Koala/build ~$ cmake --build build --target testing_ptr && cd "D:\Koala\build" && .\testing_ptr.exe
Error: D:/Koala/build/build is not a directory

It should be:

D:/Koala/build ~$ cd "D:\Koala" cmake --build build --target testing_ptr && cd "D:\Koala\build" && .\testing_ptr.exe
...
...

However, this works the first time as there is no full cmd.

Note, this is an edge case and I did not have this problem for all targets.

Cannot run an executable, if its path contains spaces

Bug description
I have a project on my external hard drive, and the drive is mounted as /run/media/eax_ebx/Verbatim Drive. I can successfully generate and build my project, but when I run :CMakeRun or click the Run button on lualine, select the executable, it gives the error zsh:1: no such file or directory: /run/media/eax_ebx/Verbatim. This error does not appear, if the path to the executable does not contain spaces.

Steps to reproduce

  1. Create a directory like /home/<username>/my project.
  2. Add a CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)

project(test LANGUAGES CXX)

add_executable(test "Test.cpp")
  1. Add the Test.cpp:
#include <iostream>
#include <cstdlib>

int main() {
    std::cout << "Hello, World!\n";

    return EXIT_SUCCESS;
}
  1. Configure, build the test project and run it. On my machine, I get the error zsh:1: no such file or directory: /home/eax_ebx/my.
  2. Now rename the project directory from my project to my_project and delete the build directory. Repeat the 4. step. But now, on my machine, I don't get the error and it successfully runs and I see "Hello, World!" in the console.

Expected behavior
I think no matter what the path to the executable looks like (contains Unicode symbols, whitespaces, etc.), the plugin should run this executable without any problems.

Environment

  • OS: ArchLinux, kernel version is 6.1.12-arch1-1. My shell is zsh 5.9 (x86_64-pc-linux-gnu).
  • Desktop environment: Window Maker 0.95.9
  • Plugins commit hash: cda96e7

Additional context
Configuration of cmake-tools in init.vim:

Plug 'Civitasv/cmake-tools.nvim'

lua << EOF
require("cmake-tools").setup {
  cmake_command = "cmake",
  cmake_build_directory = "build",
  cmake_build_directory_prefix = "", -- when cmake_build_directory is "", this option will be activated
  cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1", },
  cmake_build_options = {},
  cmake_console_size = 20, -- cmake output window height
  cmake_console_position = "belowright", -- "belowright", "aboveleft", ...
  cmake_show_console = "always", -- "always", "only_on_error"
  cmake_dap_configuration = { name = "cpp", type = "codelldb", request = "launch" }, -- dap configuration, optional
  cmake_variants_message = {
    short = { show = true },
    long = { show = true, max_length = 40 }
  }
}
EOF

I think the problem may be somewhere in the code of the cmake.run function, for example, the path to the executable is not wrapped by quotation marks.

Configure cmake command to automatically run in a docker container

CLion has a nice feature that allows you to configure cmake to automatically run in a docker container. In my work, I am developing on a mac, but am working on C/C++ code that needs to be build and deployed in a linux environment. The nice thing about CLion is that when I define the docker container to run, everything else is abstracted away. I can simply build the project without having to think about starting up a container.

Ideally I would like to be able to setup a docker image that cmake-tools can use to run all cmake commands in. That way code intelligence and built binaries would be created within the docker environment, not my laptop.

I tried doing this to simply change the command used to call cmake under the hood, but this doesn't seem to work.

require("cmake-tools").setup {
    cmake_command = "bash -c docker run --rm -v $(pwd):/home/dev-repo -w /home/dev-repo ubuntu20-container cmake"
}

I also realize I could probably setup neovim to run in the docker container and develop from there.

Is there a way to achieve this behavior with the plugin as is? or would this need to be a new feature?

Error when calling generate, build or run

Bug description

using :CMakeGenerate or :CMakeBuild on an existing project produces the following error:

Error executing Lua callback: ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: attempt to concatenate field 'short' (a nil value)
stack traceback:
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'format_item'
        ...\Local\Programs\Neovim\share\nvim\runtime/lua/vim/ui.lua:48: in function 'select'
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'select_launch_target'
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:467: in function <...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:422>
Error executing Lua callback: ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: attempt to concatenate field 'short' (a nil value)
stack traceback:
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'format_item'
        ...\Local\Programs\Neovim\share\nvim\runtime/lua/vim/ui.lua:48: in function 'select'
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'select_launch_target'
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:467: in function <...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:422>
Error executing Lua callback: ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: attempt to concatenate field 'short' (a nil value)
stack traceback:
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'format_item'
        ...\Local\Programs\Neovim\share\nvim\runtime/lua/vim/ui.lua:48: in function 'select'
        ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function <...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:654>

The same is true for :CMakeRun

Steps to reproduce
Run either of the commands above in a cmake project.

Expected behavior
Expected to see the output window with the cmake generation and build output.

Environment

  • OS: Windows (unfortunately....)
  • Plugins commit hash: 2ca9400

Additional context
Thank you so much for this awesome tool, this has made my C++ nvim experience really great.

Improve docs to help with compiler output parsing in quickfix list

Describe the problem or limitation you are having
error messages from compiler output are not parsed in quickfix list (windows, msbuild)

Describe the solution you'd like
Some 'windows users please note:' section in the readme/docs

The required action

-- MSBuild:
vim.opt.errorformat:append([[\ %#%f(%l\,%c):\ %m]])
-- cl.exe:
vim.opt.errorformat:append([[\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m]])

Unable to disable cmake generate auto-generation on save

Bug description
Hi! When the module gets imported, then an autocommand will be generated here, using default value for cmake_regenerate_on_save (true). So, after config is created, cmake_regenerate_on_save will have no effect.

Steps to reproduce

require("cmake-tools").setup {
    cmake_regenerate_on_save = false,
}

Re-generation is still triggered, which is disturbing, when using auto-save plugin. If you're interested, I can make a PR.

Icon symbols

In the Readme under the full configuraiton, there is require("user.icons"), can you link it or directly add the symbols to the Readme? I have tried searching the evil.lua example but cannot find these symbols.

CMakeRun no longer executes the executable

Bug description
I have just upgrade to the latest version and CMakeRun no longer executes the compiled binary
I have been using a simple CMakeLists file which use to work.

cmake_minimum_required(VERSION 3.26)
project(avl-tree)

set(CMAKE_CXX_STANDARD 20)

add_executable(avl-tree main.cpp)
target_link_libraries(avl-tree PRIVATE -fsanitize=undefined,address)
target_compile_options(avl-tree PRIVATE -fsanitize=undefined,address)

I also have a very simple cmake.lua plugin which has also worked before some recent changes in this project.

local M = {}

M.plugin = {
"Civitasv/cmake-tools.nvim",
config = function()
local cmake = require("cmake-tools")
cmake.setup({
cmake_command = "cmake",
cmake_build_directory = "",
cmake_build_directory_prefix = "cmake_build_",
cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1" },
cmake_generate_on_save = false,
cmake_build_options = {},
cmake_console_size = 10,
cmake_show_console = true,
cmake_variants_message = {
short = { show = true },
long = { show = true, max_length = 40 },
},
cmake_quickfix_opts = {
show = "always",
position = "belowright",
size = 10,
},
})

	vim.keymap.set("n", "<leader>cg", function()
		vim.cmd.CMakeOpen()
		vim.cmd.CMakeGenerate()
	end)
	vim.keymap.set("n", "<leader>cb", function()
		vim.cmd.CMakeOpen()
		vim.cmd.CMakeBuild()
	end)
	vim.keymap.set("n", "<leader>cr", function()
		vim.cmd.CMakeOpen()
		vim.cmd.CMakeRun()
	end)
	vim.keymap.set("n", "<leader>cc", function()
		vim.cmd.CMakeClose()
	end)
	vim.keymap.set("n", "<leader>cl", function()
		vim.cmd.CMakeOpen()
		vim.cmd.CMakeClean()
	end)
end,

}
return M

When you run now a window opens with the following:

cd /usr/home/xxxx/projects/cpp/avl-tree/cmake_build_Debug &&

an the program no longer runs and outputs in this window.

Hope this helps.

Blair

`CMakeBuild` argument passed to cmake before `--build` not after

Bug description

when you call :CMakeBuild -j32, the plugin invokes cmake as cmake -j12 --build ... which results in cmake erroring out. If you put -j12 in config.build_options, the flags are appended at the end of the line and it works as expected though.

Steps to reproduce

in any cmake project, clean the build directory, open neovim and run :CMakeBuild j32.

Expected behavior

I would expect the arguments of CMakeBuild to be passed after the --build flag. So in my example, cmake would be called as cmake --build -j32 ....

Environment

  • OS: Ubuntu 20.04
  • Desktop environment: none - ssh'ed into a remote server
  • Plugins commit hash: 86124bd

Additional context

This seems to be where the argument order is mixed up: https://github.com/Civitasv/cmake-tools.nvim/blob/master/lua/cmake-tools/init.lua#L193

Thanks for an awesome plugin BTW!

Improve cmake_regenerate_on_save

Describe the problem or limitation you are having
Currently cmake_tools only reacts to changes on CMakeLists.txt files. But changes the other files such as .cmake files or files used in configure_file can can cause cmake to re-generate.

Describe the solution you'd like
Fortunately file_picker.get_cmake_files should already contain all relevant files that can cause re-generation. Do you think it would be possible to also (or only) react to those files? It would have to be updated after each cmake.generate()

Key not found: terminal_job_id

Recently I've been getting following sporadic errors when using CMakeRun or similar.

stack traceback:
        [C]: in function 'nvim_buf_get_var'
        .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:170: in function 'send_data_to_terminal'
        .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:461: in function 'execute'
        ...are/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:74: in function 'execute'
        ...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:417: in function 'callback'
        ...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:309: in function 'on_success'
        .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/quickfix.lua:44: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Error executing Lua callback: .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: Key not found: terminal_job_pid
Error executing Lua callback: .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: Key not found: terminal_job_pid
stack traceback:
        [C]: in function 'nvim_buf_get_var'
       .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: in function 'has_active_job'
        ...are/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:130: in function 'has_active_job'
        ...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:477: in function <...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:474>
Error executing Lua callback: .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: Key not found: terminal_job_pid

Steps to reproduce
It occurs randomly when trying to run a target. Sometimes right after starting nvim, sometimes after using nvim for a while. After getting the first error, the second error occurs consistently every time I try to run. I have to restart nvim at that point.

Environment
OS: Linux and Windows WSL (not sure about native windows)

When exiting the current CMakeRun-terminal and cmd CMakeRun, an error occurs.

Bug description

When exiting the current CMakeRun-terminal and cmd CMakeRun, an error occurs.

Steps to reproduce

  1. cmd: CMakeRun
  2. terminal: exit
  3. cmd: CMakeRun
  4. Error executing Lua callback: .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: Invalid buffer id: 17
    stack traceback:
    [C]: in function 'nvim_buf_get_var'
    .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: in function 'has_active_job'
    ...are/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:130: in function 'has_active_job'
    ...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:399: in function <...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:398>
Minimal configuration default

Expected behavior

no errors, running the executor

Environment

  • OS: Ubuntu
  • Desktop environment: Gnome
  • Plugins commit hash: the main branch

build_options are saved in session

I noticed that build_options are saved in the session config

...
  build_options = { "-j32" },
...

I looks like they take precedence over the config passed to setup. E.g once saved the user has no way to change those.

Should build_options be removed from session?
Alternatively should they be configurable via the config window? That would mean the config passed to setup is then just the default.

Not generating compile_commands.json?

Hi everyone,

First off I really appreciate this plugin, it's made the transition to nvim from vscode way more pleasant.

I ran into an issue while working on an existing CMake project in neovim for the first time. Configuring and building with cmake-tools works correctly, but the code is covered in erroneous warnings from clangd; it looks like compile_commands.json isn't being generated anywhere in the build folder. My setup for cmake-tools is exactly the same as the readme in this repo, and I set up clangd via Mason and lspconfig like so:

lspconfig["clangd"].setup({
	capabilities = capabilities,
	on_attach = on_attach,
	on_new_config = function(new_config, new_cwd)
		local status, cmake = pcall(require, "cmake-tools")
		if status then
			cmake.clangd_on_new_config(new_config)
		end
	end,
})

Am I misunderstanding something about how this works or where compile_commands.json should be? Do I need to change the values of cmake_soft_link_compile_commands or cmake_compile_commands_from_lsp in the setup function? I'm on nvim version 0.9.0 and macOS Ventura 13.4 if that's relevant.
Any advice is much appreciated!

error message: couldn't make stderr distinct from stdout

Bug description
when cmake-tools starts, the message dtable::stdio_init couldn't make stderr distinct from stdout flashes up.

Steps to reproduce
Config:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end

vim.opt.rtp:prepend(lazypath)


local plugins = {

  -- cmake
  {
    'Civitasv/cmake-tools.nvim',
    lazy = false,
    config = function(plugin) require('cmake-tools').setup({}) end,
    cmd = {'CMakeBuild', 'CMakeGenerate'},
    -- keys = {
    --   {"<leader>cc", ":CMakeBuild<CR>", desc = "CMake Configure"},
    -- },
    dependencies = {
      'nvim-lua/plenary.nvim',
    },
  },
}

local opts = {}
require("lazy").setup(plugins, opts)

Start nvim (that's it)

Expected behavior
At best, no error message. Improvement would be the error being reported to a log with a call stack.

Screenshots
signal-2023-07-29-114428_002

Environment

  • OS: Win10
  • Terminal: win terminal or wezterm
  • shell: git-bash

Call cmake.build() with callback will not build

Bug description

if type(callback) == "function" then
callback()
else
utils.run(full_cmd, {}, {}, {
cmake_launch_path = vim.loop.cwd(),
cmake_always_use_terminal = const.cmake_always_use_terminal,
cmake_terminal_opts = const.cmake_terminal_opts
})
cmake.configure_compile_commands(const.cmake_always_use_terminal, const.cmake_terminal_opts)
full_cmd = ""
end

As the code show, when config.cmake_always_use_terminal is true, I call cmake.build(opt, callback) with a callback function, the callbak will be called immediately without build

Steps to reproduce

Minimal configuration
    require 'cmake-tools'.setup {
        cmake_build_directory = 'build',
        cmake_always_use_terminal = true,
        cmake_soft_link_compile_commands = false,
    }

add keymap to cmake.build with callback, such as

function()
    require 'cmake-tools'.build({ bang = false }, function()
          vim.notify("Cmake build success")
    end)
end

Expected behavior

Build success, then call callabck

Environment

  • OS: ArchLinux
  • NVIM v0.9.1
  • Plugins commit hash: 2139329

Another proposal

Another proposal, expose local variable config in cmake-tools/init.lua for conveniently obtaining information, e.g. target_binary_path

Set working directory for running

Describe the problem or limitation you are having
I am working on a C++ project which accesses files in a Resources folder as if they were in the working directory. When running the project through CMakeRun, the working directory is that of nvim, so it cannot load the files it needs.

Describe the solution you'd like
The ability to configure the working directory used when launching the program.

Describe alternatives you've considered
I found this issue in vscode-cmake-tools, but setting cwd in the require("cmake-tools").setup call did not appear to do anything. I might be doing this wrong, however, as I'm not sure how launch.json settings translate to this project.

configuration not work

Hi, this plugin is very useful for me, but I want to change debug to cppdbg, however my configuration is not working.
When I use :CMakeDebug, it still calls codelldb.Then I tried to change other configurations, but it still did not work.
image
Here is my configuration code:

-- plugins.lua
use({
  "Civitasv/cmake-tools.nvim",
  config = function()
    require("plugin-config.cmake-tools")
  end,
})
-- plugin-config/cmake-tools.lua
local status, cmake = pcall(require, "cmake-tools")
if not status then
  vim.notify("没有找到 cmake-tools")
  return
end

cmake.setup({
  cmake_command = "cmake",
  cmake_build_directory = "build",
  cmake_build_type = "Debug",
  cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1" },
  cmake_build_options = {},
  cmake_console_size = 10, -- cmake output window height
  cmake_show_console = "always", -- "always", "only_on_error"
  cmake_dap_configuration = { name = "Launch file", type = "cppdbg", request = "launch" }, -- dap configuration, optional
  cmake_dap_open_command = require("dap").repl.open, -- optional
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.