1
0
Fork 0

Improved null-ls integration

This commit is contained in:
Daniel Kempkens 2021-12-18 23:55:56 +01:00
parent 8ce9e36a82
commit 86d90510f9
4 changed files with 51 additions and 41 deletions

View file

@ -1,37 +1,18 @@
local lsp = require('lspconfig')
local lsp_status = require('lsp-status')
local illuminate = require('illuminate')
local keymap = require('nifoc.keymap')
local function enable_lsp_fixer(_)
vim.cmd [[
augroup nifoc_lsp_formatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync(nil, 1000)
augroup end
]]
end
local diagnostic_utils = require('nifoc.utils.diagnostic')
local function custom_attach(client, bufnr)
-- Plugin attachments
lsp_status.on_attach(client)
keymap.lsp_attach(client, bufnr)
if client.resolved_capabilities.document_highlight then
illuminate.on_attach(client)
end
if vim.b.nifoc_lsp_enabled == nil then
vim.api.nvim_buf_set_var(bufnr, 'nifoc_lsp_enabled', 1)
vim.cmd("setlocal omnifunc=v:lua.vim.lsp.omnifunc")
end
if client.resolved_capabilities.document_formatting and vim.b.nifoc_fixer_enabled == nil then
vim.api.nvim_buf_set_var(bufnr, 'nifoc_fixer_enabled', 1)
enable_lsp_fixer(client)
end
diagnostic_utils.maybe_enable_lsp(client, bufnr)
diagnostic_utils.maybe_enable_fixer(client, bufnr)
vim.api.nvim_command('doautocmd <nomodeline> User NifocLspAttached')
end
@ -42,22 +23,19 @@ end
-- Setup
vim.cmd('sign define LspDiagnosticsSignError text= texthl=LspDiagnosticsSignError linehl= numhl=')
vim.cmd('sign define LspDiagnosticsSignWarning text= texthl=LspDiagnosticsSignWarning linehl= numhl=')
vim.cmd('sign define LspDiagnosticsSignInformation text= texthl=LspDiagnosticsSignInformation linehl= numhl=')
vim.cmd('sign define LspDiagnosticsSignHint text= texthl=LspDiagnosticsSignHint linehl= numhl=')
vim.cmd('sign define DiagnosticSignError text= texthl=DiagnosticSignError linehl= numhl=')
vim.cmd('sign define DiagnosticSignWarn text= texthl=DiagnosticSignWarn linehl= numhl=')
vim.cmd('sign define DiagnosticSignInfo text= texthl=DiagnosticSignInfo linehl= numhl=')
vim.cmd('sign define DiagnosticSignHint text= texthl=DiagnosticSignHint linehl= numhl=')
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
underline = true,
virtual_text = {
prefix = '',
spacing = 4,
},
signs = false,
update_in_insert = false,
}
)
vim.diagnostic.config({
underline = true,
virtual_text = {
source = 'if_many',
},
signs = false,
update_in_insert = false,
})
lsp_status.register_progress()

View file

@ -1,5 +1,6 @@
local null_ls = require('null-ls')
local builtins = null_ls.builtins
local diagnostic_utils = require('nifoc.utils.diagnostic')
null_ls.setup({
sources = {
@ -9,4 +10,9 @@ null_ls.setup({
builtins.diagnostics.shellcheck.with({extra_args = { '-f', 'gcc', '-x' }}),
builtins.formatting.shfmt.with({extra_args = { '-i', '2' }}),
},
on_attach = function(client, bufnr)
diagnostic_utils.maybe_enable_lsp(client, bufnr)
diagnostic_utils.maybe_enable_fixer(client, bufnr)
end,
})

View file

@ -154,11 +154,11 @@ function M.lsp_attach(client, bufnr)
d = {
name = "diagnostics",
d = {
"<cmd>LspTroubleToggle lsp_document_diagnostics<CR>",
"<cmd>TroubleToggle document_diagnostics<CR>",
"Document Diagnostics"
},
w = {
"<cmd>LspTroubleToggle lsp_workspace_diagnostics<CR>",
"<cmd>TroubleToggle workspace_diagnostics<CR>",
"Workspace Diagnostics"
},
},
@ -172,11 +172,11 @@ function M.lsp_attach(client, bufnr)
f = {
name = "find",
r = {
"<cmd>LspTroubleToggle lsp_references<CR>",
"<cmd>TroubleToggle lsp_references<CR>",
"References"
},
d = {
"<cmd>LspTroubleToggle lsp_definitions<CR>",
"<cmd>TroubleToggle lsp_definitions<CR>",
"Definitions"
},
},

View file

@ -0,0 +1,26 @@
local M = {}
local keymap = require('nifoc.keymap')
function M.maybe_enable_lsp(client, bufnr)
if vim.b.nifoc_lsp_enabled == nil then
vim.api.nvim_buf_set_var(bufnr, 'nifoc_lsp_enabled', 1)
keymap.lsp_attach(client, bufnr)
end
end
function M.maybe_enable_fixer(client, bufnr)
if client.resolved_capabilities.document_formatting and vim.b.nifoc_fixer_enabled == nil then
vim.api.nvim_buf_set_var(bufnr, 'nifoc_fixer_enabled', 1)
vim.cmd [[
augroup nifoc_diagnostic_formatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync(nil, 1000)
augroup end
]]
end
end
return M