Overview
The null-ls configuration is located inlua/user/lsp/null-ls.lua and provides:
- Code formatting via external tools
- Diagnostics from linters
- Code actions
- Hover information
Configuration
Basic Setup
lua/user/lsp/null-ls.lua:1
Configured Tools
Formatters
Prettier
JavaScript/TypeScript/CSS/HTML/JSON formatter:lua/user/lsp/null-ls.lua:14
- JavaScript (.js, .jsx)
- TypeScript (.ts, .tsx)
- JSON, CSS, HTML, Markdown
- YAML, GraphQL
Black
Python code formatter:lua/user/lsp/null-ls.lua:15
--fast: Skip sanity checks for faster formatting
Stylua
Lua code formatter:lua/user/lsp/null-ls.lua:16
- Consistent Lua formatting
- Configurable via
.stylua.toml
Diagnostics (Optional)
lua/user/lsp/null-ls.lua:17
Using Formatters
Format Current Buffer
<leader>lf
Format on Save (Optional)
Add tolua/user/lsp/null-ls.lua:
Adding New Formatters
Step 1: Install the Tool
Install via Mason or system package manager:Step 2: Add to Sources
Editlua/user/lsp/null-ls.lua:13:
Step 3: Configure Options (Optional)
Adding Linters
Available Diagnostic Sources
Common linters available in null-ls:Example: Adding ESLint
lua/user/lsp/null-ls.lua
Formatting vs LSP Formatting
Null-ls is preferred for formatting because:- More Control: Configure formatter options precisely
- Consistency: Same formatter used in editor and CI/CD
- Performance: Formatters are often faster than LSP
Disabling LSP Formatting
Inlua/user/lsp/handlers.lua:75, specific LSP servers have formatting disabled:
Troubleshooting
Formatter Not Working
-
Check if tool is installed:
-
Enable debug mode:
-
Check null-ls log:
Format Command Not Found
Ensure LSP is attached:Conflicting Formatters
If multiple formatters claim the same filetype:Configuration Files
Prettier
Create.prettierrc in project root:
Black
Createpyproject.toml:
Stylua
Create.stylua.toml:
Advanced Configuration
Conditional Formatting
Only format if config file exists:Custom Sources
Create a custom null-ls source:Related Pages
LSP Handlers
Configure LSP keybindings and behavior
Mason Setup
Install formatters and linters

