Change to blink over cmp, improve mason so that we don't need configs

for each language server. We only override the set keys in the custom
    lsp config if it exists, otherwise we rely on the default one from
    lspconfig.
This commit is contained in:
Martin Larsson 2024-10-20 03:40:10 +02:00
parent b195a9e22a
commit 1e18e2d419
8 changed files with 49 additions and 145 deletions

View file

@ -1,44 +0,0 @@
local utils = require("lspconfig.util")
return {
default_config = {
cmd = { "bash-language-server", "start" },
settings = {
bashIde = {
-- Glob pattern for finding and parsing shell script files in the workspace.
-- Used by the background analysis features across files.
-- Prevent recursive scanning which will cause issues when opening a file
-- directly in the home directory (e.g. ~/foo.sh).
--
-- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)".
globPattern = vim.env.GLOB_PATTERN or "**/*@(.sh|.inc|.bash|.command|.zsh|zshrc|zsh_*)",
},
bash = {
format = {
enable = true,
shell = "shfmt",
args = {
"-i",
"4",
"-bn",
"-ci"
}
},
ignorePatterns = {
"node_modules",
".git"
},
lint = {
enable = true
},
trace = {
server = "verbose"
},
},
},
filetypes = { "sh", "zsh" },
root_dir = utils.find_git_ancestor,
single_file_support = true,
},
}

View file

@ -78,7 +78,7 @@ local default_capabilities = {
editsNearCursor = true,
},
},
offsetEncoding = { "utf-8", "utf-16" },
offsetEncoding = { "utf-16" },
}
return {
@ -101,8 +101,8 @@ return {
return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname)
end,
single_file_support = true,
capabilities = default_capabilities,
},
capabilities = default_capabilities,
docs = {
description = [[
https://clangd.llvm.org/installation.html

View file

@ -1,3 +0,0 @@
return {
}

View file

@ -1,30 +0,0 @@
return {
on_init = function(client)
local path = client.workspace_folders[1].name
if not vim.loop.fs_stat(path .. "/.luarc.json") and not vim.loop.fs_stat(path .. "/.luarc.jsonc") then
client.config.settings = vim.tbl_deep_extend("force", client.config.settings, {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
},
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
},
},
})
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
end
return true
end
}

View file

@ -1 +0,0 @@
return {}

View file

@ -0,0 +1,33 @@
return {
"saghen/blink.cmp",
lazy = false, -- lazy loading handled internally
-- use a release tag to download pre-built binaries
version = "v0.*",
-- OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
-- build = 'cargo build --release',
-- On musl libc based systems you need to add this flag
-- build = 'RUSTFLAGS="-C target-feature=-crt-static" cargo build --release',
-- If you use nix, you can build from source using latest nightly rust with:
-- build = 'nix run .#build-plugin',
---@module "blink.cmp"
---@type blink.cmp.Config
opts = {
highlight = {
-- sets the fallback highlight groups to nvim-cmp's highlight groups
-- useful for when your theme doesn't support blink.cmp
-- will be removed in a future release, assuming themes add support
use_nvim_cmp_as_default = true,
},
-- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- adjusts spacing to ensure icons are aligned
nerd_font_variant = "mono",
-- experimental auto-brackets support
-- accept = { auto_brackets = { enabled = true } }
-- experimental signature help support
-- trigger = { signature_help = { enabled = true } }
}
}

View file

@ -1,61 +0,0 @@
return {
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
},
event = "InsertEnter",
config = function()
local cmp = require("cmp")
cmp.setup({
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources(
{
{
name = "nvim_lsp",
entry_filter = function(entry)
return cmp.lsp.CompletionItemKind.Snippet ~= entry:get_kind()
end,
},
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources(
{
{ name = "git" }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
},
{
{ name = "buffer" },
})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ "/", "?" }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" }
}, {
{ name = "cmdline" }
}),
matching = { disallow_symbol_nonprefix_matching = false }
})
end,
}

View file

@ -1,15 +1,25 @@
local utils = require("utils")
local function get_lsp_conf(default_conf, server_name)
local result, custom_conf = pcall(require, "language_servers/" .. server_name)
if not result or not custom_conf then
return default_conf
end
return custom_conf
end
local function setup_lsp(server_names)
local capabilities = require("cmp_nvim_lsp").default_capabilities()
capabilities.offsetEncoding = { "utf-16" }
local lspconfig = require("lspconfig")
for _, server_name in ipairs(server_names) do
local server = lspconfig[server_name]
if server then
local server_conf = require("language_servers/" .. server_name)
capabilities.textDocument.completion.completionItem.snippetSupport = false
local server_conf = get_lsp_conf(server, server_name)
local capabilities = server_conf.capabilities or {}
server_conf.capabilities = capabilities
capabilities.offsetEncoding = { "utf-16" }
server_conf.on_attach = function(client, bufnr)
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })