Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 54 additions & 18 deletions plugins/nobbz/lua/nobbz/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
local null_ls = require("null-ls")
local lspconfig = require("lspconfig")
local helpers = require("nobbz.lsp.helpers")
local register_lsp = require("nobbz.health").register_lsp

local formatting = null_ls.builtins.formatting
local diagnostics = null_ls.builtins.diagnostics
local code_actions = null_ls.builtins.code_actions
Expand All @@ -24,21 +28,53 @@ null_ls.setup({
-- capabilities = require("blink.cmp").get_lsp_capabilities()

-- Load individual languages configuration
require("nobbz.lsp.astro")
require("nobbz.lsp.beancount")
require("nobbz.lsp.c-cpp")
require("nobbz.lsp.digestif")
require("nobbz.lsp.elixir")
require("nobbz.lsp.gleam")
require("nobbz.lsp.html")
require("nobbz.lsp.lua")
require("nobbz.lsp.mdx")
require("nobbz.lsp.meson")
require("nobbz.lsp.nil")
require("nobbz.lsp.nushell")
require("nobbz.lsp.oxide")
require("nobbz.lsp.python")
require("nobbz.lsp.rust")
require("nobbz.lsp.tailwind")
require("nobbz.lsp.typescript")
require("nobbz.lsp.zig")
local clients = {
require("nobbz.lsp.astro"),
require("nobbz.lsp.beancount"),
require("nobbz.lsp.c-cpp"),
require("nobbz.lsp.digestif"),
require("nobbz.lsp.elixir"),
require("nobbz.lsp.gleam"),
require("nobbz.lsp.html"),
require("nobbz.lsp.lua"),
require("nobbz.lsp.mdx"),
require("nobbz.lsp.meson"),
require("nobbz.lsp.nil"),
require("nobbz.lsp.nushell"),
require("nobbz.lsp.oxide"),
require("nobbz.lsp.python"),
require("nobbz.lsp.rust"),
require("nobbz.lsp.tailwind"),
require("nobbz.lsp.typescript"),
require("nobbz.lsp.zig"),
}

for _, client_config in ipairs(clients) do
local name = client_config.name or error("client name is required")
local activate = client_config.activate or function() return true end
local capabilities = client_config.capabilities or LSP_CAPAS
local on_attach = client_config.on_attach or { helpers.default, }
local init_options = client_config.init_options
local root_dir = client_config.root_dir
local cmd = client_config.cmd
local settings = client_config.settings
local on_init = client_config.on_init
local filetypes = client_config.filetypes

local setup = {
on_attach = helpers.combine(on_attach),
capabilities = capabilities,
init_options = init_options,
root_dir = root_dir,
cmd = cmd,
settings = settings,
on_init = on_init,
filetypes = filetypes,
}

if activate() then
lspconfig[name].setup(setup)

register_lsp(client_config.name)
end
end
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/astro.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").astro.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
})

require("nobbz.health").register_lsp("astro")
return {
name = "astro",
on_attach = { helpers.keymap, },
}
21 changes: 9 additions & 12 deletions plugins/nobbz/lua/nobbz/lsp/beancount.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ if root_dir ~= nil then
journal_file = vim.fs.joinpath(root_dir, "main.beancount")
end

if root_dir ~= nil
and journal_file ~= nil
and vim.uv.fs_stat(journal_file) ~= nil then
require("lspconfig").beancount.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
root_dir = root_dir,
init_options = { journal_file = journal_file, },
})

require("nobbz.health").register_lsp("beancount")
end
return {
name = "beancount",
activate = function()
return root_dir ~= nil and journal_file ~= nil and vim.uv.fs_stat(journal_file) ~= nil
end,
on_attach = { helpers.keymap, },
init_options = { journal_file = journal_file, },
root_dir = root_dir,
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/c-cpp.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").clangd.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
return {
name = "clangd",
on_attach = { helpers.keymap, },
cmd = { "clangd", "--background-index", },
})

require("nobbz.health").register_lsp("clangd")
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/digestif.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").digestif.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
})

require("nobbz.health").register_lsp("digestif")
return {
name = "digestif",
on_attach = { helpers.keymap, },
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/elixir.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").elixirls.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
return {
name = "elixirls",
on_attach = { helpers.keymap, },
cmd = { "elixir-ls", },
})

require("nobbz.health").register_lsp("elixirls")
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/gleam.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").gleam.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
})

require("nobbz.health").register_lsp("gleam")
return {
name = "gleam",
on_attach = { helpers.keymap, },
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/html.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").html.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
})

require("nobbz.health").register_lsp("html")
return {
name = "html",
on_attach = { helpers.keymap, },
}
76 changes: 37 additions & 39 deletions plugins/nobbz/lua/nobbz/lsp/lua.lua
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").lua_ls.setup({
on_attach = helpers.combine({
helpers.default,
function(_, buffer)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = buffer,
callback = function()
vim.lsp.buf.format({
async = false,
bufnr = buffer,
})
end,
local function on_attach(_, buffer)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = buffer,
callback = function()
vim.lsp.buf.format({
async = false,
bufnr = buffer,
})
end,
}),
})
end

