Try configuring language servers

This commit is contained in:
2024-11-21 10:54:36 +01:00
parent c84564fed0
commit 3b130ee4e7
3 changed files with 160 additions and 65 deletions

View File

@@ -1,15 +1,64 @@
-----------------------------------------------------------
-- Conform.nvim Formatter Configuration
-----------------------------------------------------------
local options = { local options = {
-- Disable LSP formatting fallback
lsp_fallback = false,
-----------------------------------------------------------
-- Formatter Assignments by File Type
-----------------------------------------------------------
formatters_by_ft = { formatters_by_ft = {
-- Lua
lua = { "stylua" }, lua = { "stylua" },
-- css = { "prettier" },
-- html = { "prettier" }, -- Web Development
javascript = { "prettierd", "prettier", stop_after_first = true },
typescript = { "prettierd", "prettier", stop_after_first = true },
typescriptreact = { "prettierd", "prettier", stop_after_first = true },
astro = { "prettierd", "prettier", stop_after_first = true },
svelte = { "prettierd", "prettier", stop_after_first = true },
html = { "prettierd", "prettier", stop_after_first = true },
css = { "prettierd", "prettier", stop_after_first = true },
json = { "prettierd" },
yml = { "prettierd", "prettier", stop_after_first = true },
toml = { "prettierd", "prettier", stop_after_first = true },
-- Systems Programming
rust = { "rustfmt" },
c = { "clangformat" },
cpp = { "clangformat" },
-- Shell and Configuration
sh = { "shfmt" },
nix = { "nixpkgsfmt" },
}, },
-- format_on_save = { -----------------------------------------------------------
-- -- These options will be passed to conform.format() -- Custom Formatter Configurations
-- timeout_ms = 500, -----------------------------------------------------------
-- lsp_fallback = true, formatters = {
-- }, -- Nix formatter configuration
nixpkgsfmt = {
command = "nixpkgs-fmt",
args = {},
},
-- C/C++ formatter configuration
clangformat = {
inherit = false,
command = "clang-format",
},
},
-----------------------------------------------------------
-- Format on Save Settings
-----------------------------------------------------------
format_on_save = {
timeout_ms = 2500, -- Maximum time to wait for formatting
lsp_fallback = false, -- Don't fallback to LSP formatting
},
} }
return options return options

View File

@@ -1,24 +1,101 @@
-- load defaults i.e lua_lsp -----------------------------------------------------------
-- LSP Configuration
-----------------------------------------------------------
-- Load NvChad LSP defaults
require("nvchad.configs.lspconfig").defaults() require("nvchad.configs.lspconfig").defaults()
local lspconfig = require "lspconfig" local lspconfig = require("lspconfig")
local nvlsp = require("nvchad.configs.lspconfig")
-- EXAMPLE -----------------------------------------------------------
local servers = { "html", "cssls" } -- Language Server Configurations
local nvlsp = require "nvchad.configs.lspconfig" -----------------------------------------------------------
-- lsps with default config local servers = {
for _, lsp in ipairs(servers) do -----------------------------------------------------------
lspconfig[lsp].setup { -- Web Development
on_attach = nvlsp.on_attach, -----------------------------------------------------------
on_init = nvlsp.on_init, -- HTML & CSS
capabilities = nvlsp.capabilities, emmet_language_server = {},
html = {},
cssls = {},
-- JavaScript & Frameworks
svelte = {},
astro = {},
-- Tailwind CSS
tailwindcss = {
settings = {
tailwindCSS = {
experimental = {
classRegex = {
{ "cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]" },
{ "cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)" },
{ "cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)" },
},
},
},
},
},
-- JSON & Linting
jsonls = {},
eslint = {},
-----------------------------------------------------------
-- DevOps & Infrastructure
-----------------------------------------------------------
-- Docker
docker_compose_language_service = {},
dockerls = {},
-- Server Configuration
nginx_language_server = {},
-----------------------------------------------------------
-- Systems Programming
-----------------------------------------------------------
-- Rust
rust_analyzer = {},
-- C/C++
clangd = {},
-- Go
gopls = {},
-----------------------------------------------------------
-- Scripting & Configuration
-----------------------------------------------------------
-- Lua
lua_ls = {},
-- Nix
nixd = {},
-- C# (currently disabled)
-- csharp_ls = {},
-----------------------------------------------------------
-- Database & Backend
-----------------------------------------------------------
-- SQL
sqls = {},
-- PHP
phpactor = {},
} }
end
-- configuring single server, example: typescript -----------------------------------------------------------
-- lspconfig.ts_ls.setup { -- Apply Server Configurations
-- on_attach = nvlsp.on_attach, -----------------------------------------------------------
-- on_init = nvlsp.on_init,
-- capabilities = nvlsp.capabilities, -- Iterate through servers and apply common configuration
-- } for name, opts in pairs(servers) do
opts.on_init = nvlsp.on_init
opts.on_attach = nvlsp.on_attach
opts.capabilities = nvlsp.capabilities
lspconfig[name].setup(opts)
end

View File

@@ -1,16 +1,9 @@
return { return {
{
"stevearc/conform.nvim",
-- event = 'BufWritePre', -- uncomment for format on save
opts = require "configs.conform",
},
{ {
"charludo/projectmgr.nvim", "charludo/projectmgr.nvim",
lazy = false, -- Required for proper functionality lazy = false, -- Required for proper functionality
}, },
-- These are some examples, uncomment them if you want to see them work!
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
config = function() config = function()
@@ -19,33 +12,9 @@ return {
}, },
{ {
"neovim/nvim-lspconfig", "stevearc/conform.nvim",
dependencies = { event = "BufWritePre",
-- Installer for language servers opts = require "configs.conform",
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
},
config = function()
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls", -- Lua
"gopls", -- Go
"tsserver", -- JavaScript/TypeScript
},
})
local lspconfig = require("lspconfig")
-- Lua Language Server
lspconfig.lua_ls.setup {}
-- Go Language Server
lspconfig.gopls.setup {}
-- JavaScript/TypeScript Language Server
lspconfig.tsserver.setup {}
end,
}, },
-- Supermaven -- Supermaven