updating nvim lsp setup, getting there

This commit is contained in:
Solomon Laing 2026-01-04 22:41:08 +10:30
parent 35dda4a37f
commit 1cefee76d8
8 changed files with 268 additions and 436 deletions

View File

@ -23,7 +23,7 @@ require("lazyvim.utils").setup()
require("lazy").setup({ require("lazy").setup({
spec = "lazyvim.plugins", spec = "lazyvim.plugins",
defaults = { lazy = true, version = false }, defaults = { lazy = false, version = false },
checker = { enabled = true }, checker = { enabled = true },
}) })

View File

@ -14,7 +14,7 @@ function M.format()
vim.lsp.buf.format() vim.lsp.buf.format()
if require("lazy.core.config").plugins["conform.nvim"]._.loaded then if require("lazy.core.config").plugins["conform.nvim"]._.loaded then
require("conform.nvim").format() require("conform").format()
else else
vim.lsp.buf.format() vim.lsp.buf.format()
end end

View File

@ -1,179 +1,36 @@
return { return {
-- lspconfig -- lspconfig
{ {
"neovim/nvim-lspconfig", "mason-org/mason-lspconfig.nvim",
enabled = true, enabled = true,
event = "BufReadPre",
dependencies = { dependencies = {
{ {
"folke/lazydev.nvim", "mason-org/mason.nvim",
ft = "lua", -- only load on lua files opts = {},
opts = {
library = {
-- See the configuration section for more details
-- Load luvit types when the `vim.uv` word is found
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
}, },
}, "neovim/nvim-lspconfig",
},
"mason.nvim",
{
"mason-org/mason-lspconfig.nvim",
version = "^1.0.0",
},
-- "hrsh7th/cmp-nvim-lsp",
}, },
opts = { opts = {
-- options for vim.diagnostic.config() automatic_enable = true,
diagnostics = { ensure_installed = {
underline = true, "lua_ls",
update_in_insert = true,
virtual_text = { spacing = 4, prefix = "" },
severity_sort = true,
},
autoformat = true,
servers = {
lua_ls = {
mason = true,
settings = {
Lua = {
workspace = {
checkThirdParty = false,
},
completion = {
callSnippet = "Replace",
},
},
},
},
ltex = {
mason = true,
settings = {
ltex = {
language = "en-AU",
},
},
},
omnisharp = {},
powershell_es = {
bundle_path = 'c:/Users/Solomon/scripts/PowerShellEditorServices',
shell = 'powershell.exe',
},
-- angularls = {
-- -- cmd = { "ngserver", "--stdio", "--tsProbeLocations", require("lazyvim.utils").get_root(), "--ngProbeLocations", require("lazyvim.utils").get_root(), },
-- -- on_new_config = function(new_config, new_root_dir)
-- -- new_config.cmd = cmd
-- -- end,
-- },
},
setup = {
-- additional setup can be added here.
omnisharp = function(_, _)
require("lazyvim.utils").on_attach(function(client, _)
if client.name == "omnisharp" then
---@type string[]
local tokenModifiers =
client.server_capabilities.semanticTokensProvider.legend.tokenModifiers
for i, v in ipairs(tokenModifiers) do
tokenModifiers[i] = v:gsub(" ", "_")
end
---@type string[]
local tokenTypes = client.server_capabilities.semanticTokensProvider.legend.tokenTypes
for i, v in ipairs(tokenTypes) do
tokenTypes[i] = v:gsub(" ", "_")
end
end
end)
return false
end,
}, },
}, },
config = function(_, opts) config = function(_, opts)
local Util = require("lazyvim.utils") require("mason-lspconfig").setup(opts)
-- setup autoformat require("lazyvim.plugins.lsp.config").setup()
require("lazyvim.plugins.lsp.format").autoformat = opts.autoformat
-- setup formatting and keymaps
Util.on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
end)
-- diagnostics
for name, icon in pairs(require("lazyvim.config.icons").diagnostics) do
name = "DiagnosticSign" .. name
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
end
if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then
opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and ""
or function(diagnostic)
local icons = require("lazyvim.config").icons.diagnostics
for d, icon in pairs(icons) do
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
return icon
end
end
end
end
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
local servers = opts.servers
local capabilities = vim.tbl_deep_extend(
"force",
{},
vim.lsp.protocol.make_client_capabilities(),
-- require("cmp_nvim_lsp").default_capabilities(),
require("blink.cmp").get_lsp_capabilities(),
opts.capabilities or {}
)
local function setup(server)
local server_opts = vim.tbl_deep_extend("force", {
capabilities = vim.deepcopy(capabilities),
}, servers[server] or {})
if opts.setup[server] then
if opts.setup[server](server, server_opts) then
return
end
elseif opts.setup["*"] then
if opts.setup["*"](server, server_opts) then
return
end
end
vim.lsp.enable(server)
vim.lsp.config(server, server_opts)
end
-- get all the servers that are available thourgh mason-lspconfig
local have_mason, mlsp = pcall(require, "mason-lspconfig")
local all_mslp_servers = {}
if have_mason then
all_mslp_servers = vim.tbl_keys(require("mason-lspconfig.mappings.server").lspconfig_to_package)
end
local ensure_installed = {} ---@type string[]
for server, server_opts in pairs(servers) do
if server_opts then
server_opts = server_opts == true and {} or server_opts
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then
setup(server)
else
ensure_installed[#ensure_installed + 1] = server
end
end
end
if have_mason then
mlsp.setup({ ensure_installed = ensure_installed })
mlsp.setup_handlers({ setup })
end
end, end,
}, },
{
"mason-org/mason.nvim",
cmd = "Mason",
keys = { { "<leader>lM", "<cmd>Mason<cr>", desc = "Mason" } },
opts = {
automatic_istallation = false,
},
},
-- formatting -- formatting
{ {
"stevearc/conform.nvim", "stevearc/conform.nvim",
@ -198,30 +55,14 @@ return {
-- cmdline tools and lsp servers -- cmdline tools and lsp servers
{ {
"williamboman/mason.nvim", "mason-org/mason.nvim",
version = "^1.0.0",
enabled = true, enabled = true,
cmd = "Mason", cmd = "Mason",
keys = { { "<leader>lM", "<cmd>Mason<cr>", desc = "Mason" } }, keys = { { "<leader>lM", "<cmd>Mason<cr>", desc = "Mason" } },
opts = { opts = {
automatic_istallation = false, automatic_istallation = false,
ensure_installed = {
"stylua",
"shellcheck",
"shfmt",
}, },
}, },
config = function(_, opts)
require("mason").setup()
local mr = require("mason-registry")
for _, tool in ipairs(opts.ensure_installed) do
local p = mr.get_package(tool)
if not p:is_installed() then
p:install()
end
end
end,
},
-- language specific tooling -- language specific tooling
{ {

View File

@ -4,7 +4,7 @@ function M.on_attach(client, buffer)
local self = M.new(client, buffer) local self = M.new(client, buffer)
self:map("<leader>ld", vim.diagnostic.open_float, { desc = "Line Diagnostics" }) self:map("<leader>ld", vim.diagnostic.open_float, { desc = "Line Diagnostics" })
self:map("<leader>lI", "LspInfo", { desc = "Lsp Info" }) self:map("<leader>lI", [[checkhealth lsp]], { desc = "Lsp Info" })
self:map("<leader>ls", "Telescope diagnostics", { desc = "Telescope Diagnostics" }) self:map("<leader>ls", "Telescope diagnostics", { desc = "Telescope Diagnostics" })
self:map("gd", "Telescope lsp_definitions", { desc = "Goto Definition" }) self:map("gd", "Telescope lsp_definitions", { desc = "Goto Definition" })
self:map("gr", "Telescope lsp_references", { desc = "References" }) self:map("gr", "Telescope lsp_references", { desc = "References" })

View File

@ -44,7 +44,7 @@ function M.disable_others_when_zk(client)
end end
end end
function M.on_attach(client, bufnr) function M.on_attach(client, _)
-- M.disable_deno_formatting(client) -- M.disable_deno_formatting(client)
-- M.resolve_tsserver_deno(client) -- M.resolve_tsserver_deno(client)
M.disable_others_when_zk(client) M.disable_others_when_zk(client)

View File

@ -2,6 +2,7 @@ return {
{ {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
enable = true, enable = true,
lazy = false,
build = ":TSUpdate", build = ":TSUpdate",
disable = function(lang, buf) disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB local max_filesize = 100 * 1024 -- 100 KB
@ -81,18 +82,4 @@ return {
require("nvim-treesitter").setup(opts) require("nvim-treesitter").setup(opts)
end, end,
}, },
{
"nvim-treesitter/nvim-treesitter-context",
name = "treesitter-context",
enabled = true,
lazy = true,
opts = {},
},
{
"nvim-treesitter/nvim-treesitter-textobjects",
enabled = true,
dependencies = {
"nvim-treesitter/nvim-treesitter"
}
},
} }

View File

@ -3,15 +3,16 @@ local M = {}
M.root_patterns = { ".git", "/lua" } M.root_patterns = { ".git", "/lua" }
function M.setup() function M.setup()
require "lazyvim.utils.term" require("lazyvim.utils.term")
end end
---@param on_attach fun(client, buffer) ---@param on_attach fun(client, buffer)
function M.on_attach(on_attach) function M.on_attach(on_attach)
vim.api.nvim_create_autocmd("LspAttach", { vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("my.lsp", {}),
callback = function(args) callback = function(args)
local buffer = args.buf local buffer = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id) local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
on_attach(client, buffer) on_attach(client, buffer)
end, end,
}) })
@ -152,7 +153,7 @@ function M.trim_whitespace()
pcall(vim.cmd, [[%s/\s\+$//e]]) pcall(vim.cmd, [[%s/\s\+$//e]])
pcall(vim.cmd, [[%s/\n\+\%$//e]]) pcall(vim.cmd, [[%s/\n\+\%$//e]])
pcall(vim.cmd, [[.[ch] %s/\%$/\r/e]]) pcall(vim.cmd, [[.[ch] %s/\%$/\r/e]])
pcall(vim.cmd, 'cal cursor(currPos[1], currPos[2])') pcall(vim.cmd, "cal cursor(currPos[1], currPos[2])")
end end
function M.exists(path) function M.exists(path)

View File

@ -33,6 +33,9 @@ setw -g pane-base-index 1
# Enable full mouse support. # Enable full mouse support.
# set -g mouse on # gross gross gross # set -g mouse on # gross gross gross
# focus events for neovim
set-option -g focus-events on
# vi mode for movement and copy/paste # vi mode for movement and copy/paste
set-window-option -g mode-keys vi set-window-option -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection bind -T copy-mode-vi v send-keys -X begin-selection