-- this snippet is adopted from:
-- https://github.com/neovim/nvim-lspconfig/blob/37f362ef42d1a604d332e8d3d7d47593852b4313/doc/server_configurations.md#lua_ls
on_init = function(client)
local path = client.workspace_folders[1].name
-- this snippet is adopted from:
-- https://github.com/neovim/nvim-lspconfig/blob/37f362ef42d1a604d332e8d3d7d47593852b4313/doc/server_configurations.md#lua_ls
local function on_init(client)
local path = client.workspace_folders[1].name

-- Search in project for a `.luarc.json` or `.luarc.jsonc`, do nothing if found.
local luarc_json_exists = vim.fn.glob(path .. "/.luarc.json") ~= ""
local luarc_jsonc_exists = vim.fn.glob(path .. "/.luarc.jsonc") ~= ""
if luarc_json_exists or luarc_jsonc_exists then return end
-- Search in project for a `.luarc.json` or `.luarc.jsonc`, do nothing if found.
local luarc_json_exists = vim.fn.glob(path .. "/.luarc.json") ~= ""
local luarc_jsonc_exists = vim.fn.glob(path .. "/.luarc.jsonc") ~= ""
if luarc_json_exists or luarc_jsonc_exists then return end

-- if there is a luarc.lua in the workspace root, import and merge.
local plugin_paths = vim.split(vim.fn.glob(path .. "/plugins/*/lua"), "\n", { trimempty = true, })
plugin_paths = vim.iter(plugin_paths):map(function(plugin_path) return string.sub(plugin_path, -1, -4) end)
table.insert(plugin_paths, vim.env.VIMRUNTIME)
-- if there is a luarc.lua in the workspace root, import and merge.
local plugin_paths = vim.split(vim.fn.glob(path .. "/plugins/*/lua"), "\n", { trimempty = true, })
plugin_paths = vim.iter(plugin_paths):map(function(plugin_path) return string.sub(plugin_path, -1, -4) end)
table.insert(plugin_paths, vim.env.VIMRUNTIME)

-- Assume we are in a nvim config and configure appropriately to not warn on nvim globals
client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
runtime = { version = "LuaJIT", },
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = plugin_paths,
},
})
end,
-- Assume we are in a nvim config and configure appropriately to not warn on nvim globals
client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
runtime = { version = "LuaJIT", },
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = plugin_paths,
},
})
end

return {
name = "lua_ls",
on_attach = { helpers.default, on_attach, },
on_init = on_init,
settings = {
Lua = {
hint = { enable = true, },
},
},
capabilities = LSP_CAPAS,
})

require("nobbz.health").register_lsp("lua_ls")
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/mdx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ vim.filetype.add({
},
})

require("lspconfig").mdx_analyzer.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
})

require("nobbz.health").register_lsp("mdx_analyzer")
return {
name = "mdx_analyzer",
on_attach = { helpers.keymap, },
}
Comment on lines +9 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Missing lazyloading mechanism as required by coding guidelines.

The declarative configuration approach is consistent with the refactoring pattern. However, the coding guidelines specify that plugins should be lazyloaded through nobbz.lazy, which is not implemented here.

🤖 Prompt for AI Agents
In plugins/nobbz/lua/nobbz/lsp/mdx.lua around lines 9 to 12, the plugin
configuration lacks the required lazyloading mechanism as per coding guidelines.
Modify the return table to include lazyloading by wrapping the plugin setup with
`nobbz.lazy` or by adding a lazyload key or function according to the project's
lazyloading pattern. This ensures the plugin is loaded only when needed,
following the established conventions.

10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/meson.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").mesonlsp.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
return {
name = "mesonlsp",
on_attach = { helpers.keymap, },
root_dir = require("lspconfig.util").root_pattern(".git"),
})

require("nobbz.health").register_lsp("mesonlsp")
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/nil.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").nil_ls.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
return {
name = "nil_ls",
on_attach = { helpers.keymap, },
cmd = { "nil", },
settings = {
["nil"] = {
Expand All @@ -20,6 +20,4 @@ require("lspconfig").nil_ls.setup({
},
},
},
})

require("nobbz.health").register_lsp("nil_ls")
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/nushell.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").nushell.setup({
on_attach = helpers.default,
capabilities = LSP_CAPAS,
return {
name = "nushell",
on_attach = { helpers.default, },
filetypes = { "nu", },
cmd = { "nu", "--lsp", },
})

require("nobbz.health").register_lsp("nushell")
}
9 changes: 4 additions & 5 deletions plugins/nobbz/lua/nobbz/lsp/oxide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ capabilities.workspace = {
},
}

require("lspconfig").markdown_oxide.setup({
on_attach = helpers.default,
return {
name = "markdown_oxide",
on_attach = { helpers.default, },
capabilities = capabilities,
})

require("nobbz.health").register_lsp("markdown_oxide")
}
10 changes: 4 additions & 6 deletions plugins/nobbz/lua/nobbz/lsp/python.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local helpers = require("nobbz.lsp.helpers")

require("lspconfig").basedpyright.setup({
on_attach = helpers.keymap,
capabilities = LSP_CAPAS,
return {
name = "basedpyright",
on_attach = { helpers.keymap, },
settings = {
basedpyright = {
analysis = {
Expand All @@ -13,6 +13,4 @@ require("lspconfig").basedpyright.setup({
},
},
},
})

require("nobbz.health").register_lsp("basedpyright")
}
Loading