ray-x / navigator.lua

Code analysis & navigation plugin for Neovim. Navigate codes like a breeze🎐 Exploring LSP and 🌲Treesitter symbols a piece of 🍰 Take control like a boss 🦍
MIT License
1.31k stars 58 forks source link

`lsp_installer = true` not works #131

Closed overcache closed 2 years ago

overcache commented 2 years ago

I installed tsserver via lsp_installer, and set lsp_installer = true in config, but no lsp-server launch.

content of packer config

  ...
    -- Packer can manage itself as an optional plugin
    use 'wbthomason/packer.nvim'

    -- Quality of life improvements
    use 'norcalli/nvim_utils'

    -- LSP
    use {
        'neovim/nvim-lspconfig',
        -- config = [[
        -- takeover by navigator
        --     require('config.lspconfig')
        -- ]]
    }
    use {
        'williamboman/nvim-lsp-installer',
    }
    use {
        'ray-x/navigator.lua',
        requires = {
            {
                'ray-x/guihua.lua',
                run = 'cd lua/fzy && make',
            },
        },
        config = [[require('config.navigator')]],
    }
    use {
        'onsails/lspkind-nvim',
        config = [[require('config.lspkind')]],
        after = 'nvim-lspconfig',
    }

    use 'folke/lsp-colors.nvim'

    use {
        'kosayoda/nvim-lightbulb',
        config = [[require('config.lightbulb')]],
        after = 'nvim-lspconfig',
    }
    ...

content of config:

local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require'navigator'.setup({
    debug = true,
    default_mapping = false,
    keymaps = {
        { key = 'gL', func = "require('navigator.diagnostics').show_diagnostics()" },
        { key = 'gG', func = "require('navigator.diagnostics').show_buf_diagnostics()" },
        { key = 'K', func = 'hover({ popup_opts = { border = single, max_width = 80 }})' },
        { key = '<leader>ca', mode = 'n', func = "require('navigator.codeAction').code_action()" },
        { key = '<leader>cA', mode = 'v', func = 'range_code_action()' },
        { key = '<leader>re', func = 'rename()' },
        { key = '<leader>rn', func = "require('navigator.rename').rename()" },
        { key = '<leader>dt', func = "require('navigator.diagnostics').toggle_diagnostics()" },
    },
    lsp_installer = true,
    lsp = {
        format_on_save = false,
        capabilities = capabilities,
        tsserver = {
            filetypes = {'typescript', 'javascript', 'jsx', 'tsx', 'typescriptreact', 'javascriptreact'},
        },
    },
    on_attach = function(client, bufnr)
        -- Mappings.
        local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
        local opts = { noremap=true, silent=true }
        if client.resolved_capabilities.document_formatting then
            buf_set_keymap("n", "<leader>lf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
        end
        if client.resolved_capabilities.document_range_formatting then
            buf_set_keymap("v", "<leader>lf", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
        end
    end,
    icons = {
        -- Code action
        code_action_icon = "💡",
    }
})

output of :LspPrintInstalled

['tsserver', 'jsonls']

output of :LspInfo

 Language client log: /Users/simon/.cache/nvim/lsp.log
 Detected filetype:   javascript

 0 client(s) attached to this buffer: 

 Configured servers list: tsserver, jsonls

everything works fine if I install tssever global with: npm i -g npm install -g typescript typescript-language-servertsserver

ray-x commented 2 years ago

This is expected behaviour. Once you setup lsp_installer=true navigator will not run setup for the LSP. You will need to setup those LSPs in lsp_installer setup function.

overcache commented 2 years ago

Sorry, I misunderstand the README:

Navigator will startup the server installed by lsp-installer. Please do not call server:setup{opts} from lsp installer as it will override the navigator setup

May I ask how to config lsp_installer without call server:setup{opts}? thanks

ray-x commented 2 years ago

Sorry, my README is confusing. I put some updates.

If you are using go with gopls, the setup will be look like this:

local path = require 'nvim-lsp-installer.path'
local install_root_dir = path.concat {vim.fn.stdpath 'data', 'lsp_servers'}

require'navigator'.setup({
  -- lsp_installer = false -- default value is false

  lsp = {
    gopls = {
      cmd = { install_root_dir .. '/go/gopls' }
    }
  }
}

Please check the lsp binary in your install_root_dir and update thecmd setup.

Alternatively, add those binary to PATH should also work.

overcache commented 2 years ago

Thanks, it works

I prefer config lsp_server in nvim-lsp-installer, so I dont need to config every server's cmd path.