Add completion basic settings
This commit is contained in:
parent
ee4f78902b
commit
f9c4d63afb
3 changed files with 229 additions and 0 deletions
193
lua/custom/lsp.lua
Normal file
193
lua/custom/lsp.lua
Normal file
|
@ -0,0 +1,193 @@
|
|||
local lspconfig = require("lspconfig")
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
local keymap = vim.keymap
|
||||
|
||||
local capabilities = nil
|
||||
if pcall(require, "cmp_nvim_lsp") then
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
end
|
||||
|
||||
|
||||
local servers = {
|
||||
gopls = {
|
||||
settings = {
|
||||
gopls = {
|
||||
hints = {
|
||||
assignVariableTypes = true,
|
||||
compositeLiteralFields = true,
|
||||
compositeLiteralTypes = true,
|
||||
constantValues = true,
|
||||
functionTypeParameters = true,
|
||||
parameterNames = true,
|
||||
rangeVariableTypes = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ruff = {
|
||||
init_options = {
|
||||
settings = {
|
||||
-- Ruff language server settings go here
|
||||
logLevel = "debug",
|
||||
},
|
||||
},
|
||||
},
|
||||
pyright = {
|
||||
settings = {
|
||||
pyright = {
|
||||
-- Using Ruff's import organizer
|
||||
disableOrganizeImports = true,
|
||||
},
|
||||
python = {
|
||||
analysis = {
|
||||
-- Ignore all files for analysis to exclusively use Ruff for linting
|
||||
ignore = { "*" },
|
||||
diagnosticMode = "off",
|
||||
typeCheckingMode = "off",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
lua_ls = {
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
-- make the language server recognize "vim" global
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
clangd = {
|
||||
filetypes = { "c" },
|
||||
cmd = {
|
||||
"clangd",
|
||||
"--offset-encoding=utf-16",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local servers_to_install = vim.tbl_filter(function(key)
|
||||
local t = servers[key]
|
||||
if type(t) == "table" then
|
||||
return not t.manual_install
|
||||
else
|
||||
return t
|
||||
end
|
||||
end, vim.tbl_keys(servers))
|
||||
|
||||
|
||||
|
||||
require("mason").setup()
|
||||
local ensure_installed = {
|
||||
"stylua",
|
||||
"lua_ls",
|
||||
"ruff",
|
||||
"gopls",
|
||||
"gofumpt",
|
||||
"golines",
|
||||
"prettier",
|
||||
"pyright"
|
||||
}
|
||||
|
||||
vim.list_extend(ensure_installed, servers_to_install)
|
||||
require("mason-tool-installer").setup { ensure_installed = ensure_installed }
|
||||
|
||||
for name, config in pairs(servers) do
|
||||
if config == true then
|
||||
config = {}
|
||||
end
|
||||
config = vim.tbl_deep_extend("force", {}, {
|
||||
capabilities = capabilities,
|
||||
}, config)
|
||||
|
||||
lspconfig[name].setup(config)
|
||||
end
|
||||
|
||||
for name, config in pairs(servers) do
|
||||
if config == true then
|
||||
config = {}
|
||||
end
|
||||
config = vim.tbl_deep_extend("force", {}, {
|
||||
capabilities = capabilities,
|
||||
}, config)
|
||||
|
||||
lspconfig[name].setup(config)
|
||||
end
|
||||
|
||||
-- Here it is used the LSP server attaches to file
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
-- Grouping together autocommands.
|
||||
-- Here we creating new group and calling it "UserLspConfig"
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
-- callback defining logic to execute on the event
|
||||
callback = function(ev)
|
||||
-- Buffer local mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local opts = { buffer = ev.buf, silent = true }
|
||||
|
||||
-- set keybinds
|
||||
-- show definition, references
|
||||
opts.desc = "Show LSP references"
|
||||
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
|
||||
|
||||
-- go to declaration
|
||||
opts.desc = "Go to declaration"
|
||||
keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||
|
||||
-- show lsp definitions
|
||||
opts.desc = "Show LSP definitions"
|
||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||
|
||||
-- show lsp implementations
|
||||
opts.desc = "Show LSP implementations"
|
||||
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||
|
||||
-- show lsp type definitions
|
||||
opts.desc = "Show LSP type definitions"
|
||||
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
||||
|
||||
-- see available code actions, in visual mode will apply to selection
|
||||
opts.desc = "See available code actions"
|
||||
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
|
||||
-- smart rename
|
||||
opts.desc = "Smart rename"
|
||||
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||
|
||||
-- show diagnostics for file
|
||||
opts.desc = "Show buffer diagnostics"
|
||||
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts)
|
||||
|
||||
-- show diagnostics for line
|
||||
opts.desc = "Show line diagnostics"
|
||||
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
|
||||
|
||||
-- jump to previous diagnostic in buffer
|
||||
opts.desc = "Go to previous diagnostic"
|
||||
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
||||
|
||||
-- jump to next diagnostic in buffer
|
||||
opts.desc = "Go to next diagnostic"
|
||||
keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
||||
|
||||
-- show documentation for what is under cursor
|
||||
opts.desc = "Show documentation for what is under cursor"
|
||||
keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
|
||||
-- mapping to restart lsp if necessary
|
||||
opts.desc = "Restart LSP"
|
||||
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
|
||||
|
||||
opts.desc = "Run formatting on current buffer"
|
||||
keymap.set("n", "<space>f", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, opts)
|
||||
end,
|
||||
})
|
|
@ -12,6 +12,7 @@ return {
|
|||
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
||||
"rafamadriz/friendly-snippets", -- useful snippets
|
||||
"onsails/lspkind.nvim", -- vs-code like pictograms
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
config = function()
|
||||
require "custom/completion"
|
||||
|
|
35
lua/custom/plugins/lsp.lua
Normal file
35
lua/custom/plugins/lsp.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
return {
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
{
|
||||
--`lazydev` configures Lua LSP for your Neovim config, runtime and plugins
|
||||
-- used for completion, annotations and signatures of Neovim apis
|
||||
"folke/lazydev.nvim",
|
||||
ft = "lua",
|
||||
opts = {
|
||||
library = {
|
||||
-- Load luvit types when the `vim.uv` word is found
|
||||
{ path = "luvit-meta/library", words = { "vim%.uv" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
{ "Bilal2453/luvit-meta", lazy = true },
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||
|
||||
-- Some enhancements for notifications in bottom-right corner
|
||||
{ "j-hui/fidget.nvim", opts = {} },
|
||||
|
||||
-- Following plugin enables enhancements for diagnostics info
|
||||
-- { "https://git.sr.ht/~whynothugo/lsp_lines.nvim" },
|
||||
|
||||
-- Autoformatting
|
||||
"stevearc/conform.nvim",
|
||||
},
|
||||
config = function()
|
||||
require "custom/lsp"
|
||||
end,
|
||||
},
|
||||
}
|
Loading…
Reference in a new issue