mistweaverco / kulala-cmp-graphql.nvim

nvim-cmp source 🧙 for graphql 📊 completions 📋 in http/rest files based on schema 💪 for your favorite editor 😍
14 stars 0 forks source link

Lazyvim cmp setup for kulala-cmp-graphql #3

Closed AlexanderNelzin closed 3 months ago

AlexanderNelzin commented 3 months ago

Need help to set up cmp properly. Tried to place this part of code from README.md to ~/.config/nvim/lua/plugins/cmp.lua file with different variations like this:

return {
  "hrsh7th/nvim-cmp",
  event = "VeryLazy",
  function()
    local cmp = require("cmp")
    cmp.setup.filetype("http", {
      sources = cmp.config.sources({
        { name = "kulala-cmp-graphql" },
      }, {
        { name = "buffer" },
      }),
    })
  end,
}

But didn't got it working. Can you please help me to set it up correctly?

gorillamoe commented 3 months ago

I have stripped down my config, but it looks something like this:

-- Bootstrapping lazy.nvim
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)

-- Install Plugins
require("lazy").setup({
  {
    "nvim-treesitter/nvim-treesitter",
    build = function()
      pcall(require("nvim-treesitter.install").update { with_sync = true })
    end,
    config = function()
      require('nvim-treesitter.configs').setup({
        -- Add languages to be installed here that you want installed for treesitter
        ensure_installed = {
          'http',
          'json',
        },
        highlight = { enable = true },
        indent = { enable = true },
      })
    end,
  },
  {
    "mistweaverco/kulala.nvim",
    opts= {},
  },
  {
    "hrsh7th/nvim-cmp", -- Autocompletion plugin
    config = function()
      -- Set up nvim-cmp.
      local cmp = require("cmp")
      local lspkind = require("lspkind")

      cmp.setup({
        formatting = {
          format = lspkind.cmp_format({
            preset = "default", -- can be either 'default' (requires nerd-fonts font) or 'codicons' for codicon preset (requires vscode-codicons font)
            mode = "symbol_text", -- show only symbol annotations
            -- maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
            -- can also be a function to dynamically calculate max width such as
            -- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
            ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
            show_labelDetails = true, -- show labelDetails in menu. Disabled by default
          }),
        },
        window = {
          completion = cmp.config.window.bordered(),
          documentation = cmp.config.window.bordered(),
        },
        mapping = cmp.mapping.preset.insert({
          ["<C-b>"] = cmp.mapping.scroll_docs(-4),
          ["<C-f>"] = cmp.mapping.scroll_docs(4),
          ["<C-Space>"] = cmp.mapping.complete(),
          ["<C-e>"] = cmp.mapping.abort(),
          ["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
        }),
        sources = cmp.config.sources({
          { name = "nvim_lsp" },
        }, {
          { name = "buffer" },
        }),
      })
      cmp.setup.filetype("http", {
        sources = cmp.config.sources({
          { name = "kulala-cmp-graphql" },
        }, {
          { name = "buffer" },
        }),
      })
    end,
    dependencies = {
      "hrsh7th/cmp-nvim-lsp", -- LSP source for nvim-cmp
      "hrsh7th/cmp-buffer",
      "hrsh7th/cmp-path",
      "onsails/lspkind.nvim", -- Add vscode-like pictograms to completion items
      {
        "mistweaverco/kulala-cmp-graphql.nvim", -- GraphQL source for nvim-cmp in http files
        opts = {},
        ft = "http",
      },
    },
  },
})
AlexanderNelzin commented 3 months ago

@gorillamoe , thanks! Got it working! I created ~/.config/nvim/lua/plugins/cmp.lua, used default config from https://www.lazyvim.org/plugins/coding#nvim-cmp and added code from readme ( cmp.setup.filetype ... ) at the end of opts function.

gorillamoe commented 3 months ago

Glad you managed to get it done! 👍🏾