VonHeikemen / lsp-zero.nvim

A starting point to setup some lsp related features in neovim.
https://lsp-zero.netlify.app/docs/
MIT License
3.83k stars 99 forks source link

ThePrimeagen Config doesn't ensure lua lsp install. #358

Closed dmambapoor closed 9 months ago

dmambapoor commented 10 months ago

I was following ThePrimeagen's 0 to LSP : Neovim RC From Scratch. I created a lsp.lua file as instructed, and I noticed my jump to definition was not working on lua files. After making the following changes to lsp.lua, my jump to definition was working.

require('mason-lspconfig').setup({
  -- ensure_installed = {'tsserver', 'rust_analyzer'},
 ensure_installed = {'tsserver', 'rust_analyzer', 'lua_ls'},
-- ^change: added lua_ls
  handlers = {
    lsp_zero.default_setup,
    lua_ls = function()
      local lua_opts = lsp_zero.nvim_lua_ls()
      require('lspconfig').lua_ls.setup(lua_opts)
    end,
  }
})

System: Ubuntu 22.04.3 (minimal installation) Plugin Manager: Packer LSP-Zero packer.lua:

-- This file can be loaded by calling `lua require('plugins')` from your init.vim

-- Only required if you have packer configured as `opt`
vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'
  use {
      'nvim-telescope/telescope.nvim', tag = '0.1.5',
      -- or                            , branch = '0.1.x',
      requires = { {'nvim-lua/plenary.nvim'} }
  }
  use { "ellisonleao/gruvbox.nvim", as = 'gruvbox', config = function() vim.cmd('colorscheme gruvbox') end}
  use {'nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'} }
  use {'nvim-treesitter/playground'}
  use { 'theprimeagen/harpoon' }
  use { '/mbbill/undotree' }
  use { 'tpope/vim-fugitive' }
  use {
      'VonHeikemen/lsp-zero.nvim',
      branch = 'v3.x',
      requires = {
          --- Uncomment these if you want to manage LSP servers from neovim
          {'williamboman/mason.nvim'},
          {'williamboman/mason-lspconfig.nvim'},

          -- LSP Support
          {'neovim/nvim-lspconfig'},
          -- Autocompletion
          {'hrsh7th/nvim-cmp'},
          {'hrsh7th/cmp-nvim-lsp'},
          {'L3MON4D3/LuaSnip'},
      }
  }
end)
VonHeikemen commented 10 months ago

You are missing the comma at the end of the list in ensure_installed.

dmambapoor commented 10 months ago

Hi, the comma was in my lua.lsp, I just accidentally deleted it when making the issue. I've edited the original issue comment to reflect the comma.

VonHeikemen commented 10 months ago

Ok. Maybe there is an error during installation. Try installing manually using the command :LspInstall lua_ls and see if you get an error message.

dmambapoor commented 10 months ago

It worked without errors.

"lua-language-server" was successfully installed.
dmambapoor commented 10 months ago

I did the following:

It does not seem to automatically install lua_ls without specifying it in ensure_installed.

VonHeikemen commented 10 months ago

Language servers rarely work as expected right after installation. You need to restart neovim for them to work correctly. And if your "go to definition" doesn't work, you should check the root directory is correct, using the command :LspInfo.