Remove exisint lsp config; Start adding LSPs with new config
This commit is contained in:
parent
b963d7746e
commit
17b700c910
@ -1,5 +1,8 @@
|
|||||||
require("set")
|
require("set")
|
||||||
require("remap")
|
require("remap")
|
||||||
|
require("lsp")
|
||||||
|
|
||||||
|
-- Set up lazy
|
||||||
|
|
||||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||||
if not vim.loop.fs_stat(lazypath) then
|
if not vim.loop.fs_stat(lazypath) then
|
||||||
|
|||||||
13
nvim/.config/nvim/lsp/clangd.lua
Normal file
13
nvim/.config/nvim/lsp/clangd.lua
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
return {
|
||||||
|
cmd = {
|
||||||
|
'clangd'
|
||||||
|
},
|
||||||
|
root_markers = {
|
||||||
|
'.clangd',
|
||||||
|
'compile_commands.json'
|
||||||
|
},
|
||||||
|
filetypes = {
|
||||||
|
'c',
|
||||||
|
'cpp'
|
||||||
|
}
|
||||||
|
}
|
||||||
20
nvim/.config/nvim/lsp/luals.lua
Normal file
20
nvim/.config/nvim/lsp/luals.lua
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
return {
|
||||||
|
cmd = {
|
||||||
|
'lua-language-server'
|
||||||
|
},
|
||||||
|
filetypes = {
|
||||||
|
'lua'
|
||||||
|
},
|
||||||
|
root_markers = {
|
||||||
|
'.luarc.json',
|
||||||
|
'.luarc.jsonc',
|
||||||
|
'.git'
|
||||||
|
},
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
runtime = {
|
||||||
|
version = 'LuaJIT'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
nvim/.config/nvim/lsp/pyright.lua
Normal file
20
nvim/.config/nvim/lsp/pyright.lua
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
return {
|
||||||
|
cmd = {
|
||||||
|
'pyright-langserver', '--stdio'
|
||||||
|
},
|
||||||
|
settings = {
|
||||||
|
python = {
|
||||||
|
analysis = {
|
||||||
|
typeCheckingMode = "basic", -- or "strict", "off"
|
||||||
|
autoSearchPaths = true,
|
||||||
|
useLibraryCodeForTypes = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
root_markers = {
|
||||||
|
'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', '.git'
|
||||||
|
},
|
||||||
|
filetypes = {
|
||||||
|
'python'
|
||||||
|
},
|
||||||
|
}
|
||||||
56
nvim/.config/nvim/lua/lsp.lua
Normal file
56
nvim/.config/nvim/lua/lsp.lua
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
-- Set up LSP
|
||||||
|
|
||||||
|
local lsp_configs = {}
|
||||||
|
|
||||||
|
for _, f in pairs(vim.api.nvim_get_runtime_file('lsp/*.lua', true)) do
|
||||||
|
local server_name = vim.fn.fnamemodify(f, ':t:r')
|
||||||
|
table.insert(lsp_configs, server_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.lsp.enable(lsp_configs)
|
||||||
|
|
||||||
|
|
||||||
|
vim.o.completeopt = "menu,menuone,noinsert"
|
||||||
|
vim.api.nvim_set_keymap("i", "<C-Space>", "<C-x><C-o>", { noremap = true })
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO: Put this somewhere sensible
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
group = vim.api.nvim_create_augroup('my.lsp', {}),
|
||||||
|
callback = function(args)
|
||||||
|
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
|
||||||
|
|
||||||
|
-- Enable auto-completion. Note: Use CTRL-Y to select an item. |complete_CTRL-Y|
|
||||||
|
if client:supports_method('textDocument/completion') then
|
||||||
|
-- Trigger autocompletion on EVERY keypress. May be slow!
|
||||||
|
local chars = {}; for i = 32, 126 do table.insert(chars, string.char(i)) end
|
||||||
|
client.server_capabilities.completionProvider.triggerCharacters = chars
|
||||||
|
|
||||||
|
vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true })
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('n', '<M-L>',
|
||||||
|
function() vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) end,
|
||||||
|
{ desc = "Format" })
|
||||||
|
vim.keymap.set('i', '<M-L>',
|
||||||
|
function() vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) end,
|
||||||
|
{ desc = "Format" })
|
||||||
|
|
||||||
|
-- if client:supports_method('textDocument/implementation') then
|
||||||
|
-- -- Create a keymap for vim.lsp.buf.implementation ...
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- -- Auto-format ("lint") on save.
|
||||||
|
-- -- Usually not needed if server supports "textDocument/willSaveWaitUntil".
|
||||||
|
-- if not client:supports_method('textDocument/willSaveWaitUntil')
|
||||||
|
-- and client:supports_method('textDocument/formatting') then
|
||||||
|
-- vim.api.nvim_create_autocmd('BufWritePre', {
|
||||||
|
-- group = vim.api.nvim_create_augroup('my.lsp', { clear = false }),
|
||||||
|
-- buffer = args.buf,
|
||||||
|
-- callback = function()
|
||||||
|
-- vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 })
|
||||||
|
-- end,
|
||||||
|
-- })
|
||||||
|
-- end
|
||||||
|
end,
|
||||||
|
})
|
||||||
@ -1,193 +0,0 @@
|
|||||||
return {
|
|
||||||
{
|
|
||||||
{
|
|
||||||
'VonHeikemen/lsp-zero.nvim',
|
|
||||||
branch = 'v3.x',
|
|
||||||
lazy = true,
|
|
||||||
config = false,
|
|
||||||
init = function()
|
|
||||||
-- Disable automatic setup, we are doing it manually
|
|
||||||
vim.g.lsp_zero_extend_cmp = 0
|
|
||||||
vim.g.lsp_zero_extend_lspconfig = 0
|
|
||||||
end
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'williamboman/mason.nvim',
|
|
||||||
lazy = false,
|
|
||||||
opts = {
|
|
||||||
registries = {
|
|
||||||
"github:antsouchlos/mason-registry",
|
|
||||||
"github:mason-org/mason-registry"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Autocompletion
|
|
||||||
{
|
|
||||||
'hrsh7th/nvim-cmp',
|
|
||||||
event = 'InsertEnter',
|
|
||||||
dependencies = {
|
|
||||||
'L3MON4D3/LuaSnip',
|
|
||||||
'hrsh7th/cmp-buffer',
|
|
||||||
'hrsh7th/cmp-path',
|
|
||||||
'hrsh7th/cmp-cmdline',
|
|
||||||
'hrsh7th/cmp-nvim-lsp-signature-help',
|
|
||||||
'saadparwaiz1/cmp_luasnip'
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
local lsp_zero = require('lsp-zero')
|
|
||||||
lsp_zero.extend_cmp()
|
|
||||||
|
|
||||||
local cmp = require('cmp')
|
|
||||||
|
|
||||||
cmp.setup({
|
|
||||||
sources = {
|
|
||||||
-- LuaFormatter off
|
|
||||||
{ name = 'path' },
|
|
||||||
{ name = 'nvim_lsp' },
|
|
||||||
{ name = 'nvim_lua' },
|
|
||||||
{ name = 'luasnip', keyword_length = 2 },
|
|
||||||
{ name = 'buffer', keyword_length = 3 },
|
|
||||||
{ name = 'nvim_lsp_signature_help' }
|
|
||||||
-- LuaFormatter on
|
|
||||||
},
|
|
||||||
formatting = lsp_zero.cmp_format(),
|
|
||||||
mapping = cmp.mapping.preset.insert({
|
|
||||||
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
|
||||||
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
|
||||||
['<Tab>'] = cmp.mapping.confirm({
|
|
||||||
select = true
|
|
||||||
}),
|
|
||||||
['<C-Space>'] = cmp.mapping.complete()
|
|
||||||
}),
|
|
||||||
snippet = {
|
|
||||||
expand = function(args) require('luasnip').lsp_expand(args.body) end
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.filetype('gitcommit', {
|
|
||||||
-- LuaFormatter off
|
|
||||||
sources = cmp.config.sources(
|
|
||||||
{ { name = 'git' } },
|
|
||||||
{ { name = 'buffer' } }
|
|
||||||
)
|
|
||||||
-- LuaFormatter on
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.cmdline({
|
|
||||||
'/',
|
|
||||||
'?'
|
|
||||||
}, {
|
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
|
||||||
sources = {
|
|
||||||
{
|
|
||||||
name = 'buffer'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.cmdline(':', {
|
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
|
||||||
sources = cmp.config.sources({
|
|
||||||
{
|
|
||||||
name = 'path'
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
{
|
|
||||||
name = 'cmdline'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
end
|
|
||||||
},
|
|
||||||
|
|
||||||
-- LSP
|
|
||||||
{
|
|
||||||
'neovim/nvim-lspconfig',
|
|
||||||
cmd = {
|
|
||||||
'LspInfo',
|
|
||||||
'LspInstall',
|
|
||||||
'LspStart'
|
|
||||||
},
|
|
||||||
event = {
|
|
||||||
'BufReadPre',
|
|
||||||
'BufNewFile'
|
|
||||||
},
|
|
||||||
dependencies = {
|
|
||||||
'hrsh7th/cmp-nvim-lsp',
|
|
||||||
'williamboman/mason-lspconfig.nvim',
|
|
||||||
"folke/trouble.nvim"
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
local lsp_zero = require('lsp-zero')
|
|
||||||
lsp_zero.extend_lspconfig()
|
|
||||||
|
|
||||||
lsp_zero.on_attach(function(client, bufnr)
|
|
||||||
vim.keymap.set("n", "<leader>ld", function() vim.lsp.buf.definition() end, {
|
|
||||||
desc = "Go to definition"
|
|
||||||
})
|
|
||||||
vim.keymap.set("n", "<leader>lh", function() vim.lsp.buf.hover() end, {
|
|
||||||
desc = "Hover"
|
|
||||||
})
|
|
||||||
vim.keymap.set("n", "<leader>lr", ":Trouble lsp_references<CR>", {
|
|
||||||
desc = "Show references"
|
|
||||||
})
|
|
||||||
vim.keymap.set("n", "<leader>ln", function() vim.lsp.buf.rename() end, {
|
|
||||||
desc = "Rename"
|
|
||||||
})
|
|
||||||
vim.keymap.set("n", "<leader>ls", function() vim.lsp.buf.signature_help() end, {
|
|
||||||
desc = "Signature help"
|
|
||||||
})
|
|
||||||
vim.keymap.set("n", "<leader>la", function() vim.lsp.buf.code_action() end, {
|
|
||||||
desc = "Code actions"
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
|
|
||||||
require('mason-lspconfig').setup({
|
|
||||||
ensure_installed = {
|
|
||||||
'clangd',
|
|
||||||
'pyright',
|
|
||||||
'cmake',
|
|
||||||
'texlab'
|
|
||||||
},
|
|
||||||
handlers = {
|
|
||||||
lsp_zero.default_setup,
|
|
||||||
lua_ls = function()
|
|
||||||
local lua_opts = lsp_zero.nvim_lua_ls()
|
|
||||||
require('lspconfig').lua_ls.setup(lua_opts)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
require('lspconfig')['clangd'].setup {
|
|
||||||
cmd = {
|
|
||||||
"clangd",
|
|
||||||
"--background-index",
|
|
||||||
"--clang-tidy",
|
|
||||||
"--completion-style=bundled",
|
|
||||||
"--cross-file-rename",
|
|
||||||
"--header-insertion=iwyu",
|
|
||||||
-- Required for embedded system compilers
|
|
||||||
"--query-driver=/**/*g++",
|
|
||||||
"--offset-encoding=utf-16"
|
|
||||||
-- "-j=8",
|
|
||||||
-- "--malloc-trim",
|
|
||||||
-- "--pch-storage=memory"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- require('lspconfig').matlab_ls.setup({
|
|
||||||
-- settings = {
|
|
||||||
-- filetypes = {
|
|
||||||
-- "matlab"
|
|
||||||
-- },
|
|
||||||
-- matlab = {
|
|
||||||
-- installPath = "/opt/matlab/R2023a/"
|
|
||||||
-- }
|
|
||||||
-- },
|
|
||||||
-- single_file_support = true
|
|
||||||
-- })
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
10
nvim/.config/nvim/lua/plugins/mason.lua
Normal file
10
nvim/.config/nvim/lua/plugins/mason.lua
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
return {
|
||||||
|
'williamboman/mason.nvim',
|
||||||
|
lazy = false,
|
||||||
|
opts = {
|
||||||
|
registries = {
|
||||||
|
"github:antsouchlos/mason-registry",
|
||||||
|
"github:mason-org/mason-registry"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,124 +0,0 @@
|
|||||||
return {
|
|
||||||
{
|
|
||||||
'sbdchd/neoformat',
|
|
||||||
event = {
|
|
||||||
"BufReadPost",
|
|
||||||
"BufNewFile"
|
|
||||||
},
|
|
||||||
init = function()
|
|
||||||
----------------
|
|
||||||
-- Formatters
|
|
||||||
----------------
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
pattern = "python",
|
|
||||||
callback = function()
|
|
||||||
vim.g.neoformat_python_autopep8 = {
|
|
||||||
exe = 'autopep8',
|
|
||||||
args = {'--max-line-length', '79', '--experimental'},
|
|
||||||
-- replace = 1
|
|
||||||
}
|
|
||||||
vim.g.neoformat_enabled_python = {
|
|
||||||
'autopep8'
|
|
||||||
}
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
pattern = {
|
|
||||||
"cpp",
|
|
||||||
"c"
|
|
||||||
},
|
|
||||||
callback = function()
|
|
||||||
vim.g.neoformat_enabled_cpp = {
|
|
||||||
'clangformat'
|
|
||||||
}
|
|
||||||
vim.g.neoformat_enabled_c = {
|
|
||||||
'clangformat'
|
|
||||||
}
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
pattern = "lua",
|
|
||||||
callback = function()
|
|
||||||
vim.g.neoformat_enable_lua = {
|
|
||||||
'luaformatter'
|
|
||||||
}
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
pattern = "cmake",
|
|
||||||
callback = function()
|
|
||||||
vim.g.neoformat_enabled_cmake = {
|
|
||||||
'cmake-format'
|
|
||||||
}
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Commented out rust formatter
|
|
||||||
-- vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
-- pattern = "rust",
|
|
||||||
-- callback = function()
|
|
||||||
-- vim.g.neoformat_enabled_rust = {'rustfmt'}
|
|
||||||
-- end
|
|
||||||
-- })
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
pattern = "markdown",
|
|
||||||
callback = function()
|
|
||||||
vim.g.neoformat_markdown_mdformat = {
|
|
||||||
exe = 'mdformat',
|
|
||||||
args = {
|
|
||||||
'--wrap=79',
|
|
||||||
'--number'
|
|
||||||
},
|
|
||||||
replace = 1
|
|
||||||
}
|
|
||||||
vim.g.neoformat_enabled_markdown = {
|
|
||||||
'mdformat'
|
|
||||||
}
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
pattern = "tex",
|
|
||||||
callback = function()
|
|
||||||
vim.g.neoformat_tex_texfmt = {
|
|
||||||
exe = "tex-fmt",
|
|
||||||
args = {
|
|
||||||
"--stdin",
|
|
||||||
"--tabsize",
|
|
||||||
"4"
|
|
||||||
},
|
|
||||||
stdin = 1
|
|
||||||
}
|
|
||||||
vim.g.neoformat_enabled_tex = {
|
|
||||||
"texfmt"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
----------------
|
|
||||||
-- Other
|
|
||||||
----------------
|
|
||||||
|
|
||||||
-- vim.cmd([[
|
|
||||||
-- augroup Neoformat
|
|
||||||
-- autocmd!
|
|
||||||
-- autocmd BufWritePre * undojoin | Neoformat
|
|
||||||
-- augroup END
|
|
||||||
-- ]])
|
|
||||||
|
|
||||||
vim.api.nvim_set_keymap('n', '<M-L>', '<cmd>Neoformat<cr>', {
|
|
||||||
noremap = true,
|
|
||||||
silent = true
|
|
||||||
})
|
|
||||||
vim.api.nvim_set_keymap('i', '<M-L>', '<cmd>Neoformat<cr>', {
|
|
||||||
noremap = true,
|
|
||||||
silent = true
|
|
||||||
})
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user