Overview
The LSP and completion system consists of:- nvim-lspconfig: LSP client configuration
- mason.nvim: LSP server installation manager
- nvim-cmp: Completion engine
- LuaSnip: Snippet engine
- Multiple completion sources: LSP, buffer, path, snippets
- lspkind: VSCode-like completion icons
Completion Engine: nvim-cmp
nvim-cmp is the powerful autocompletion engine that provides intelligent suggestions as you type.Features
- Multiple Sources: Combines LSP, snippets, buffer text, and file paths
- Smart Sorting: Prioritizes relevant completions
- Preview: Shows documentation for completion items
- Snippet Support: Expands and navigates snippets
- LSP Integration: Full support for LSP capabilities
Completion Sources
Magictt uses these completion sources in priority order:- nvim_lsp: Completions from language servers
- luasnip: Snippet completions
- buffer: Text from current buffer
- path: Filesystem paths
Keybindings
In Completion Menu
| Keybinding | Action |
|---|---|
<C-k> | Previous completion item |
<C-j> | Next completion item |
<C-b> | Scroll documentation up |
<C-f> | Scroll documentation down |
<C-Space> | Trigger completion manually |
<C-e> | Close completion menu |
<CR> | Confirm selected item |
Completion Behavior
- menu: Show popup menu
- menuone: Show menu even for single match
- preview: Show preview window with documentation
- noselect: Don’t auto-select first item
Configuration
Location:lua/magictt/plugins/nvim-cmp.lua
Snippet Engine: LuaSnip
LuaSnip is a modern snippet engine that powers snippet expansion in completion.Features
- VSCode Snippets: Compatible with VSCode snippet format
- Dynamic Snippets: Snippets can execute Lua code
- Snippet Navigation: Tab through snippet placeholders
- Friendly Snippets: Includes large snippet library
Snippet Sources
- friendly-snippets: Community-maintained snippet collection
- Snippets for 50+ languages
- Common patterns and boilerplate
- Framework-specific snippets (React, Vue, etc.)
Usage
- Start typing snippet trigger
- Snippet appears in completion menu
- Press
<CR>to expand - Tab through placeholders
- Finish editing snippet
Example Snippets
JavaScript/TypeScript:log→console.log()cl→console.log()fn→ function declarationafn→ arrow functionimp→ import statement
def→ function definitionclass→ class definitionif→ if statementfor→ for loop
!→ HTML5 boilerplatediv→<div></div>link→<link>tag
Completion Icons: lspkind
lspkind adds VSCode-like pictograms to completion items, making it easy to identify item types.Icon Types
- Method
- Function
- Variable
- Class
- ⌘ Keyword
- Snippet
- File
- Folder
Format
Magictt usessymbol_text mode:
Completion Sources
LSP Source (cmp-nvim-lsp)
Provides completions from language servers:- Function and method names
- Variable names
- Class and interface names
- Keywords
- Import suggestions
Buffer Source (cmp-buffer)
Provides completions from text in the current buffer:- Words you’ve already typed
- Variable names in current file
- Useful when LSP isn’t available
Path Source (cmp-path)
Provides filesystem path completions:- File paths
- Directory paths
- Relative and absolute paths
Snippet Source (cmp_luasnip)
Provides snippet completions:- Pre-defined snippets
- Custom snippets
- Framework-specific patterns
LSP Configuration: nvim-lspconfig
nvim-lspconfig provides configurations for Neovim’s built-in LSP client.Features
- Go to Definition: Jump to symbol definitions
- Find References: Find all references to a symbol
- Hover Documentation: Show documentation for symbol under cursor
- Code Actions: Quick fixes and refactorings
- Diagnostics: Real-time error and warning detection
- Auto-format: Format code on save
Auto-format on Save
Magictt auto-formats JavaScript and TypeScript files:Configuration
Location:lua/magictt/plugins/lsp/lsp.lua
Package Manager: mason.nvim
mason.nvim is a portable package manager for LSP servers, formatters, and linters.Features
- Easy Installation: Install servers with simple commands
- Cross-platform: Works on Windows, macOS, and Linux
- Auto-install: Can automatically install configured servers
- Version Management: Install specific versions of tools
UI Commands
| Command | Action |
|---|---|
:Mason | Open Mason UI |
:MasonUpdate | Update registry |
:MasonInstall <package> | Install a package |
:MasonUninstall <package> | Uninstall a package |
UI Icons
- ✓ Package installed
- ➜ Package pending installation
- ✗ Package not installed
Configuration
Location:lua/magictt/plugins/lsp/mason.lua
Mason LSP Config: mason-lspconfig.nvim
mason-lspconfig bridges mason.nvim with nvim-lspconfig for seamless server setup.Auto-installed Servers
Magictt automatically installs these language servers:| Server | Language |
|---|---|
| ts_ls | TypeScript/JavaScript |
| html | HTML |
| cssls | CSS |
| tailwindcss | Tailwind CSS |
| svelte | Svelte |
| lua_ls | Lua |
| graphql | GraphQL |
| emmet_ls | Emmet (HTML/CSS expansion) |
| prismals | Prisma ORM |
| pyright | Python |
| eslint | ESLint (JavaScript linting) |
Configuration
Mason Tool Installer: mason-tool-installer.nvim
mason-tool-installer automatically installs formatters and linters.Auto-installed Tools
| Tool | Purpose |
|---|---|
| prettier | Formatter for JS/TS/HTML/CSS/JSON |
| stylua | Lua formatter |
| isort | Python import sorter |
| black | Python formatter |
| pylint | Python linter |
| eslint_d | Fast ESLint daemon |
Configuration
Additional LSP Features
LSP File Operations
nvim-lsp-file-operations notifies LSP servers when files are renamed or moved in nvim-tree.- Auto-updates imports when files move
- Keeps project references in sync
- Works seamlessly with nvim-tree
Lua Development: lazydev.nvim
lazydev.nvim provides better Lua development for Neovim configuration.- Neovim API completions
- Plugin API completions
- Better type checking for Neovim Lua
How Completion Works
The Flow
- Type in Insert Mode
- nvim-cmp monitors your typing
- Sources Queried
- LSP asked for completions
- LuaSnip checks for matching snippets
- Buffer scanned for matching text
- Filesystem checked for path completions
- Results Combined
- All sources return their results
- Results ranked by relevance
- Icons added by lspkind
- Menu Displayed
- Completion menu appears
- Navigate with
<C-j>/<C-k> - Documentation shown in preview window
- Completion Confirmed
- Press
<CR>to confirm - Text inserted at cursor
- If snippet, placeholders activated
- Press
Keybindings Summary
Completion
| Keybinding | Action |
|---|---|
<C-Space> | Trigger completion |
<C-j> | Next item |
<C-k> | Previous item |
<C-f> | Scroll docs down |
<C-b> | Scroll docs up |
<CR> | Confirm selection |
<C-e> | Close menu |
LSP (defined elsewhere)
| Keybinding | Action |
|---|---|
gd | Go to definition |
gr | Go to references |
K | Hover documentation |
<leader>ca | Code actions |
<leader>rn | Rename symbol |
Troubleshooting
Completion Not Working
- Check LSP is attached:
:LspInfo - Check sources are configured:
:CmpStatus - Verify server is installed:
:Mason
Missing Snippets
- Ensure friendly-snippets is installed
- Check LuaSnip loaded:
:lua print(require('luasnip').get_snippets())
Server Not Starting
- Open Mason:
:Mason - Install server if missing
- Check logs:
:LspLog
Customization
Add More LSP Servers
Editlua/magictt/plugins/lsp/mason.lua:
Change Completion Keybindings
Editlua/magictt/plugins/nvim-cmp.lua:
Add Custom Snippets
Create~/.config/nvim/snippets/<filetype>.json:
Related Documentation
Plugin Overview
See all installed plugins
Keybindings
Complete keybinding reference