Shatur / neovim-cmake

CMake integration for Neovim
GNU General Public License v3.0
87 stars 19 forks source link

API For Fetching Build Targets #46

Closed JuniorSuperTux closed 2 years ago

JuniorSuperTux commented 2 years ago

Describe the problem or limitation you are having I want to integrate the build type selection and build target selection with fzf, and I need to get the targets

Describe the solution you'd like A function that returns an array of build targets in string

Describe alternatives you've considered Copying the code in this project to the config file

Additional context That's all about it

Shatur commented 2 years ago

I want to integrate the build type selection and build target selection with fzf, and I need to get the targets

The plugin is not tied to picker, it uses vim.ui.select. You can just install something like https://github.com/stevearc/dressing.nvim and to use FZF or Telescope for target selection.

A function that returns an array of build targets in string

You can reuse any function from the plugin. To get targets use the following:

local ProjectConfig = require('cmake.project_config') -- Import it

local project_config = ProjectConfig.new()
local targets = project_config:get_codemodel_targets()

In case you want to do it yourself.

JuniorSuperTux commented 2 years ago

I was trying to combine the example you gave me with nui, but I got some problems

/home/supertux/build/linux-debug/.cmake/api/v1/reply is not accessible by the current user!                                                                                                                        
E5108: Error executing lua ...im/site/pack/packer/start/nui.nvim/lua/nui/menu/init.lua:82: attempt to index field 'size' (a nil value)                                                                             
stack traceback:                                                                                                                                                                                                   
        ...im/site/pack/packer/start/nui.nvim/lua/nui/menu/init.lua:82: in function 'make_default_prepare_node'                                                                                                    
        ...im/site/pack/packer/start/nui.nvim/lua/nui/menu/init.lua:269: in function 'init'                                                                                                                        
        .../site/pack/packer/start/nui.nvim/lua/nui/object/init.lua:111: in function 'nui_menu'                                                                                                                    
        /home/supertux/.config/nvim/init.lua:526: in function 'CMake_select_target_nui'                                                                                                                            
        [string ":lua"]:1: in main chunk  

Unable to find codemodel file

The following is how I did it:

local nui_menu = require('nui.menu')
local nui_event = require('nui.utils.autocmd').event

local function convert_array_to_menu(array)
    local menu_items = {}
    for _, name in ipairs(array) do
        table.insert(menu_items, nui_menu.item(name))
    end
    return menu_items
end

function CMake_select_target_nui()
    local project_config = require('cmake.project_config').new()
    local targets = project_config:get_codemodel_targets()
    local menu = nui_menu({
        border = {
            style = "single",
            text = {
                top = "[Select Target]",
                top_align = "center",
            },
        }
    }, {
        lines = {
            convert_array_to_menu(targets)
        }
    })
    menu:mount()
    menu:on(nui_event.BufLeave, menu.menu_props.on_close, { once = true })
end

Is there anything that I didn't do properly? (Sorry I've never coded in lua before)

Shatur commented 2 years ago

I don't see any error caused by my plugin (all comes from nui). And it looks like this error:

/home/supertux/build/linux-debug/.cmake/api/v1/reply is not accessible by the current user!

Indicates that you have permission issues.

JuniorSuperTux commented 2 years ago

How should I solve the permission issue? Everything seems to work fairly fine when I use the default one that comes with this plugin

Shatur commented 2 years ago

How should I solve the permission issue?

How can I know? Check this folder, maybe it doesn't exist. You need to configure your CMake project first.

JuniorSuperTux commented 2 years ago

Now that I noticed, the CMake path is sus. My best guess is that some autocmd changed the working directory of neovim, I'll check it tomorrow, thanks for your advice

JuniorSuperTux commented 2 years ago

After some attempting, the CMake part seems to be working, but I still haven't got nui to work.