-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.lua
126 lines (116 loc) · 3.19 KB
/
config.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
local function setup_diagnostic(active)
local config = {
virtual_text = false,
signs = { active = active },
update_in_insert = true,
underline = false,
severity_sort = true,
float = {
focusable = false,
style = "minimal",
border = "rounded",
source = "always",
header = "",
prefix = "",
},
}
vim.diagnostic.config(config)
if IS_LEET_CODE then
vim.diagnostic.disable()
end
end
local function init()
local signs = {
DiagnosticSignError = { text = " ", texthl = "DiagnosticSignError" },
DiagnosticSignWarn = { text = " ", texthl = "DiagnosticSignWarn" },
DiagnosticSignHint = { text = " ", texthl = "DiagnosticSignHint" },
DiagnosticSignInfo = { text = " ", texthl = "DiagnosticSignInfo" },
}
DEFINE_SIGNS(signs)
local active = {}
for name, value in pairs(signs) do
table.insert(active, { name = name, text = value.text })
end
setup_diagnostic(active)
local opt = {
border = "rounded",
width = LSP_DOC_WIDTH,
max_width = GET_MAX_WIDTH(),
silent = true,
}
local hd = vim.lsp.handlers
hd["textDocument/hover"] = vim.lsp.with(hd.hover, opt)
hd["textDocument/signatureHelp"] = vim.lsp.with(hd.signature_help, opt)
end
local function on_attach(client)
if client.name == "tsserver" then
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
end
end
local function get_options(cmp_nvim_lsp, server)
local opts = {
on_attach = on_attach,
capabilities = cmp_nvim_lsp.default_capabilities(),
}
local has_custom_opts, server_custom_opts =
pcall(require, "plugins.lsp.settings." .. server)
if has_custom_opts then
if server_custom_opts.disabled then
return nil
end
opts = MERGE_TABLE(opts, server_custom_opts)
end
return opts
end
local function try_load(conf, exclude_filetypes, include_filetypes)
local try_add = conf.manager.try_add
conf.manager.try_add = function(config)
local disabled = TABLE_CONTAINS(exclude_filetypes, vim.bo.filetype)
if disabled then
return
end
if include_filetypes ~= nil then
local enabled = TABLE_CONTAINS(include_filetypes, vim.bo.filetype)
if not enabled then
return
end
end
return try_add(config)
end
end
local function load_neodev(server)
if not IS_MAC or server ~= "lua_ls" then
return
end
if IS_LEET_CODE then
return
end
require("neodev").setup()
end
return {
"neovim/nvim-lspconfig",
cond = not IS_VSCODE,
event = { "BufReadPre", "BufNewFile" },
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"b0o/schemastore.nvim",
},
config = function()
require("lspconfig.ui.windows").default_options.border = "rounded"
local lspconfig = require("lspconfig")
local cmp_nvim_lsp = require("cmp_nvim_lsp")
for _, server in pairs(LSP_SERVERS) do
local conf = lspconfig[server]
local opts = get_options(cmp_nvim_lsp, server)
if not opts then
goto continue
end
load_neodev(server)
conf.setup(opts)
try_load(conf, opts.exclude_filetypes or {}, opts.include_filetypes)
::continue::
end
init()
end,
}