Civitasv / cmake-tools.nvim

CMake integration in Neovim
GNU General Public License v3.0
371 stars 63 forks source link

Usage/workflow questions #201

Open TheSunCat opened 7 months ago

TheSunCat commented 7 months ago

Hi! I set up this plugin with the terminal option, and it does its job. Thanks for maintaining it!

I believe I may be using it wrong though, as I have encountered several issues with it:

  1. it seems to always create a buffer called *cmake-tools* that shows up in my bar and gets saved as a file when I do :wa This is tracked at #198
  2. it outputs to a terminal that opens at the bottom, but this terminal does not scroll down to the latest output, so I am always looking at the first build/generate I ever did
  3. the terminal stays open and if I use a keybind to go to the next or previous buffer, it changes the terminal into the contents of the file I was going to.
  4. sometimes the terminal CD's to the build directory, and then none of the commands work as they cannot find a CMakeLists.txt until I manually run :cd ..
  5. the toggleterm mode starts printing errors if my program logs too much, and eventually fully freezes nvim (requiring force closing my terminal emulator)

Did I mess up my config or is this normal behavior?

Config:

cmake-tools config ```lua require("cmake-tools").setup { cmake_command = "cmake", -- this is used to specify cmake command path ctest_command = "ctest", -- this is used to specify ctest command path cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate` cmake_build_options = {}, -- this will be passed when invoke `CMakeBuild` -- support macro expansion: -- ${kit} -- ${kitGenerator} -- ${variant:xx} cmake_build_directory = "out/${variant:buildType}", -- this is used to specify generate directory for cmake, allows macro expansion, relative to vim.loop.cwd() cmake_soft_link_compile_commands = true, -- this will automatically make a soft link from compile commands file to project root dir cmake_compile_commands_from_lsp = false, -- this will automatically set compile commands file location using lsp, to use it, please set `cmake_soft_link_compile_commands` to false cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage cmake_variants_message = { short = { show = true }, -- whether to show short message long = { show = true, max_length = 40 }, -- whether to show long message }, cmake_dap_configuration = { -- debug settings for cmake name = "cpp", type = "codelldb", request = "launch", stopOnEntry = false, runInTerminal = true, console = "integratedTerminal", }, cmake_executor = { -- executor to use name = "terminal", -- name of the executor opts = {}, -- the options the executor will get, possible values depend on the executor type. See `default_opts` for possible values. default_opts = { -- a list of default and possible values for executors quickfix = { show = "always", -- "always", "only_on_error" position = "belowright", -- "vertical", "horizontal", "leftabove", "aboveleft", "rightbelow", "belowright", "topleft", "botright", use `:h vertical` for example to see help on them size = 10, encoding = "utf-8", -- if encoding is not "utf-8", it will be converted to "utf-8" using `vim.fn.iconv` auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful. }, -- toggleterm = { -- direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' -- close_on_exit = false, -- whether close the terminal when exit -- auto_scroll = true, -- whether auto scroll to the bottom -- }, -- overseer = { -- new_task_opts = { -- strategy = { -- "toggleterm", -- direction = "horizontal", -- autos_croll = true, -- quit_on_exit = "success" -- } -- }, -- options to pass into the `overseer.new_task` command -- on_new_task = function(task) -- require("overseer").open( -- { enter = false, direction = "right" } -- ) -- end, -- a function that gets overseer.Task when it is created, before calling `task:start` -- }, terminal = { name = "Main Terminal", prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name split_direction = "horizontal", -- "horizontal", "vertical" split_size = 11, -- Window handling single_terminal_per_instance = true, -- Single viewport, multiple windows single_terminal_per_tab = true, -- Single viewport per tab keep_terminal_static_location = true, -- Static location of the viewport if avialable -- Running Tasks start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun focus = false, -- Focus on terminal when cmake task is launched. do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter. }, -- terminal executor uses the values in cmake_terminal }, }, cmake_runner = { -- runner to use name = "terminal", -- name of the runner opts = {}, -- the options the runner will get, possible values depend on the runner type. See `default_opts` for possible values. default_opts = { -- a list of default and possible values for runners quickfix = { show = "always", -- "always", "only_on_error" position = "belowright", -- "bottom", "top" size = 10, encoding = "utf-8", auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful. }, --toggleterm = { -- direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' -- close_on_exit = false, -- whether close the terminal when exit -- auto_scroll = true, -- whether auto scroll to the bottom --}, --overseer = { -- new_task_opts = { -- strategy = { -- "toggleterm", -- direction = "horizontal", -- autos_croll = true, -- quit_on_exit = "success" -- } -- }, -- options to pass into the `overseer.new_task` command -- on_new_task = function(task) -- end, -- a function that gets overseer.Task when it is created, before calling `task:start` --}, terminal = { name = "Main Terminal", prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name split_direction = "horizontal", -- "horizontal", "vertical" split_size = 11, -- Window handling single_terminal_per_instance = true, -- Single viewport, multiple windows single_terminal_per_tab = true, -- Single viewport per tab keep_terminal_static_location = true, -- Static location of the viewport if avialable -- Running Tasks start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun focus = false, -- Focus on terminal when cmake task is launched. do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter. }, }, }, cmake_notifications = { runner = { enabled = true }, executor = { enabled = true }, spinner = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }, -- icons used for progress display refresh_rate_ms = 100, -- how often to iterate icons }, working_dir = "${dir.build}/..", } ```
quasar-pankaj commented 7 months ago

Hello @Civitasv, I have added it to my config as follows in my plugins.lua (I am using nvchad as my base config and followed this video to configure it for c++):

{
        "Civitasv/cmake-tools.nvim",
        config = function()
            require("cmake-tools").setup {
                cmake_command = "cmake", -- this is used to specify cmake command path
                ctest_command = "ctest", -- this is used to specify ctest command path
                cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt
                cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate`
                cmake_build_options = {}, -- this will be passed when invoke `CMakeBuild`
                -- support macro expansion:
                --       ${kit}
                --       ${kitGenerator}
                --       ${variant:xx}
                cmake_build_directory = "out/${variant:buildType}", -- this is used to specify generate directory for cmake, allows macro expansion, relative to vim.loop.cwd()
                cmake_soft_link_compile_commands = true, -- this will automatically make a soft link from compile commands file to project root dir
                cmake_compile_commands_from_lsp = false, -- this will automatically set compile commands file location using lsp, to use it, please set `cmake_soft_link_compile_commands` to false
                cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage
                cmake_variants_message = {
                    short = { show = true }, -- whether to show short message
                    long = { show = true, max_length = 40 }, -- whether to show long message
                },
                cmake_dap_configuration = { -- debug settings for cmake
                    name = "cpp",
                    type = "codelldb",
                    request = "launch",
                    stopOnEntry = false,
                    runInTerminal = true,
                    console = "integratedTerminal",
                },
                cmake_executor = { -- executor to use
                    name = "quickfix", -- name of the executor
                    opts = {}, -- the options the executor will get, possible values depend on the executor type. See `default_opts` for possible values.
                    default_opts = { -- a list of default and possible values for executors
                        quickfix = {
                          show = "always", -- "always", "only_on_error"
                          position = "belowright", -- "vertical", "horizontal", "leftabove", "aboveleft", "rightbelow", "belowright", "topleft", "botright", use `:h vertical` for example to see help on them
                          size = 10,
                          encoding = "utf-8", -- if encoding is not "utf-8", it will be converted to "utf-8" using `vim.fn.iconv`
                          auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful.
                        },
                        toggleterm = {
                          direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float'
                          close_on_exit = false, -- whether close the terminal when exit
                          auto_scroll = true, -- whether auto scroll to the bottom
                        },
                        overseer = {
                          new_task_opts = {
                              strategy = {
                                  "toggleterm",
                                  direction = "horizontal",
                                  autos_croll = true,
                                  quit_on_exit = "success"
                              }
                          }, -- options to pass into the `overseer.new_task` command
                          on_new_task = function(task)
                              require("overseer").open(
                                  { enter = false, direction = "right" }
                              )
                          end,   -- a function that gets overseer.Task when it is created, before calling `task:start`
                        },
                        terminal = {
                          name = "Main Terminal",
                          prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name
                          split_direction = "horizontal", -- "horizontal", "vertical"
                          split_size = 11,

                          -- Window handling
                          single_terminal_per_instance = true, -- Single viewport, multiple windows
                          single_terminal_per_tab = true, -- Single viewport per tab
                          keep_terminal_static_location = true, -- Static location of the viewport if avialable

                          -- Running Tasks
                          start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
                          focus = false, -- Focus on terminal when cmake task is launched.
                          do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter.
                        }, -- terminal executor uses the values in cmake_terminal
                    },
                },
                cmake_runner = { -- runner to use
                    name = "terminal", -- name of the runner
                    opts = {}, -- the options the runner will get, possible values depend on the runner type. See `default_opts` for possible values.
                    default_opts = { -- a list of default and possible values for runners
                        quickfix = {
                          show = "always", -- "always", "only_on_error"
                          position = "belowright", -- "bottom", "top"
                          size = 10,
                          encoding = "utf-8",
                          auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful.
                        },
                        toggleterm = {
                          direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float'
                          close_on_exit = false, -- whether close the terminal when exit
                          auto_scroll = true, -- whether auto scroll to the bottom
                        },
                        overseer = {
                          new_task_opts = {
                              strategy = {
                                  "toggleterm",
                                  direction = "horizontal",
                                  autos_croll = true,
                                  quit_on_exit = "success"
                              }
                          }, -- options to pass into the `overseer.new_task` command
                          on_new_task = function(task)
                          end,   -- a function that gets overseer.Task when it is created, before calling `task:start`
                        },
                        terminal = {
                          name = "Main Terminal",
                          prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name
                          split_direction = "horizontal", -- "horizontal", "vertical"
                          split_size = 11,

                          -- Window handling
                          single_terminal_per_instance = true, -- Single viewport, multiple windows
                          single_terminal_per_tab = true, -- Single viewport per tab
                          keep_terminal_static_location = true, -- Static location of the viewport if avialable

                          -- Running Tasks
                          start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
                          focus = false, -- Focus on terminal when cmake task is launched.
                          do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter.
                        },
                    },
                },
                cmake_notifications = {
                    runner = { enabled = true },
                    executor = { enabled = true },
                    spinner = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }, -- icons used for progress display
                    refresh_rate_ms = 100, -- how often to iterate icons
                },
            }
        end
    },

