added formatter and format on save!!!
This commit is contained in:
parent
a8a297d142
commit
35bab88ce9
14 changed files with 620 additions and 494 deletions
|
|
@ -1,59 +1,66 @@
|
|||
local M = {}
|
||||
|
||||
function M.on_attach(_, bufnr)
|
||||
-- we create a function that lets us more easily define mappings specific
|
||||
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||
-- we create a function that lets us more easily define mappings specific
|
||||
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||
|
||||
local nmap = function(keys, func, desc)
|
||||
if desc then
|
||||
desc = 'LSP: ' .. desc
|
||||
end
|
||||
local nmap = function(keys, func, desc)
|
||||
if desc then
|
||||
desc = "LSP: " .. desc
|
||||
end
|
||||
|
||||
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||
end
|
||||
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||
nmap("<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame")
|
||||
nmap("<leader>ca", vim.lsp.buf.code_action, "[C]ode [A]ction")
|
||||
|
||||
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
||||
nmap("gd", vim.lsp.buf.definition, "[G]oto [D]efinition")
|
||||
|
||||
-- NOTE: why are these functions that call the telescope builtin?
|
||||
-- because otherwise they would load telescope eagerly when this is defined.
|
||||
-- due to us using the on_require handler to make sure it is available.
|
||||
if nixCats('general.telescope') then
|
||||
nmap('gr', function() require('telescope.builtin').lsp_references() end, '[G]oto [R]eferences')
|
||||
nmap('gI', function() require('telescope.builtin').lsp_implementations() end, '[G]oto [I]mplementation')
|
||||
nmap('<leader>ds', function() require('telescope.builtin').lsp_document_symbols() end, '[D]ocument [S]ymbols')
|
||||
nmap('<leader>ws', function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, '[W]orkspace [S]ymbols')
|
||||
nmap('<leader>dd', "<cmd>Telescope diagnostics bufnr=0<CR>", '[D]ocument [D]iagnostics')
|
||||
nmap('<leader>wd', "<cmd>Telescope diagnostics<CR>", '[W]orkspace [D]iagnostics')
|
||||
end -- TODO: someone who knows the builtin versions of these to do instead help me out please.
|
||||
-- NOTE: why are these functions that call the telescope builtin?
|
||||
-- because otherwise they would load telescope eagerly when this is defined.
|
||||
-- due to us using the on_require handler to make sure it is available.
|
||||
if nixCats("general.telescope") then
|
||||
nmap("gr", function()
|
||||
require("telescope.builtin").lsp_references()
|
||||
end, "[G]oto [R]eferences")
|
||||
nmap("gI", function()
|
||||
require("telescope.builtin").lsp_implementations()
|
||||
end, "[G]oto [I]mplementation")
|
||||
nmap("<leader>ds", function()
|
||||
require("telescope.builtin").lsp_document_symbols()
|
||||
end, "[D]ocument [S]ymbols")
|
||||
nmap("<leader>ws", function()
|
||||
require("telescope.builtin").lsp_dynamic_workspace_symbols()
|
||||
end, "[W]orkspace [S]ymbols")
|
||||
nmap("<leader>dd", "<cmd>Telescope diagnostics bufnr=0<CR>", "[D]ocument [D]iagnostics")
|
||||
nmap("<leader>wd", "<cmd>Telescope diagnostics<CR>", "[W]orkspace [D]iagnostics")
|
||||
end -- TODO: someone who knows the builtin versions of these to do instead help me out please.
|
||||
|
||||
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||
nmap('<leader>e', vim.diagnostic.open_float, 'Show [E]rror')
|
||||
nmap("<leader>D", vim.lsp.buf.type_definition, "Type [D]efinition")
|
||||
nmap("<leader>e", vim.diagnostic.open_float, "Show [E]rror")
|
||||
|
||||
-- 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')
|
||||
-- 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')
|
||||
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||
nmap('<leader>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, '[W]orkspace [L]ist Folders')
|
||||
|
||||
-- Create a command `:Format` local to the LSP buffer
|
||||
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||
vim.lsp.buf.format()
|
||||
end, { desc = 'Format current buffer with LSP' })
|
||||
-- Lesser used LSP functionality
|
||||
nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
|
||||
nmap("<leader>wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder")
|
||||
nmap("<leader>wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder")
|
||||
nmap("<leader>wl", function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, "[W]orkspace [L]ist Folders")
|
||||
|
||||
-- Create a command `:Format` local to the LSP buffer
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
|
||||
vim.lsp.buf.format()
|
||||
end, { desc = "Format current buffer with LSP" })
|
||||
end
|
||||
|
||||
function M.get(server_name)
|
||||
local capabilities = require('blink.cmp').get_lsp_capabilities()
|
||||
local capabilities = require("blink.cmp").get_lsp_capabilities()
|
||||
|
||||
return capabilities
|
||||
return capabilities
|
||||
end
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -1,88 +1,88 @@
|
|||
return {
|
||||
{
|
||||
"friendly-snippets",
|
||||
dep_of = { "blink.cmp" },
|
||||
},
|
||||
{
|
||||
"blink.cmp",
|
||||
event = { "InsertEnter", "CmdlineEnter" },
|
||||
on_require = "blink",
|
||||
load = function (name)
|
||||
vim.cmd.packadd(name)
|
||||
end,
|
||||
after = function(plugin)
|
||||
local blink = require('blink.cmp')
|
||||
|
||||
blink.setup({
|
||||
keymap = {
|
||||
preset = 'default',
|
||||
},
|
||||
|
||||
appearance = {
|
||||
nerd_font_variant = 'mono',
|
||||
{
|
||||
"friendly-snippets",
|
||||
dep_of = { "blink.cmp" },
|
||||
},
|
||||
{
|
||||
"blink.cmp",
|
||||
event = { "InsertEnter", "CmdlineEnter" },
|
||||
on_require = "blink",
|
||||
load = function(name)
|
||||
vim.cmd.packadd(name)
|
||||
end,
|
||||
after = function(plugin)
|
||||
local blink = require("blink.cmp")
|
||||
|
||||
sources = {
|
||||
default = { 'lsp', 'path', 'snippets', 'buffer' },
|
||||
providers = {
|
||||
lsp = {
|
||||
name = 'LSP',
|
||||
module = 'blink.cmp.sources.lsp',
|
||||
enabled = true,
|
||||
},
|
||||
path = {
|
||||
name = 'Path',
|
||||
module = 'blink.cmp.sources.path',
|
||||
enabled = true,
|
||||
},
|
||||
snippets = {
|
||||
name = 'Snippets',
|
||||
module = 'blink.cmp.sources.snippets',
|
||||
enabled = true,
|
||||
},
|
||||
buffer = {
|
||||
name = 'Buffer',
|
||||
module = 'blink.cmp.sources.buffer',
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
blink.setup({
|
||||
keymap = {
|
||||
preset = "default",
|
||||
},
|
||||
|
||||
appearance = {
|
||||
nerd_font_variant = "mono",
|
||||
},
|
||||
|
||||
sources = {
|
||||
default = { "lsp", "path", "snippets", "buffer" },
|
||||
providers = {
|
||||
lsp = {
|
||||
name = "LSP",
|
||||
module = "blink.cmp.sources.lsp",
|
||||
enabled = true,
|
||||
},
|
||||
path = {
|
||||
name = "Path",
|
||||
module = "blink.cmp.sources.path",
|
||||
enabled = true,
|
||||
},
|
||||
snippets = {
|
||||
name = "Snippets",
|
||||
module = "blink.cmp.sources.snippets",
|
||||
enabled = true,
|
||||
},
|
||||
buffer = {
|
||||
name = "Buffer",
|
||||
module = "blink.cmp.sources.buffer",
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
completion = {
|
||||
accept = {
|
||||
auto_brackets = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
|
||||
menu = {
|
||||
border = "rounded",
|
||||
max_height = 12,
|
||||
scrolloff = 2,
|
||||
|
||||
draw = {
|
||||
columns = {
|
||||
{ "kind_icon", gap = 1 },
|
||||
{ "label", "label_description", gap = 1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
documentation = {
|
||||
auto_show = false,
|
||||
window = {
|
||||
border = "rounded",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
signature = {
|
||||
enabled = true,
|
||||
window = {
|
||||
border = "rounded",
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
completion = {
|
||||
accept = {
|
||||
auto_brackets = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
|
||||
menu = {
|
||||
border = 'rounded',
|
||||
max_height = 12,
|
||||
scrolloff = 2,
|
||||
|
||||
draw = {
|
||||
columns = {
|
||||
{ "kind_icon", gap = 1, },
|
||||
{ "label", "label_description", gap = 1, },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
documentation = {
|
||||
auto_show = false,
|
||||
window = {
|
||||
border = 'rounded',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
signature = {
|
||||
enabled = true,
|
||||
window = {
|
||||
border = 'rounded',
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "lua",
|
||||
callback = function()
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
pattern = "lua",
|
||||
callback = function()
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "nix",
|
||||
callback = function()
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
pattern = "nix",
|
||||
callback = function()
|
||||
vim.opt_local.shiftwidth = 2
|
||||
vim.opt_local.tabstop = 2
|
||||
vim.opt_local.expandtab = true
|
||||
end,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
require("lze").load {
|
||||
{ import = "lsp.completion", },
|
||||
}
|
||||
require("lze").load({
|
||||
{ import = "lsp.completion" },
|
||||
})
|
||||
|
||||
require("lsp.indentation")
|
||||
require("lsp.lsp")
|
||||
|
|
|
|||
|
|
@ -1,87 +1,87 @@
|
|||
local servers = {}
|
||||
|
||||
servers.lua_ls = {
|
||||
settings = {
|
||||
Lua = {
|
||||
formatters = {
|
||||
ignoreComments = false,
|
||||
},
|
||||
signatureHelp = { enable = true },
|
||||
diagnostics = {
|
||||
globals = { 'nixCats', 'vim' },
|
||||
-- disable = { 'missing-fields' },
|
||||
},
|
||||
workspace = {
|
||||
-- make the server aware of the neovim runtime files
|
||||
library = vim.api.nvim_get_runtime_file("", true),
|
||||
checkThirdParty = false,
|
||||
},
|
||||
},
|
||||
telemetry = { enabled = false },
|
||||
},
|
||||
settings = {
|
||||
Lua = {
|
||||
formatters = {
|
||||
ignoreComments = false,
|
||||
},
|
||||
signatureHelp = { enable = true },
|
||||
diagnostics = {
|
||||
globals = { "nixCats", "vim" },
|
||||
-- disable = { 'missing-fields' },
|
||||
},
|
||||
workspace = {
|
||||
-- make the server aware of the neovim runtime files
|
||||
library = vim.api.nvim_get_runtime_file("", true),
|
||||
checkThirdParty = false,
|
||||
},
|
||||
},
|
||||
telemetry = { enabled = false },
|
||||
},
|
||||
}
|
||||
|
||||
servers.nil_ls = {
|
||||
settings = {},
|
||||
settings = {},
|
||||
}
|
||||
|
||||
local rust_analyzer_cmd = os.getenv("RUST_ANALYZER_CMD")
|
||||
servers.rust_analyzer = {
|
||||
cmd = { rust_analyzer_cmd },
|
||||
settings = {
|
||||
server = {
|
||||
-- For debugging rust-analyzer, to see log location do :LspInfo in neovim
|
||||
-- extraEnv = { {["RA_LOG"]="project_model=debug"} },
|
||||
},
|
||||
cargo = {
|
||||
allFeatures = false,
|
||||
allTargets = false,
|
||||
buildScripts = { enable = true },
|
||||
target = "x86_64-unknown-linux-gnu",
|
||||
},
|
||||
diagnostics = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
cmd = { rust_analyzer_cmd },
|
||||
settings = {
|
||||
server = {
|
||||
-- For debugging rust-analyzer, to see log location do :LspInfo in neovim
|
||||
-- extraEnv = { {["RA_LOG"]="project_model=debug"} },
|
||||
},
|
||||
cargo = {
|
||||
allFeatures = false,
|
||||
allTargets = false,
|
||||
buildScripts = { enable = true },
|
||||
target = "x86_64-unknown-linux-gnu",
|
||||
},
|
||||
diagnostics = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
servers.zls = {
|
||||
settings = {},
|
||||
settings = {},
|
||||
}
|
||||
|
||||
local elixir_ls_cmd = os.getenv("ELIXIR_LS_CMD")
|
||||
servers.elixirls = {
|
||||
cmd = { elixir_ls_cmd },
|
||||
settings = {},
|
||||
cmd = { elixir_ls_cmd },
|
||||
settings = {},
|
||||
}
|
||||
|
||||
servers.gleam = {
|
||||
settings = {},
|
||||
settings = {},
|
||||
}
|
||||
|
||||
servers.hls = {
|
||||
settings = {},
|
||||
settings = {},
|
||||
}
|
||||
|
||||
local java_home = os.getenv("JAVA_HOME")
|
||||
servers.jdtls = {
|
||||
settings = {
|
||||
java = {
|
||||
contentProvider = { preferred = 'fernflower' },
|
||||
configuration = {
|
||||
runtimes = {
|
||||
{
|
||||
name = "OpenJDK 17",
|
||||
path = os.getenv("OPENJDK_17"),
|
||||
},
|
||||
{
|
||||
name = "OpenJDK 21",
|
||||
path = os.getenv("OPENJDK_21"),
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
settings = {
|
||||
java = {
|
||||
contentProvider = { preferred = "fernflower" },
|
||||
configuration = {
|
||||
runtimes = {
|
||||
{
|
||||
name = "OpenJDK 17",
|
||||
path = os.getenv("OPENJDK_17"),
|
||||
},
|
||||
{
|
||||
name = "OpenJDK 21",
|
||||
path = os.getenv("OPENJDK_21"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Taken from nixCats example:
|
||||
|
|
@ -90,41 +90,41 @@ servers.jdtls = {
|
|||
-- nvim-lspconfig, it would do the same thing.
|
||||
-- come to think of it, it might be better because then lspconfig doesnt have to be called before lsp attach?
|
||||
-- but you would still end up triggering on a FileType event anyway, so, it makes little difference.
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('nixCats-lsp-attach', { clear = true }),
|
||||
callback = function(event)
|
||||
require('lsp.capabilities').on_attach(vim.lsp.get_client_by_id(event.data.client_id), event.buf)
|
||||
end
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("nixCats-lsp-attach", { clear = true }),
|
||||
callback = function(event)
|
||||
require("lsp.capabilities").on_attach(vim.lsp.get_client_by_id(event.data.client_id), event.buf)
|
||||
end,
|
||||
})
|
||||
|
||||
require("lze").load {
|
||||
{
|
||||
"nvim-lspconfig",
|
||||
event = "FileType",
|
||||
after = function(plugin)
|
||||
-- Just register configs, don't enable yet
|
||||
for server_name, cfg in pairs(servers) do
|
||||
vim.lsp.config(server_name, {
|
||||
capabilities = require('lsp.capabilities').get(server_name),
|
||||
settings = (cfg or {}).settings,
|
||||
filetypes = (cfg or {}).filetypes,
|
||||
cmd = (cfg or {}).cmd,
|
||||
root_pattern = (cfg or {}).root_pattern,
|
||||
})
|
||||
end
|
||||
require("lze").load({
|
||||
{
|
||||
"nvim-lspconfig",
|
||||
event = "FileType",
|
||||
after = function(plugin)
|
||||
-- Just register configs, don't enable yet
|
||||
for server_name, cfg in pairs(servers) do
|
||||
vim.lsp.config(server_name, {
|
||||
capabilities = require("lsp.capabilities").get(server_name),
|
||||
settings = (cfg or {}).settings,
|
||||
filetypes = (cfg or {}).filetypes,
|
||||
cmd = (cfg or {}).cmd,
|
||||
root_pattern = (cfg or {}).root_pattern,
|
||||
})
|
||||
end
|
||||
|
||||
-- Enable on-demand per filetype
|
||||
for server_name, cfg in pairs(servers) do
|
||||
local filetypes = cfg.filetypes or vim.lsp.config[server_name].filetypes
|
||||
if filetypes then
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = filetypes,
|
||||
callback = function()
|
||||
vim.lsp.enable(server_name)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
-- Enable on-demand per filetype
|
||||
for server_name, cfg in pairs(servers) do
|
||||
local filetypes = cfg.filetypes or vim.lsp.config[server_name].filetypes
|
||||
if filetypes then
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = filetypes,
|
||||
callback = function()
|
||||
vim.lsp.enable(server_name)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue