Skip to main content
Magictt uses Mason to manage LSP servers, formatters, and linters. All language servers are configured in lua/magictt/plugins/lsp/mason.lua.

Current Configuration

The LSP configuration is split into two main sections:

1. Language Servers (mason.lua:1-35)

return {
  {
    "williamboman/mason-lspconfig.nvim",
    opts = {
      ensure_installed = {
        "ts_ls",      -- TypeScript
        "html",       -- HTML
        "cssls",      -- CSS
        "tailwindcss",-- Tailwind CSS
        "svelte",     -- Svelte
        "lua_ls",     -- Lua
        "graphql",    -- GraphQL
        "emmet_ls",   -- Emmet
        "prismals",   -- Prisma
        "pyright",    -- Python
        "eslint",     -- ESLint
      },
    },
  },
}

2. Formatters and Linters (mason.lua:36-51)

{
  "WhoIsSethDaniel/mason-tool-installer.nvim",
  opts = {
    ensure_installed = {
      "prettier",  -- prettier formatter
      "stylua",    -- lua formatter
      "isort",     -- python formatter
      "black",     -- python formatter
      "pylint",    -- python linter
      "eslint_d",  -- eslint daemon
    },
  },
}

Adding a New Language Server

1

Find the LSP server name

Visit Mason’s LSP server list or run:
:Mason
Then search for your language (press / and type the language name).Common examples:
  • Rust: rust_analyzer
  • Go: gopls
  • C/C++: clangd
  • Java: jdtls
  • Ruby: solargraph
  • PHP: intelephense
2

Open mason.lua

Open the Mason configuration file:
nvim lua/magictt/plugins/lsp/mason.lua
3

Add the server to ensure_installed

Add your language server to the ensure_installed table:
opts = {
  ensure_installed = {
    "ts_ls",
    "html",
    "cssls",
    "tailwindcss",
    "svelte",
    "lua_ls",
    "graphql",
    "emmet_ls",
    "prismals",
    "pyright",
    "eslint",
    "rust_analyzer", -- Add Rust support
    "gopls",         -- Add Go support
  },
},
4

Restart and sync

Save the file and restart Neovim. Mason will automatically install the new language server.Or run manually:
:MasonInstall rust_analyzer gopls
Verify installation:
:Mason

Adding Formatters and Linters

To add formatters or linters for your language:
1

Find the tool name

Open Mason to browse available tools:
:Mason
Filter by category:
  • Press 2 for Formatters
  • Press 3 for Linters
2

Add to mason-tool-installer

Add the tool to the second section of mason.lua:
{
  "WhoIsSethDaniel/mason-tool-installer.nvim",
  opts = {
    ensure_installed = {
      "prettier",
      "stylua",
      "isort",
      "black",
      "pylint",
      "eslint_d",
      "rustfmt",     -- Rust formatter
      "gofumpt",     -- Go formatter
      "golines",     -- Go formatter
    },
  },
}
3

Configure the formatter

Formatters are configured in lua/magictt/plugins/conform.lua. Add your formatter configuration there if needed.

Real-World Example: Adding Rust Support

Here’s a complete example of adding Rust language support:
1

Add rust_analyzer

Edit lua/magictt/plugins/lsp/mason.lua:
ensure_installed = {
  -- ... existing servers
  "rust_analyzer",
},
2

Add Rust formatters

Add Rust formatting tools:
ensure_installed = {
  -- ... existing tools
  "rustfmt",
},
3

Restart Neovim

Restart Neovim and open a Rust file (.rs). The LSP should automatically attach and provide:
  • Code completion
  • Diagnostics
  • Go to definition
  • Hover documentation
  • And more!

Real-World Example: Adding Go Support

1

Add gopls

ensure_installed = {
  -- ... existing servers
  "gopls",
},
2

Add Go formatters

ensure_installed = {
  -- ... existing tools
  "gofumpt",
  "goimports",
  "golines",
},
3

Test Go support

Open a Go file and verify LSP features work.

LSP Configuration Structure

The LSP setup follows this structure:
lua/magictt/plugins/lsp/
├── mason.lua       # Language servers and tools installation
└── lsp.lua         # LSP configuration and capabilities

