chore: move rust stuff to lsp
This commit is contained in:
parent
b177e9a731
commit
0050526934
@ -1,53 +0,0 @@
|
||||
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 has_formatter(ft)
|
||||
local sources = require 'null-ls.sources'
|
||||
local available = sources.get_available(ft, 'NULL_LS_FORMATTING')
|
||||
return #available > 0
|
||||
end
|
||||
|
||||
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 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,
|
||||
standalone = false,
|
||||
},
|
||||
}
|
@ -104,6 +104,15 @@ function M.config()
|
||||
-- vim.cmd "command! -buffer JdtJshell lua require('jdtls').jshell()"
|
||||
goto continue
|
||||
end
|
||||
if server == 'rust_analyzer' then
|
||||
require('rust-tools').setup {
|
||||
server = {
|
||||
on_attach = on_attach,
|
||||
standalone = false,
|
||||
},
|
||||
}
|
||||
goto continue
|
||||
end
|
||||
lspconfig[server].setup(opts)
|
||||
::continue::
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user