simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 159 forks source link

[Feature request] Integrate with overseer #340

Open qRoC opened 1 year ago

qRoC commented 1 year ago

https://github.com/stevearc/overseer.nvim - A task runner and job management plugin for Neovim

Command to integrate:

qRoC commented 1 year ago

ok, that turned out to be easy. I think it makes no sense to include in the plugin

IndianBoy42 commented 1 year ago

Could you share what you did to integrate?

qRoC commented 1 year ago

@IndianBoy42

lua/overseer/template/personal/rust-tools-runnables.lua:

-- https://github.com/simrat39/rust-tools.nvim/blob/master/lua/rust-tools/runnables.lua

local rt = require "rust-tools"

local function get_params()
  return {
    textDocument = vim.lsp.util.make_text_document_params(0),
    position = nil, -- get em all
  }
end

local function getCommand(result)
  local ret = {}
  local args = result.args

  local dir = args.workspaceRoot

  ret = vim.list_extend(ret, args.cargoArgs or {})
  ret = vim.list_extend(ret, args.cargoExtraArgs or {})
  table.insert(ret, "--")
  ret = vim.list_extend(ret, args.executableArgs or {})

  return "cargo", ret, dir
end

return {
  generator = function(_, cb)
    local handler = function(_, results)
      if results == nil then
        return
      end

      local ret = {}
      for _, result in pairs(results) do
        local command, args, cwd = getCommand(result)
        table.insert(ret, {
          name = result.label,
          builder = function()
            return {
              name = result.label,
              cmd = command,
              cwd = cwd,
              args = args,
              components = { "default", "unique" },
            }
          end,
        })
      end

      cb(ret)
    end

    rt.utils.request(0, "experimental/runnables", get_params(), handler)
  end,
  condition = {
    callback = function()
      return #vim.lsp.get_active_clients { name = "rust_analyzer" } >= 1
    end,
  },
}

Add to overseer setup:

templates = { "builtin", "personal" },