-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
null-ls.lua
77 lines (60 loc) · 2.42 KB
/
null-ls.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
-- null-ls is an attempt to bridge that gap and simplify the process of creating,
-- sharing, and setting up LSP sources using pure Lua.
local M = { 'jose-elias-alvarez/null-ls.nvim', deps = { 'jay-babu/mason-null-ls.nvim' } }
local config = require('one.config').config
local util = require('one.util')
M.defaultConfig = {
'nullLS',
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/CONFIG.md#options
{
debug = false,
debounce = 150,
default_timeout = 3000,
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/CONFIG.md#diagnostics_format-string
-- No #{s} and #{c} in format. because source and code are showing by vim.diagnostic.
-- See the config.lsp.diagnostic.float.format at lua/one/plugins/lsp/main.lua
diagnostics_format = '#{m}',
-- should_attach = function(bufnr)
-- return not vim.api.nvim_buf_get_name(bufnr):match('^gitsigns://')
-- end,
-- Available null-ls sources list
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md
-- How to config null-ls sources:
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTIN_CONFIG.md
sources = function(builtins)
return { builtins.completion.spell }
end,
automatic_installation = false,
},
}
local function defaultOnAttach()
local ok, lspFormat = pcall(require, 'lsp-format')
if not ok then return nil end
return function(client, bufnr)
if client.supports_method('textDocument/formatting') then
-- If null-ls client is a formatter, register the client to lsp-format.
-- So we can use lsp-format to trigger null-ls formatter when execute ":w".
lspFormat.on_attach(client, bufnr)
end
end
end
function M.config()
local nullLS = require('null-ls')
local conf = config.nullLS
local sources = conf.sources
if type(sources) == 'function' then sources = sources(nullLS.builtins) end
sources = sources or {}
if pcall(require, 'gitsigns') then table.insert(sources, nullLS.builtins.code_actions.gitsigns) end
-- print(vim.inspect(sources))
local opts = util.merge(conf, { sources = sources })
if not opts.on_attach then opts.on_attach = defaultOnAttach() end
nullLS.setup(opts)
local ok, masonNullLS = pcall(require, 'mason-null-ls')
if ok then masonNullLS.setup { automatic_installation = conf.automatic_installation } end
end
M.filetypes = {
['null-ls-info'] = function()
vim.api.nvim_win_set_config(0, { border = 'rounded', height = 30 })
end,
}
return M