LSP finally working a decent amount

This commit is contained in:
RingOfStorms (Joshua Bell) 2023-06-30 17:53:02 -05:00
parent 518951ec2f
commit 9c884fb841
15 changed files with 489 additions and 112 deletions

10
lua/plugins/comments.lua Normal file
View file

@ -0,0 +1,10 @@
vim.g.NERDCreateDefaultMappings = 0
vim.cmd('filetype plugin on')
return {
"preservim/nerdcommenter",
keys = {
{ "<leader>/", ':call nerdcommenter#Comment(0, "toggle")<CR>', desc = "Toggle comments on selection" },
{ "<leader>/", ':call nerdcommenter#Comment(0, "toggle")<CR>', desc = "Toggle comments on selection", mode = "v" },
},
}

View file

@ -0,0 +1,30 @@
vim.cmd([[highlight IndentBlanklineIndent1 guifg=#E06C75 gui=nocombine]])
vim.cmd([[highlight IndentBlanklineIndent2 guifg=#E5C07B gui=nocombine]])
vim.cmd([[highlight IndentBlanklineIndent3 guifg=#98C379 gui=nocombine]])
vim.cmd([[highlight IndentBlanklineIndent4 guifg=#61AFEF gui=nocombine]])
vim.cmd([[highlight IndentBlanklineIndent5 guifg=#C678DD gui=nocombine]])
vim.opt.list = true
-- vim.opt.listchars:append "space:⋅"
vim.opt.listchars:append("eol:↴")
return {
-- Add indentation guides even on blank lines
"lukas-reineke/indent-blankline.nvim",
-- Enable `lukas-reineke/indent-blankline.nvim`
-- See `:help indent_blankline.txt`
opts = {
-- space_char_blankline = " ",
-- char = '┊',
-- show_trailing_blankline_indent = false,
-- show_current_context = false,
show_current_context_start = true,
char_highlight_list = {
"IndentBlanklineIndent1",
"IndentBlanklineIndent2",
"IndentBlanklineIndent3",
"IndentBlanklineIndent4",
"IndentBlanklineIndent5",
},
},
}

206
lua/plugins/lsp.lua Normal file
View file

@ -0,0 +1,206 @@
local servers = {
rust_analyzer = {
-- rust
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
cargo = {
allFeatures = true,
},
checkOnSave = {
allFeatures = true,
command = "clippy",
},
},
},
tsserver = {
-- typescript/javascript
},
pyright = {
-- python
},
lua_ls = {
-- lua
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
bashls = {
-- bash
},
cssls = {
-- css
},
cssmodules_ls = {
-- css modules
},
dockerls = {
-- docker
},
docker_compose_language_service = {
-- docker compose
},
jsonls = {
-- json
},
marksman = {
-- markdown
},
taplo = {
-- toml
},
yamlls = {
-- yaml
},
lemminx = {
-- xml
},
rnix = {
-- Nix
},
ansiblels = {
-- ansible
},
}
-- LSP config
-- Took lots of inspiration from this kickstart lua file: https://github.com/hjr3/dotfiles/blob/main/.config/nvim/init.lua
return {
{
-- Autocompletion
"hrsh7th/nvim-cmp",
dependencies = { "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip" },
},
{
"williamboman/mason.nvim",
cmd = {
"Mason",
"MasonUpdate",
"MasonInstall",
"MasonInstallAll",
"MasonUninstall",
"MasonUninstallAll",
"MasonLog",
},
build = ":MasonUpdate",
opts = {},
},
{
"williamboman/mason-lspconfig.nvim",
},
{ "folke/neodev.nvim", opts = {} },
{
"neovim/nvim-lspconfig",
after = { "nvim-telescope/telescope.nvim" },
config = function()
local config = require("lspconfig")
local util = require("lspconfig/util")
local mason_lspconfig = require("mason-lspconfig")
local cmp = require("cmp")
local luasnip = require("luasnip")
-- LSP
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(client, bufnr)
local nmap = function(keys, func, desc)
if desc then
desc = "LSP: " .. desc
end
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc })
end
nmap("<leader>lr", vim.lsp.buf.rename, "[R]ename")
nmap("<leader>la", vim.lsp.buf.code_action, "Code [A]ction")
nmap("gd", vim.lsp.buf.definition, "[G]oto [D]efinition")
nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
nmap("gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation")
nmap("<leader>D", vim.lsp.buf.type_definition, "Type [D]efinition")
-- See `:help K` for why this keymap
nmap("K", vim.lsp.buf.hover, "Hover Documentation")
nmap("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation")
-- Lesser used LSP functionality
nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
-- disable tsserver so it does not conflict with prettier
if client.name == "tsserver" then
client.server_capabilities.document_formatting = false
end
end
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
-- Install servers used
mason_lspconfig.setup({
ensure_installed = vim.tbl_keys(servers),
})
local flags = {
allow_incremental_sync = true,
debounce_text_changes = 200,
}
mason_lspconfig.setup_handlers({
function(server_name)
require("lspconfig")[server_name].setup({
flags = flags,
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name],
})
end,
})
-- Completion
luasnip.config.setup({})
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete({}),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
},
})
end,
},
}

View file

@ -1,25 +1,21 @@
local test = function ()
return "test 123"
end
return {
"nvim-lualine/lualine.nvim",
dependencies = {
"RingOfStorms/lualine-lsp-progress",
},
opts = {
options = {
theme = "codedark",
section_separators = { left = '', right = '' },
component_separators = '|',
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename', "lsp_progress", test},
lualine_x = {'encoding', 'filetype', 'filesize'},
lualine_y = {'searchcount', 'selectioncount'},
lualine_z = {'location'},
},
},
"nvim-lualine/lualine.nvim",
--dependencies = {
-- "RingOfStorms/lualine-lsp-progress",
--},
opts = {
options = {
theme = "codedark",
section_separators = { left = "", right = "" },
component_separators = "|",
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename" },
lualine_x = { "encoding", "filetype", "filesize" },
lualine_y = { "searchcount", "selectioncount" },
lualine_z = { "location" },
},
},
}

View file

@ -1,55 +1,60 @@
-- npm install -g cspell@latest
local output = vim.fn.system {
"which",
"cspell",
}
local output = vim.fn.system({
"which",
"cspell",
})
if output == nil or output == "" then
-- if v:shell_error != 0 then
vim.fn.system {
"npm",
"install",
"-g",
"cspell@latest",
}
-- if v:shell_error != 0 then
vim.fn.system({
"npm",
"install",
"-g",
"cspell@latest",
})
end
return {
"jose-elias-alvarez/null-ls.nvim",
dependencies = "williamboman/mason.nvim",
opts = function(_, config)
require('util').ensure_installed_mason({
"stylua",
"prettier",
"rustfmt",
})
{
"jose-elias-alvarez/null-ls.nvim",
after = { "williamboman/mason.nvim" },
opts = function(_, config)
-- config variable is the default definitions table for the setup function call
local null_ls = require "null-ls"
-- config variable is the default definitions table for the setup function call
local null_ls = require("null-ls")
-- Check supported formatters and linters
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
config.sources = {
-- Set a formatter
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.rustfmt,
-- null_ls.builtins.formatting.python,
-- null_ls.builtins.code_actions.proselint, -- TODO looks interesting
null_ls.builtins.code_actions.cspell.with {
config = {
find_json = function() return vim.fn.findfile("cspell.json", vim.fn.environ().HOME .. "/.config/nvim/lua/user/;") end,
},
},
null_ls.builtins.diagnostics.cspell.with {
extra_args = { "--config", "~/.config/nvim/lua/user/cspell.json" },
},
-- Check supported formatters and linters
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
config.sources = {
-- Set a formatter
null_ls.builtins.formatting.prettier, -- typescript/javascript
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.rustfmt,
null_ls.builtins.formatting.black, -- python
-- null_ls.builtins.code_actions.proselint, -- TODO looks interesting
null_ls.builtins.code_actions.cspell.with({
config = {
find_json = function()
return vim.fn.findfile("cspell.json", vim.fn.environ().HOME .. "/.config/nvim/lua/user/;")
end,
},
}),
null_ls.builtins.diagnostics.cspell.with({
extra_args = { "--config", "~/.config/nvim/lua/user/cspell.json" },
}),
}
config.update_in_insert = true
config.debug = true
return config
end,
},
{
"jay-babu/mason-null-ls.nvim",
opts = {
ensure_installed = { "rustfmt", "stylelua", "prettier", "black" }
}
config.update_in_insert = true
config.debug = true
return config
end,
}
}

View file

@ -0,0 +1,5 @@
return {
"simrat39/rust-tools.nvim",
event = "BufEnter *.rs",
after = { "mason-lspconfig.nvim", "inlay-hints." },
}