mason.lua (Installation)

Defines which servers and tools to install.

lsp.lua (Configuration)

Defines how LSP servers behave (keybindings, autocompletion capabilities, etc.).

Advanced: Per-Language Configuration

For language-specific LSP configuration, you can modify lua/magictt/plugins/lsp/lsp.lua.

Current Auto-Format Configuration (lsp.lua:18-24)

-- Auto-format on save for web files
vim.api.nvim_create_autocmd("BufWritePre", {
  pattern = { "*.js", "*.ts" },
  callback = function()
    vim.lsp.buf.format({ async = true })
  end,
})

Adding Custom Language Configuration

To add custom configuration for a specific language server:
config = function()
  local lspconfig = require("lspconfig")
  local cmp_nvim_lsp = require("cmp_nvim_lsp")
  local capabilities = cmp_nvim_lsp.default_capabilities()

  -- Rust-specific configuration
  lspconfig.rust_analyzer.setup({
    capabilities = capabilities,
    settings = {
      ["rust-analyzer"] = {
        cargo = {
          allFeatures = true,
        },
        checkOnSave = {
          command = "clippy",
        },
      },
    },
  })

  -- Go-specific configuration
  lspconfig.gopls.setup({
    capabilities = capabilities,
    settings = {
      gopls = {
        analyses = {
          unusedparams = true,
        },
        staticcheck = true,
      },
    },
  })
end,

LSP Server Settings

Each language server has its own settings. Find documentation for your server:

Example: TypeScript Settings

lspconfig.ts_ls.setup({
  capabilities = capabilities,
  settings = {
    typescript = {
      inlayHints = {
        includeInlayParameterNameHints = "all",
        includeInlayFunctionParameterTypeHints = true,
      },
    },
  },
})

Example: Lua Settings

lspconfig.lua_ls.setup({
  capabilities = capabilities,
  settings = {
    Lua = {
      diagnostics = {
        globals = { "vim" }, -- Recognize 'vim' global
      },
      workspace = {
        library = vim.api.nvim_get_runtime_file("", true),
        checkThirdParty = false,
      },
    },
  },
})

Managing Installed Servers

Mason UI Commands

  • :Mason or <leader>mm - Open Mason panel
  • :MasonInstall <package> - Install a package
  • :MasonUninstall <package> - Uninstall a package
  • :MasonUpdate - Update all packages
  • :MasonLog - View installation logs

Within the Mason UI

  • i - Install package under cursor
  • u - Uninstall package under cursor
  • U - Update package under cursor
  • / - Search packages
  • X - Uninstall all packages

Troubleshooting

LSP Not Attaching

  1. Check if server is installed:
    :Mason
    
  2. Check LSP status:
    :LspInfo
    
  3. Restart LSP:
    :LspRestart
    

Installation Failures

  1. Check Mason log:
    :MasonLog
    
  2. Check dependencies: Some servers require external dependencies (Node.js, Python, etc.)
  3. Manual installation:
    :MasonInstall <server-name>
    

Server Not Working Correctly

  1. Check health:
    :checkhealth mason
    :checkhealth lsp
    
  2. Verify file type: Ensure Neovim detects the correct file type:
    :set filetype?
    
  3. Review server settings: Check the server’s documentation for required configuration.

Best Practices

  1. Only install what you need: Don’t install every available LSP server
  2. Use mason-tool-installer: Automatically installs tools on startup
  3. Keep servers updated: Run :MasonUpdate periodically
  4. Check compatibility: Ensure your OS supports the LSP server
  5. Read documentation: Each server has unique features and settings
  6. Configure per-project: Use project-local settings when needed

Common Language Servers

LanguageLSP ServerFormatterLinter
TypeScript/JavaScriptts_lsprettiereslint_d
Pythonpyrightblack, isortpylint
Rustrust_analyzerrustfmtBuilt-in
Gogoplsgofumptgolangci-lint
C/C++clangdclang-formatcpplint
Lualua_lsstylualuacheck
HTMLhtmlprettier-
CSScsslsprettierstylelint
JSONjsonlsprettier-
YAMLyamllsprettier-
Markdownmarksmanprettiermarkdownlint

Build docs developers (and LLMs) love