fix: move rust-tools to ftplugins, fixes filetype breaking
This commit is contained in:
parent
7d0233b9b2
commit
689b4b3e3f
46
ftplugin/rust.lua
Normal file
46
ftplugin/rust.lua
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
local cmp_nvim_lsp = require 'cmp_nvim_lsp'
|
||||||
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||||
|
capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
|
||||||
|
|
||||||
|
local function lsp_keymaps(bufnr)
|
||||||
|
local opt = { noremap = true, silent = true }
|
||||||
|
local keymap = vim.api.nvim_buf_set_keymap
|
||||||
|
keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', 'gI', '<cmd>lua vim.lsp.buf.implementation()<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', 'gr', '<cmd>TroubleToggle lsp_references<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', 'gl', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>lf', '<cmd>lua vim.lsp.buf.format { async = true }<cr>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>li', '<cmd>LspInfo<cr>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>lI', '<cmd>LspInstallInfo<cr>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>la', '<cmd>lua vim.lsp.buf.code_action()<cr>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>lj', '<cmd>lua vim.diagnostic.goto_next({buffer=0})<cr>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>lk', '<cmd>lua vim.diagnostic.goto_prev({buffer=0})<cr>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>lr', '<cmd>lua vim.lsp.buf.rename()<cr>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>ls', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>lq', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
|
||||||
|
keymap(bufnr, 'n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
|
||||||
|
end
|
||||||
|
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
|
--[[ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') ]]
|
||||||
|
lsp_keymaps(bufnr)
|
||||||
|
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
|
||||||
|
local nls = require 'plugins.null-ls'
|
||||||
|
|
||||||
|
local enable = false
|
||||||
|
if nls.has_formatter(ft) then
|
||||||
|
enable = client.name == 'null-ls'
|
||||||
|
else
|
||||||
|
enable = not (client.name == 'null-ls')
|
||||||
|
end
|
||||||
|
|
||||||
|
client.server_capabilities.documentFormattingProvider = enable
|
||||||
|
end
|
||||||
|
require('rust-tools').setup {
|
||||||
|
server = {
|
||||||
|
on_attach = on_attach,
|
||||||
|
},
|
||||||
|
}
|
@ -121,13 +121,6 @@ function M.config()
|
|||||||
require('lspconfig')[server].setup(opts)
|
require('lspconfig')[server].setup(opts)
|
||||||
::continue::
|
::continue::
|
||||||
end,
|
end,
|
||||||
['rust_analyzer'] = function()
|
|
||||||
require('rust-tools').setup {
|
|
||||||
server = {
|
|
||||||
on_attach = on_attach,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
|
Loading…
Reference in New Issue
Block a user