The starter configuration uses nvim-cmp for autocompletion and nvim-lspconfig for LSP support. While the initial setup includes these plugins, it doesn't configure any specific language servers by default. This is why autocomplete and other LSP features might not be working for your specific language. Let's fix that.
Here's a breakdown of what needs to be done and how to do it:
Install Language Servers: You'll need a language server for the language you're working with. The starter project utilizes mason.nvim for managing LSP servers. In your lua/plugins/example.lua file (or your equivalent custom plugin configuration), you'll see a section for williamboman/mason.nvim. Add the language servers you need to the ensure_installed list. For example, for Python and TypeScript, you'd add:
After adding these, restart Neovim or run :MasonInstall to install the servers.
Configure nvim-lspconfig: Next, tell nvim-lspconfig to load and configure these servers. Within the same lua/plugins/example.lua file, locate the neovim/nvim-lspconfig section. In the servers table, add entries for the servers you installed:
This minimal configuration will load the servers. For more advanced configuration (like keybindings, formatting, etc.), refer to the nvim-lspconfig documentation and the example provided in lua/plugins/example.lua under the "add tsserver and setup with typescript.nvim instead of lspconfig" comment. The example shows how to configure tsserver using typescript.nvim and provides hints for custom LSP server setups.
(Optional) Configure nvim-cmp:nvim-cmp should automatically work with nvim-lspconfig. However, you might want to add other completion sources. The lua/plugins/example.lua file also shows how to add cmp-emoji as a source. You can find more details and examples in the nvim-cmp documentation.
Check Your lazy.lua Configuration: Ensure that your lazy.lua file correctly imports the plugins table from the lua/plugins directory. The default configuration should handle this correctly:
lua
require("lazy").setup({
spec = {
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "plugins" }, -- This line imports your custom plugins
},
-- ... rest of the configuration
})
Troubleshooting:
No Autocompletion: If you've installed the server and configured nvim-lspconfig, but autocompletion still isn't working, check if the language server is attached to the current buffer. You can usually see this in the status line or by running the :LspInfo command.
Errors: Look for errors in the Neovim logs (:messages). This can help pinpoint configuration issues or problems with the language server.
Restart: Sometimes a restart of Neovim is required after installing new plugins or making configuration changes.
By following these steps, you should have LSP and autocompletion working in your Neovim setup. Remember to consult the documentation for nvim-lspconfig, nvim-cmp, and your specific language server for more advanced configuration options.