xeluxee / competitest.nvim

CompetiTest.nvim is a Neovim plugin for Competitive Programming: it can manage and check testcases, download problems and contests from online judges and much more
GNU Lesser General Public License v3.0
389 stars 16 forks source link

Use lua api instead of viml #7

Closed nullchilly closed 2 years ago

nullchilly commented 2 years ago

vim.api.nvim_set_hl: Not sure why CompetiTestWarning default guifg is orange instead of hex color?

vim.api.nvim_create_autocmd replaced vim.cmd[[autocmd]]

vim.api.nvim_create_user_command Not sure why the ! modifier is necessary for command but I added bang = true via vim.tbl_extend 🤔

nullchilly commented 2 years ago

CompetiTest convert all I still want this space completion like Telescope's

https://github.com/nvim-telescope/telescope.nvim/blob/master/plugin/telescope.lua#L108-L143

vim.api.nvim_create_user_command("Telescope", function(opts)
  require("telescope.command").load_command(unpack(opts.fargs))
end, {
  nargs = "*",
  complete = function(_, line)
    local builtin_list = vim.tbl_keys(require "telescope.builtin")
    local extensions_list = vim.tbl_keys(require("telescope._extensions").manager)

    local l = vim.split(line, "%s+")
    local n = #l - 2

    if n == 0 then
      return vim.tbl_filter(function(val)
        return vim.startswith(val, l[2])
      end, vim.tbl_extend("force", builtin_list, extensions_list))
    end

    if n == 1 then
      local is_extension = vim.tbl_filter(function(val)
        return val == l[2]
      end, extensions_list)

      if #is_extension > 0 then
        local extensions_subcommand_dict = require("telescope.command").get_extensions_subcommand()
        return vim.tbl_filter(function(val)
          return vim.startswith(val, l[3])
        end, extensions_subcommand_dict[l[2]])
      end
    end

    local options_list = vim.tbl_keys(require("telescope.config").values)
    return vim.tbl_filter(function(val)
      return vim.startswith(val, l[#l])
    end, options_list)
  end,
})

Then we will be able to add more things like flags control without clutter the completion list

Work in progress. Something higher priority would be adding test cases completion list I guess