-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
124 lines (100 loc) · 4.42 KB
/
init.lua
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
local lspconfig = require('lspconfig')
local utils = require("utils")
vim.cmd('autocmd BufRead,BufNewFile *.hbs set filetype=html')
require('lsp-config.cmp-config')
require('lsp-config.comment-config')
require('lsp-config.treesitter-config')
-- [[ Configure LSP ]]
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr)
-- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time.
local nmap = function(keys, func, desc, mode) utils.nmap(keys, func, "LSP: " .. desc, mode, bufnr) end
nmap('<c-r><c-r>', vim.lsp.buf.rename, '<c-r><c-r> Rename')
nmap('<a-cr>', function() vim.cmd("CodeActionMenu") end, '[a-cr] Code Action', { 'n', 'v' })
nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
nmap('<F12>', require('telescope.builtin').lsp_references, '[F12]ind References')
nmap('<C-F12>', require('telescope.builtin').lsp_implementations, '[C-F12]ind Implementations')
nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Do[K]umentation')
-- nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Do[<c-K>]umentation')
-- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' })
nmap('<C-K><C-F>', function() vim.cmd("Format") end, '[C-K C-F] Format Document', { 'n', 'v' })
end
-- mason-lspconfig requires that these setup functions are called in this order
-- before setting up the servers.
require('mason').setup()
require('mason-lspconfig').setup()
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- rust_analyzer = {},
-- tsserver = {},
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
}
-- Setup neovim lua configuration
require('neodev').setup()
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Ensure the servers above are installed
local mason_lspconfig = require('mason-lspconfig')
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}
mason_lspconfig.setup_handlers {
function(server_name)
lspconfig[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
}
end,
}
lspconfig.tsserver.setup {}
lspconfig.html.setup {
filetypes = { "html", "hbs", "handlebars" }
}
lspconfig.omnisharp.setup {
cmd = { "omnisharp" },
enable_roslyn_analyzers = true,
-- analyze_open_documents_only = true,
organize_imports_on_format = true,
enable_import_completion = true,
}
-- lspconfig.csharp_ls.setup{}
-- require("roslyn").setup({
-- dotnet_cmd = "dotnet", -- this is the default
-- roslyn_version = "4.8.0-3.23475.7", -- this is the default
-- on_attach = on_attach,
-- capabilities = capabilities
-- })
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
on_attach(nil, ev.buf)
end,
})