fix issues that may prevent lsp.buf.format to perform

nix-components
pegasust 2022-09-19 12:52:25 -07:00
parent 51105a3e83
commit e3c4414769
1 changed files with 21 additions and 14 deletions

View File

@ -316,7 +316,7 @@ harpoon_nav('0', 10)
-- LSP settings
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr)
local on_attach = function(_client, bufnr)
-- NOTE: Remember that lua is a real programming language, and as such it is possible
-- to define small helper and utility functions so you don't have to repeat yourself
-- many times.
@ -328,11 +328,13 @@ local on_attach = function(_, bufnr)
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
vim.keymap.set('n', keys, func, { noremap = true, buffer = bufnr, desc = desc })
end
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
nmap('<leader>df', function() vim.lsp.buf.format({ async = true }) end, '[D]ocument [F]ormat')
-- symbols and gotos
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
@ -348,20 +350,18 @@ local on_attach = function(_, bufnr)
-- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
nmap('<leader>ja', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>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', vim.lsp.buf.format or vim.lsp.buf.formatting,
{ desc = 'Format current buffer with LSP' })
end
-- nvim-cmp supports additional completion capabilities
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- default language servers
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', 'cmake', 'tailwindcss', 'prismals', 'rnix', 'eslint' }
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', 'cmake', 'tailwindcss', 'prismals',
'rnix', 'eslint' }
require("mason").setup({
ui = {
icons = {
@ -399,7 +399,14 @@ require('mason-lspconfig').setup_handlers({
workspace = {
library = vim.api.nvim_get_runtime_file('', true)
},
telemetry = { enable = false }
telemetry = { enable = false },
format = {
enable = true,
defaultConfig = {
indent_style = "space",
indent_size = 2,
}
}
}
}
}