aboutsummaryrefslogtreecommitdiff
path: root/lua/plugins/cmp.lua
blob: 1eb964697aa977cb856290addc1619299bf7563a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
return {
  {
    'hrsh7th/nvim-cmp',
    dependencies = {
      'nvim-lua/popup.nvim',
      'nvim-lua/plenary.nvim',
      'saadparwaiz1/cmp_luasnip',
      "hrsh7th/cmp-emoji",
      'hrsh7th/cmp-nvim-lsp',
      'hrsh7th/cmp-buffer',
      'hrsh7th/cmp-path',
      'hrsh7th/vim-vsnip',
      'octaltree/cmp-look',
      'folke/trouble.nvim',
      {
        'L3MON4D3/LuaSnip',
        config = function()
          vim.keymap.set(
          {"i", "s"},
          "<leader><Tab>",
          function() require('luasnip').jump(1) end,
          {silent = true}
          )
          vim.keymap.set(
          {"i", "s"},
          "<leader><S-Tab>",
          function() require('luasnip').jump(-1) end,
          {silent = true}
          )
        end,
      },
    },

    config = function()
      require('trouble').setup()

      local cmp = require'cmp'
      cmp.setup({
        snippet = {
          -- REQUIRED - you must specify a snippet engine
          expand = function(args)
            require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
            -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
          end,
        },
        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 = 'luasnip' }, -- For luasnip users.
        }, {
          { name = 'buffer' },
        })
      })
    end
  },
  {
    'neovim/nvim-lspconfig',
    dependencies = {
      { "folke/neodev.nvim" }
    },
    config = function()
      -- Set up lspconfig.
      local keymap = vim.keymap
      local on_attach = function(client, bufnr)
        local opts = { noremap = true, silent = true, buffer = bufnr }
        keymap.set("n", "gf", "<cmd>Lspsaga lsp_finder<CR>", opts) -- show definition, references
        keymap.set("n", "gD", "<Cmd>Lspsaga goto_definition<CR>", opts) -- got to declaration
        keymap.set("n", "gd", "<cmd>Lspsaga peek_definition<CR>", opts) -- see definition and make edits in window
        keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) -- go to implementation
        keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts) -- see available code actions
        keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts) -- smart rename
        keymap.set("n", "<leader>D", "<cmd>Lspsaga show_line_diagnostics<CR>", opts) -- show  diagnostics for line
        keymap.set("n", "<leader>d", "<cmd>Lspsaga show_cursor_diagnostics<CR>", opts) -- show diagnostics for cursor
        keymap.set("n", "[d", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opts) -- jump to previous diagnostic in buffer
        keymap.set("n", "]d", "<cmd>Lspsaga diagnostic_jump_next<CR>", opts) -- jump to next diagnostic in buffer
        keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", opts) -- show documentation for what is under cursor
        keymap.set("n", "<leader>o", "<cmd>LSoutlineToggle<CR>", opts) -- see outline on right hand side
        keymap.set("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
        vim.keymap.set("n", "<C-n>", ":cnext<CR>")
        vim.keymap.set("n", "<C-p>", ":cprev<CR>")
      end

      local capabilities = require("cmp_nvim_lsp").default_capabilities()

      -- # Language Servers
      --   https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
      for _,server in ipairs({
        'bitbake_language_server',
        "clangd",         -- C/C++ | clang
        "ts_ls",          -- javascript | typescript-language-server
        "lua_ls",         -- lua (but not init.lua entirely, hence why neodev)
        "jdtls",
        "html",
        "cssls",          -- ccs | vscode-css-languageserver
        "rust_analyzer",  -- rust | rust-analyzer 
        "eslint",         -- javascript | eslint
        'vimls',          -- vimscript | vim-language-server
        'html',           -- html
        'jsonls',         -- jsonls
        "pyright",        -- python
        "bashls",         -- bash | bash-language-server
        "gopls",
        "emmet_ls",
        "marksman"}) do
        require("lspconfig")[server].setup({
          capabilities = capabilities,
          on_attach = on_attach
        })
      end

      -- # specialized config for some LSPs which have non-ideal defaults
      --
      -- require('lspconfig')['java_language_server'].setup{ cmd = { "/usr/share/java/java-language-server/lang_server_linux.sh" }, root_dir = function () return vim.fn.getcwd() end }
      -- configure html server
      require('lspconfig')["html"].setup({
        init_options = {
          configurationSection = { "html", "css", "javascript" },
          embeddedLanguages = {
            css = true,
            javascript = true,
          },
          provideFormatter = true,
        },
      })
      require('lspconfig')['pylsp'].setup{
        settings = {
          pylsp = {
            plugins = {
              pycodestyle = {
                ignore = {'W391'},
                maxLineLength = 100
              }
            }
          }
        }
      }
      require("lspconfig").clangd.setup {
        on_attach = on_attach,
        capabilities = capabilities,
        cmd = {
          "clangd",
          "--offset-encoding=utf-16",
        },
      }
    end
  }
}
..