and apparently it is having no effect at all. I am new to neovim and lua so maybe I have done something wrong here. Can you help me out in this regard? Thanks, Pankaj

Civitasv commented 7 months ago

@quasar-pankaj I think you should check how to install plugin in NVChad.

quasar-pankaj commented 7 months ago

Can you provide a link because that is where I am having problems

@quasar-pankaj I think you should check how to install plugin in NVChad.

I can't seem to find that information. Thanks.

Arniiiii commented 7 months ago

@quasar-pankaj you can check my NvChad config. https://github.com/Gerodote/Nvchad_config_cpp

code-disaster commented 6 months ago

I have to backup @quasar-pankaj here - at least some of the options do not seem to have any effect.

Btw, the NVChad config has a cmake_terminal block which isn't referenced anywhere. I doubt this works as intended.

Civitasv commented 5 months ago

This already get fixed.

  • it outputs to a terminal that opens at the bottom, but this terminal does not scroll down to the latest output, so I am always looking at the first build/generate I ever did

Fixed.

  • the terminal stays open and if I use a keybind to go to the next or previous buffer, it changes the terminal into the contents of the file I was going to.

In this case, terminal is the next buffer, so use :bn and :bp should switch between current and terminal buffer, is that bother to you?

  • sometimes the terminal CD's to the build directory, and then none of the commands work as they cannot find a CMakeLists.txt until I manually run :cd ..

I don't quite understand this problem, can you give reproduce steps?

  • the toggleterm mode starts printing errors if my program logs too much, and eventually fully freezes nvim (requiring force closing my terminal emulator)

can you also give reproduce steps?

Civitasv commented 5 months ago

I have to backup @quasar-pankaj here - at least some of the options do not seem to have any effect.

  • quickfix.auto_close_when_success = false doesn't work for me. It always closes the window.
  • terminal.split_size is ignored, the terminal is always resized to 50% height. Though I can't rule out one of my other plugins interfering.

Btw, the NVChad config has a cmake_terminal block which isn't referenced anywhere. I doubt this works as intended.

I've checked both auto_close_when_success and terminal.split_size works right for me, can you update to the latest commit and see if they work?