updating nvim lsp setup, getting there
This commit is contained in:
parent
35dda4a37f
commit
1cefee76d8
@ -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 },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -3,35 +3,35 @@ local M = {}
|
|||||||
M.autoformat = true
|
M.autoformat = true
|
||||||
|
|
||||||
function M.toggle()
|
function M.toggle()
|
||||||
M.autoformat = not M.autoformat
|
M.autoformat = not M.autoformat
|
||||||
vim.notify(M.autoformat and "Enabled format on save" or "Disabled format on save")
|
vim.notify(M.autoformat and "Enabled format on save" or "Disabled format on save")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.format()
|
function M.format()
|
||||||
-- TODO: work out how to call conform if it has a formatter and default
|
-- TODO: work out how to call conform if it has a formatter and default
|
||||||
-- to vim.lsp.buf.format()
|
-- to vim.lsp.buf.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
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.on_attach(client, buf)
|
function M.on_attach(client, buf)
|
||||||
if client:supports_method("textDocument/formatting") then
|
if client:supports_method("textDocument/formatting") then
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
group = vim.api.nvim_create_augroup("LspFormat." .. buf, {}),
|
group = vim.api.nvim_create_augroup("LspFormat." .. buf, {}),
|
||||||
buffer = buf,
|
buffer = buf,
|
||||||
callback = function()
|
callback = function()
|
||||||
if M.autoformat then
|
if M.autoformat then
|
||||||
M.format()
|
M.format()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@ -1,242 +1,83 @@
|
|||||||
return {
|
return {
|
||||||
-- lspconfig
|
-- lspconfig
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"mason-org/mason-lspconfig.nvim",
|
||||||
enabled = true,
|
enabled = true,
|
||||||
event = "BufReadPre",
|
dependencies = {
|
||||||
dependencies = {
|
{
|
||||||
{
|
"mason-org/mason.nvim",
|
||||||
"folke/lazydev.nvim",
|
opts = {},
|
||||||
ft = "lua", -- only load on lua files
|
},
|
||||||
opts = {
|
"neovim/nvim-lspconfig",
|
||||||
library = {
|
},
|
||||||
-- See the configuration section for more details
|
opts = {
|
||||||
-- Load luvit types when the `vim.uv` word is found
|
automatic_enable = true,
|
||||||
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
|
ensure_installed = {
|
||||||
},
|
"lua_ls",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"mason.nvim",
|
config = function(_, opts)
|
||||||
{
|
require("mason-lspconfig").setup(opts)
|
||||||
"mason-org/mason-lspconfig.nvim",
|
require("lazyvim.plugins.lsp.config").setup()
|
||||||
version = "^1.0.0",
|
end,
|
||||||
},
|
},
|
||||||
-- "hrsh7th/cmp-nvim-lsp",
|
|
||||||
},
|
|
||||||
opts = {
|
|
||||||
-- options for vim.diagnostic.config()
|
|
||||||
diagnostics = {
|
|
||||||
underline = true,
|
|
||||||
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)
|
|
||||||
local Util = require("lazyvim.utils")
|
|
||||||
-- setup autoformat
|
|
||||||
require("lazyvim.plugins.lsp.format").autoformat = opts.autoformat
|
|
||||||
|
|
||||||
-- setup formatting and keymaps
|
{
|
||||||
Util.on_attach(function(client, buffer)
|
"mason-org/mason.nvim",
|
||||||
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
|
cmd = "Mason",
|
||||||
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
|
keys = { { "<leader>lM", "<cmd>Mason<cr>", desc = "Mason" } },
|
||||||
end)
|
opts = {
|
||||||
|
automatic_istallation = false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
-- diagnostics
|
-- formatting
|
||||||
for name, icon in pairs(require("lazyvim.config.icons").diagnostics) do
|
{
|
||||||
name = "DiagnosticSign" .. name
|
"stevearc/conform.nvim",
|
||||||
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })
|
enabled = true,
|
||||||
end
|
opts = {
|
||||||
|
formatters_by_ft = {
|
||||||
|
lua = { "stylua" },
|
||||||
|
-- Conform will run multiple formatters sequentially
|
||||||
|
python = { "isort", "black" },
|
||||||
|
-- Use a sub-list to run only the first available formatter
|
||||||
|
typescript = { { "prettierd", "prettier" } },
|
||||||
|
cs = { "csharpier" },
|
||||||
|
},
|
||||||
|
formatters = {
|
||||||
|
csharpier = {
|
||||||
|
command = "dotnet-csharpier",
|
||||||
|
args = { "--write-stdout" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then
|
-- cmdline tools and lsp servers
|
||||||
opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and "●"
|
{
|
||||||
or function(diagnostic)
|
"mason-org/mason.nvim",
|
||||||
local icons = require("lazyvim.config").icons.diagnostics
|
enabled = true,
|
||||||
for d, icon in pairs(icons) do
|
cmd = "Mason",
|
||||||
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
|
keys = { { "<leader>lM", "<cmd>Mason<cr>", desc = "Mason" } },
|
||||||
return icon
|
opts = {
|
||||||
end
|
automatic_istallation = false,
|
||||||
end
|
},
|
||||||
end
|
},
|
||||||
end
|
|
||||||
|
|
||||||
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
|
-- language specific tooling
|
||||||
|
{
|
||||||
local servers = opts.servers
|
"simrat39/rust-tools.nvim",
|
||||||
local capabilities = vim.tbl_deep_extend(
|
enabled = false,
|
||||||
"force",
|
opts = {
|
||||||
{},
|
server = {
|
||||||
vim.lsp.protocol.make_client_capabilities(),
|
on_attach = function(_, bufnr)
|
||||||
-- require("cmp_nvim_lsp").default_capabilities(),
|
local rt = require("rust-tools")
|
||||||
require("blink.cmp").get_lsp_capabilities(),
|
-- Hover actions
|
||||||
opts.capabilities or {}
|
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
|
||||||
)
|
-- Code action groups
|
||||||
|
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
|
||||||
local function setup(server)
|
end,
|
||||||
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,
|
|
||||||
},
|
|
||||||
|
|
||||||
-- formatting
|
|
||||||
{
|
|
||||||
"stevearc/conform.nvim",
|
|
||||||
enabled = true,
|
|
||||||
opts = {
|
|
||||||
formatters_by_ft = {
|
|
||||||
lua = { "stylua" },
|
|
||||||
-- Conform will run multiple formatters sequentially
|
|
||||||
python = { "isort", "black" },
|
|
||||||
-- Use a sub-list to run only the first available formatter
|
|
||||||
typescript = { { "prettierd", "prettier" } },
|
|
||||||
cs = { "csharpier" },
|
|
||||||
},
|
|
||||||
formatters = {
|
|
||||||
csharpier = {
|
|
||||||
command = "dotnet-csharpier",
|
|
||||||
args = { "--write-stdout" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
-- cmdline tools and lsp servers
|
|
||||||
{
|
|
||||||
"williamboman/mason.nvim",
|
|
||||||
version = "^1.0.0",
|
|
||||||
enabled = true,
|
|
||||||
cmd = "Mason",
|
|
||||||
keys = { { "<leader>lM", "<cmd>Mason<cr>", desc = "Mason" } },
|
|
||||||
opts = {
|
|
||||||
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
|
|
||||||
{
|
|
||||||
"simrat39/rust-tools.nvim",
|
|
||||||
enabled = false,
|
|
||||||
opts = {
|
|
||||||
server = {
|
|
||||||
on_attach = function(_, bufnr)
|
|
||||||
local rt = require("rust-tools")
|
|
||||||
-- Hover actions
|
|
||||||
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
|
|
||||||
-- Code action groups
|
|
||||||
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,72 +1,72 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.on_attach(client, buffer)
|
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" })
|
||||||
self:map("gD", "Telescope lsp_declarations", { desc = "Goto Declaration" })
|
self:map("gD", "Telescope lsp_declarations", { desc = "Goto Declaration" })
|
||||||
self:map("gI", "Telescope lsp_implementations", { desc = "Goto Implementation" })
|
self:map("gI", "Telescope lsp_implementations", { desc = "Goto Implementation" })
|
||||||
self:map("gt", "Telescope lsp_type_definitions", { desc = "Goto Type Definition" })
|
self:map("gt", "Telescope lsp_type_definitions", { desc = "Goto Type Definition" })
|
||||||
self:map("K", vim.lsp.buf.hover, { desc = "Hover" })
|
self:map("K", vim.lsp.buf.hover, { desc = "Hover" })
|
||||||
self:map("gK", vim.lsp.buf.signature_help, { desc = "Signature Help", has = "signatureHelp" })
|
self:map("gK", vim.lsp.buf.signature_help, { desc = "Signature Help", has = "signatureHelp" })
|
||||||
self:map("[d", M.diagnostic_goto(true), { desc = "Next Diagnostic" })
|
self:map("[d", M.diagnostic_goto(true), { desc = "Next Diagnostic" })
|
||||||
self:map("]d", M.diagnostic_goto(false), { desc = "Prev Diagnostic" })
|
self:map("]d", M.diagnostic_goto(false), { desc = "Prev Diagnostic" })
|
||||||
self:map("]e", M.diagnostic_goto(true, "ERROR"), { desc = "Next Error" })
|
self:map("]e", M.diagnostic_goto(true, "ERROR"), { desc = "Next Error" })
|
||||||
self:map("[e", M.diagnostic_goto(false, "ERROR"), { desc = "Prev Error" })
|
self:map("[e", M.diagnostic_goto(false, "ERROR"), { desc = "Prev Error" })
|
||||||
self:map("]w", M.diagnostic_goto(true, "WARNING"), { desc = "Next Warning" })
|
self:map("]w", M.diagnostic_goto(true, "WARNING"), { desc = "Next Warning" })
|
||||||
self:map("[w", M.diagnostic_goto(false, "WARNING"), { desc = "Prev Warning" })
|
self:map("[w", M.diagnostic_goto(false, "WARNING"), { desc = "Prev Warning" })
|
||||||
self:map("<leader>la", vim.lsp.buf.code_action, { desc = "Code Action", mode = { "n", "v" }, has = "codeAction" })
|
self:map("<leader>la", vim.lsp.buf.code_action, { desc = "Code Action", mode = { "n", "v" }, has = "codeAction" })
|
||||||
|
|
||||||
local format = require("lazyvim.plugins.lsp.format").format
|
local format = require("lazyvim.plugins.lsp.format").format
|
||||||
self:map("<leader>lf", format, { desc = "Format Document", has = "documentFormatting" })
|
self:map("<leader>lf", format, { desc = "Format Document", has = "documentFormatting" })
|
||||||
self:map("<leader>lr", M.rename, { expr = true, desc = "Rename", has = "rename" })
|
self:map("<leader>lr", M.rename, { expr = true, desc = "Rename", has = "rename" })
|
||||||
|
|
||||||
if client.name == "tsserver" and pcall(require, "typescript") then
|
if client.name == "tsserver" and pcall(require, "typescript") then
|
||||||
self:map("<leader>lo", "TypescriptOrganizeImports", { desc = "Organize Imports" })
|
self:map("<leader>lo", "TypescriptOrganizeImports", { desc = "Organize Imports" })
|
||||||
self:map("<leader>lR", "TypescriptRenameFile", { desc = "Rename File" })
|
self:map("<leader>lR", "TypescriptRenameFile", { desc = "Rename File" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.new(client, buffer)
|
function M.new(client, buffer)
|
||||||
return setmetatable({ client = client, buffer = buffer }, { __index = M })
|
return setmetatable({ client = client, buffer = buffer }, { __index = M })
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:has(cap)
|
function M:has(cap)
|
||||||
return self.client.server_capabilities[cap .. "Provider"]
|
return self.client.server_capabilities[cap .. "Provider"]
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:map(lhs, rhs, opts)
|
function M:map(lhs, rhs, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
if opts.has and not self:has(opts.has) then
|
if opts.has and not self:has(opts.has) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.keymap.set(
|
vim.keymap.set(
|
||||||
opts.mode or "n",
|
opts.mode or "n",
|
||||||
lhs,
|
lhs,
|
||||||
type(rhs) == "string" and ("<cmd>%s<cr>"):format(rhs) or rhs,
|
type(rhs) == "string" and ("<cmd>%s<cr>"):format(rhs) or rhs,
|
||||||
---@diagnostic disable-next-line: no-unknown
|
---@diagnostic disable-next-line: no-unknown
|
||||||
{ silent = true, buffer = self.buffer, expr = opts.expr, desc = opts.desc }
|
{ silent = true, buffer = self.buffer, expr = opts.expr, desc = opts.desc }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.rename()
|
function M.rename()
|
||||||
if pcall(require, "inc_rename") then
|
if pcall(require, "inc_rename") then
|
||||||
return ":IncRename " .. vim.fn.expand("<cword>")
|
return ":IncRename " .. vim.fn.expand("<cword>")
|
||||||
else
|
else
|
||||||
vim.lsp.buf.rename()
|
vim.lsp.buf.rename()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.diagnostic_goto(next, severity)
|
function M.diagnostic_goto(next, severity)
|
||||||
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
|
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
|
||||||
severity = severity and vim.diagnostic.severity[severity] or nil
|
severity = severity and vim.diagnostic.severity[severity] or nil
|
||||||
return function()
|
return function()
|
||||||
go({ severity = severity })
|
go({ severity = severity })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,18 +3,19 @@ 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", {
|
||||||
callback = function(args)
|
group = vim.api.nvim_create_augroup("my.lsp", {}),
|
||||||
local buffer = args.buf
|
callback = function(args)
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
local buffer = args.buf
|
||||||
on_attach(client, buffer)
|
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
|
||||||
end,
|
on_attach(client, buffer)
|
||||||
})
|
end,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns the root directory based on:
|
-- returns the root directory based on:
|
||||||
@ -24,146 +25,146 @@ end
|
|||||||
-- * root pattern of cwd
|
-- * root pattern of cwd
|
||||||
---@return string
|
---@return string
|
||||||
function M.get_root()
|
function M.get_root()
|
||||||
---@type string?
|
---@type string?
|
||||||
local path = vim.api.nvim_buf_get_name(0)
|
local path = vim.api.nvim_buf_get_name(0)
|
||||||
path = path ~= "" and vim.loop.fs_realpath(path) or nil
|
path = path ~= "" and vim.loop.fs_realpath(path) or nil
|
||||||
---@type string[]
|
---@type string[]
|
||||||
local roots = {}
|
local roots = {}
|
||||||
if path then
|
if path then
|
||||||
for _, client in pairs(vim.lsp.get_clients({ bufnr = 0 })) do
|
for _, client in pairs(vim.lsp.get_clients({ bufnr = 0 })) do
|
||||||
local workspace = client.config.workspace_folders
|
local workspace = client.config.workspace_folders
|
||||||
local paths = workspace
|
local paths = workspace
|
||||||
and vim.tbl_map(function(ws)
|
and vim.tbl_map(function(ws)
|
||||||
return vim.uri_to_fname(ws.uri)
|
return vim.uri_to_fname(ws.uri)
|
||||||
end, workspace)
|
end, workspace)
|
||||||
or client.config.root_dir and { client.config.root_dir }
|
or client.config.root_dir and { client.config.root_dir }
|
||||||
or {}
|
or {}
|
||||||
for _, p in ipairs(paths) do
|
for _, p in ipairs(paths) do
|
||||||
local r = vim.loop.fs_realpath(p)
|
local r = vim.loop.fs_realpath(p)
|
||||||
if path:find(r, 1, true) then
|
if path:find(r, 1, true) then
|
||||||
roots[#roots + 1] = r
|
roots[#roots + 1] = r
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(roots, function(a, b)
|
table.sort(roots, function(a, b)
|
||||||
return #a > #b
|
return #a > #b
|
||||||
end)
|
end)
|
||||||
---@type string?
|
---@type string?
|
||||||
local root = roots[1]
|
local root = roots[1]
|
||||||
if not root then
|
if not root then
|
||||||
path = path and vim.fs.dirname(path) or vim.loop.cwd()
|
path = path and vim.fs.dirname(path) or vim.loop.cwd()
|
||||||
---@type string?
|
---@type string?
|
||||||
root = vim.fs.find(M.root_patterns, { path = path, upward = true })[1]
|
root = vim.fs.find(M.root_patterns, { path = path, upward = true })[1]
|
||||||
root = root and vim.fs.dirname(root) or vim.loop.cwd()
|
root = root and vim.fs.dirname(root) or vim.loop.cwd()
|
||||||
end
|
end
|
||||||
---@cast root string
|
---@cast root string
|
||||||
return root
|
return root
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param silent boolean?
|
---@param silent boolean?
|
||||||
---@param values? {[1]:any, [2]:any}function
|
---@param values? {[1]:any, [2]:any}function
|
||||||
function M.toggle(option, silent, values)
|
function M.toggle(option, silent, values)
|
||||||
if values then
|
if values then
|
||||||
if vim.opt_local[option]:get() == values[1] then
|
if vim.opt_local[option]:get() == values[1] then
|
||||||
vim.opt_local[option] = values[2]
|
vim.opt_local[option] = values[2]
|
||||||
else
|
else
|
||||||
vim.opt_local[option] = values[1]
|
vim.opt_local[option] = values[1]
|
||||||
end
|
end
|
||||||
return vim.notify(
|
return vim.notify(
|
||||||
"Set " .. option .. " to " .. vim.opt_local[option]:get(),
|
"Set " .. option .. " to " .. vim.opt_local[option]:get(),
|
||||||
vim.log.levels.INFO,
|
vim.log.levels.INFO,
|
||||||
{ title = "Option" }
|
{ title = "Option" }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
vim.opt_local[option] = not vim.opt_local[option]:get()
|
vim.opt_local[option] = not vim.opt_local[option]:get()
|
||||||
if not silent then
|
if not silent then
|
||||||
vim.notify(
|
vim.notify(
|
||||||
(vim.opt_local[option]:get() and "Enabled" or "Disabled") .. " " .. option,
|
(vim.opt_local[option]:get() and "Enabled" or "Disabled") .. " " .. option,
|
||||||
vim.log.levels.INFO,
|
vim.log.levels.INFO,
|
||||||
{ title = "Option" }
|
{ title = "Option" }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local diagnostics_enabled = true
|
local diagnostics_enabled = true
|
||||||
function M.toggle_diagnostics()
|
function M.toggle_diagnostics()
|
||||||
diagnostics_enabled = not diagnostics_enabled
|
diagnostics_enabled = not diagnostics_enabled
|
||||||
if diagnostics_enabled then
|
if diagnostics_enabled then
|
||||||
vim.diagnostic.enable()
|
vim.diagnostic.enable()
|
||||||
vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
|
vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
|
||||||
else
|
else
|
||||||
vim.diagnostic.disable()
|
vim.diagnostic.disable()
|
||||||
vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
|
vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.smart_quit()
|
function M.smart_quit()
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
local modified = vim.api.nvim_buf_get_option(bufnr, "modified")
|
local modified = vim.api.nvim_buf_get_option(bufnr, "modified")
|
||||||
if modified then
|
if modified then
|
||||||
vim.ui.input({
|
vim.ui.input({
|
||||||
prompt = "You have unsaved changes. Quit anyway? (y/n) ",
|
prompt = "You have unsaved changes. Quit anyway? (y/n) ",
|
||||||
}, function(input)
|
}, function(input)
|
||||||
if input == "y" then
|
if input == "y" then
|
||||||
vim.cmd("q!")
|
vim.cmd("q!")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
vim.cmd("q!")
|
vim.cmd("q!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.isempty(s)
|
function M.isempty(s)
|
||||||
return s == nil or s == ""
|
return s == nil or s == ""
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_buf_option(opt)
|
function M.get_buf_option(opt)
|
||||||
local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt)
|
local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt)
|
||||||
if not status_ok then
|
if not status_ok then
|
||||||
return nil
|
return nil
|
||||||
else
|
else
|
||||||
return buf_option
|
return buf_option
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.telescope(builtin, opts)
|
function M.telescope(builtin, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts.dir = opts.dir or M.get_root()
|
opts.dir = opts.dir or M.get_root()
|
||||||
return function()
|
return function()
|
||||||
require("telescope.builtin")[builtin](vim.tbl_deep_extend("force", { cwd = opts.dir }, opts))
|
require("telescope.builtin")[builtin](vim.tbl_deep_extend("force", { cwd = opts.dir }, opts))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This might not be best, but it allows for easy resetting
|
-- This might not be best, but it allows for easy resetting
|
||||||
function M.setColorscheme(scheme)
|
function M.setColorscheme(scheme)
|
||||||
local colorscheme = scheme or "gruvbox-material"
|
local colorscheme = scheme or "gruvbox-material"
|
||||||
|
|
||||||
local okay, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
|
local okay, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
|
||||||
|
|
||||||
if not okay then
|
if not okay then
|
||||||
vim.notify("Colorscheme " .. colorscheme .. " not found!")
|
vim.notify("Colorscheme " .. colorscheme .. " not found!")
|
||||||
vim.cmd("colorscheme habamax")
|
vim.cmd("colorscheme habamax")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.trim_whitespace()
|
function M.trim_whitespace()
|
||||||
pcall(vim.cmd, 'let currPos = getpos(".")')
|
pcall(vim.cmd, 'let currPos = getpos(".")')
|
||||||
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)
|
||||||
local exists = vim.fn.filereadable(vim.fn.expand(path))
|
local exists = vim.fn.filereadable(vim.fn.expand(path))
|
||||||
if exists == 1 then
|
if exists == 1 then
|
||||||
-- vim.notify(path .. " exists", vim.log.levels.INFO)
|
-- vim.notify(path .. " exists", vim.log.levels.INFO)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
-- vim.notify(path .. " doesn't exist", vim.log.levels.INFO)
|
-- vim.notify(path .. " doesn't exist", vim.log.levels.INFO)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user