aboutsummaryrefslogtreecommitdiff
path: root/neovim/.config/nvim/lua/dyamon/lsp.lua
blob: 0424929cc3d5ff1bf71f33437c2a9665d54091e3 (plain) (blame)
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
--- Personal lua config files for NeoVim.
--  Last Changed: 2019-01-27
--  Author: Federico Igne <git@federicoigne.com>
--  License: This file is placed in the public domain.

local map = require 'dyamon.util.map'

local lsp = { }

--- Collection of settings to be set for any language server
function lsp.on_attach_common(client, bufnr, opts)
  local opts = opts or { }

  -- Connect omnifunc completion with LSP server
  vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Collection of bindings taken from
  --    https://github.com/neovim/nvim-lspconfig#keybindings-and-completion
  map.b.nore.n(bufnr, 'gd', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
  map.b.nore.n(bufnr, 'gD', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
  map.b.nore.n(bufnr, 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
  --map.b.nore.n(bufnr, 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  --map.b.nore.n(bufnr, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  --map.b.nore.n(bufnr, '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  --map.b.nore.n(bufnr, '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  --map.b.nore.n(bufnr, '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  --map.b.nore.n(bufnr, '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  map.b.nore.n(bufnr, '<leader>ln', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
  map.b.nore.n(bufnr, '<leader>la', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
  map.b.nore.n(bufnr, '<leader>lr', '<cmd>Telescope lsp_references<cr>', opts)
  map.b.nore.n(bufnr, '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>', opts)
  map.b.nore.n(bufnr, ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>', opts)
  --map.b.nore.n(bufnr, '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
  --map.b.nore.n(bufnr, '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
  map.b.nore.n(bufnr, '<leader>ld', '<cmd>Telescope diagnostics<cr>', opts)

end

function lsp.on_attach_clangd(client, bufnr, opts)
  local opts = opts or { }
  lsp.on_attach_common(client, bufnr, opts)
  map.b.nore.n(bufnr, '<leader>##', '<cmd>ClangdSwitchSourceHeader<cr>', opts)
  map.b.nore.n(bufnr, '<leader>#s', '<cmd>split | ClangdSwitchSourceHeader<cr>', opts)
  map.b.nore.n(bufnr, '<leader>#v', '<cmd>vertical split | ClangdSwitchSourceHeader<cr>', opts)
  map.b.nore.n(bufnr, '<leader>#t', '<cmd>tab split | ClangdSwitchSourceHeader<cr>', opts)
  map.b.nore.n(bufnr, '<leader>#S', '<cmd>botright split | ClangdSwitchSourceHeader<cr>', opts)
  map.b.nore.n(bufnr, '<leader>#V', '<cmd>botright vertical split | ClangdSwitchSourceHeader<cr>', opts)


end

function lsp.on_attach_ltex(client, bufnr, opts)
  local opts = opts or { }
  map.b.nore.n(bufnr, '<leader>=', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
  map.b.nore.n(bufnr, '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>', opts)
  map.b.nore.n(bufnr, ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>', opts)
  map.b.nore.n(bufnr, '<leader>ld', '<cmd>Telescope diagnostics<cr>', opts)
end

return lsp