-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
145 lines (135 loc) · 4.48 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
--- `true` if this version of nvim can show inlay hints.
local has_inlay_hints = vim.lsp['inlay_hint'] ~= nil
vim.api.nvim_create_autocmd('LspAttach', {
desc = 'Run when a language server is attached',
callback = function(args)
if not (args.data and args.data.client_id) then
vim.notify('unable to execute LSP on_attach', vim.log.levels.WARN)
return
end
local client = vim.lsp.get_client_by_id(args.data.client_id)
if not client then
vim.notify('unable to get client', vim.log.levels.WARN)
return
end
local bufnr = args.buf
local methods = vim.lsp.protocol.Methods
if client.name == 'null-ls' then
local ft = vim.bo[bufnr].filetype
for _, nls in ipairs(require('null-ls').get_source({ filetype = ft })) do
require('util').lang_tools.register(nls.name, bufnr)
end
else
require('util').lang_tools.register(client.name, bufnr)
end
if client.supports_method(methods.textDocument_documentSymbol) then
require('nvim-navic').attach(client, bufnr)
require('nvim-navbuddy').attach(client, bufnr)
end
require('plugin.lsp.formatting').on_attach(client, bufnr)
require('plugin.lsp.keymaps').on_attach(client, bufnr)
if has_inlay_hints then
if client and client.supports_method(methods.textDocument_inlayHint) then
-- For some reason, inlay hints don't show up for me until InsertEnter. This defer resolves that.
vim.defer_fn(function()
vim.lsp.inlay_hint.enable(0, true)
end, 500)
end
else
require('lsp-inlayhints').on_attach(client, bufnr, false)
end
end,
})
return {
{
'neovim/nvim-lspconfig',
event = { 'BufReadPre', 'BufNewFile' },
dependencies = {
'williamboman/mason-lspconfig.nvim',
'folke/trouble.nvim',
'SmiteshP/nvim-navic',
'SmiteshP/nvim-navbuddy',
'b0o/schemastore.nvim',
'mason.nvim',
-- neoconf must be loaded _before_ an lsp
{
'folke/neoconf.nvim',
opts = {
import = {
coc = false,
nlsp = false,
},
},
},
{
'lvimuser/lsp-inlayhints.nvim',
cond = function()
if has_inlay_hints and vim.version().prerelease == false then
vim.notify('nvim now supports inlay hints. Remove lsp-inlayhints and related checks.', vim.log.levels.WARN)
end
return not has_inlay_hints
end,
config = true,
},
{ 'folke/neodev.nvim', config = true },
},
config = function()
vim.fn.sign_define({
{ name = 'DiagnosticSignError', text = '', texthl = 'DiagnosticSignError', numhl = '' },
{ name = 'DiagnosticSignWarn', text = '', texthl = 'DiagnosticSignWarn', numhl = '' },
{ name = 'DiagnosticSignHint', text = '', texthl = 'DiagnosticSignHint', numhl = '' },
{ name = 'DiagnosticSignInfo', text = '', texthl = 'DiagnosticSignInfo', numhl = '' },
})
vim.diagnostic.config({
float = {
border = 'rounded',
},
update_in_insert = true,
severity_sort = true,
})
local opts = {
capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
}
require('mason-lspconfig').setup_handlers({
function(server_name)
local setup = require('lspconfig')[server_name].setup
local ok, lsp_opts = pcall(require, 'plugin.lsp.settings.' .. server_name)
if ok then
setup(vim.tbl_deep_extend('force', opts, lsp_opts))
else
setup(opts)
end
end,
})
end,
},
{
'williamboman/mason.nvim',
cmd = 'Mason',
keys = { { '<leader>M', '<cmd>Mason<cr>', desc = 'Show Mason' } },
opts = {
ui = {
border = 'rounded',
},
},
},
{
'nvimtools/none-ls.nvim',
event = { 'BufReadPre', 'BufNewFile' },
dependencies = { 'mason.nvim' },
opts = function()
local nls = require('null-ls')
return {
-- root_dir = require("null-ls.utils").root_pattern(".null-ls-root", ".neoconf.json", "Makefile", ".git"),
border = 'rounded',
sources = {
nls.builtins.formatting.fish_indent,
nls.builtins.formatting.prettierd.with({ args = { '--prose-wrap=always', '$FILENAME' } }),
nls.builtins.formatting.stylua,
nls.builtins.diagnostics.eslint,
nls.builtins.diagnostics.fish,
},
}
end,
},
}