mirror of
https://github.com/ray-x/navigator.lua
synced 2024-11-03 15:40:20 +00:00
mason support #215
This commit is contained in:
parent
967fd32bae
commit
348ab9dced
41
README.md
41
README.md
@ -278,6 +278,7 @@ require'navigator'.setup({
|
||||
-- refer to lua/navigator.lua for more icons setups
|
||||
},
|
||||
lsp_installer = false, -- set to true if you would like use the lsp installed by williamboman/nvim-lsp-installer
|
||||
mason = false, -- set to true if you would like use the lsp installed by williamboman/mason
|
||||
lsp = {
|
||||
enable = true, -- skip lsp setup if disabled make sure add require('navigator.lspclient.mapping').setup() in you
|
||||
-- own on_attach
|
||||
@ -502,18 +503,18 @@ The plugin can be loaded lazily (packer `opt = true` ), And it will check if opt
|
||||
|
||||
The terminal will need to be able to output nerdfont and emoji correctly. I am using Kitty with nerdfont (Victor Mono).
|
||||
|
||||
## Integrat with lsp_installer (williamboman/nvim-lsp-installer)
|
||||
## Integrat with mason (williamboman/mason.nvim) or lsp_installer (williamboman/nvim-lsp-installer, deprecated)
|
||||
|
||||
If you are using lsp_installer and would like to use the lsp servers installed by lsp_installer. Please set
|
||||
If you are using mason or lsp_installer and would like to use the lsp servers installed by lsp_installer. Please set
|
||||
|
||||
```lua
|
||||
lsp_installer = true
|
||||
|
||||
lsp_installer = true --lsp_installer users, deprecated
|
||||
mason = true -- mason user
|
||||
```
|
||||
|
||||
In the config. Also please setup the lsp server from installer setup with `server:setup{opts}`
|
||||
|
||||
example:
|
||||
lsp-installer example:
|
||||
```lua
|
||||
use({
|
||||
'williamboman/nvim-lsp-installer',
|
||||
@ -526,14 +527,40 @@ example:
|
||||
'ray-x/navigator.lua',
|
||||
config = function()
|
||||
require('navigator').setup({
|
||||
debug = true,
|
||||
lsp_installer = true,
|
||||
keymaps = { { key = 'gR', func = "require('navigator.reference').async_ref()" } },
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
```
|
||||
for mason
|
||||
```lua
|
||||
use("williamboman/mason.nvim")
|
||||
use({
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
config = function()
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup({})
|
||||
end,
|
||||
})
|
||||
|
||||
use({
|
||||
"ray-x/navigator.lua",
|
||||
requires = {
|
||||
{ "ray-x/guihua.lua", run = "cd lua/fzy && make" },
|
||||
{ "neovim/nvim-lspconfig" },
|
||||
{ "nvim-treesitter/nvim-treesitter" },
|
||||
},
|
||||
config = function()
|
||||
require("navigator").setup({
|
||||
mason = true,
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
Please refer to [lsp_installer_config](https://github.com/ray-x/navigator.lua/blob/master/playground/init_lsp_installer.lua)
|
||||
for more info
|
||||
|
@ -86,6 +86,7 @@ _NgConfigValues = {
|
||||
servers = {}, -- you can add additional lsp server so navigator will load the default for you
|
||||
},
|
||||
lsp_installer = false, -- set to true if you would like use the lsp installed by williamboman/nvim-lsp-installer
|
||||
mason = false, -- set to true if you would like use the lsp installed by williamboman/mason
|
||||
icons = {
|
||||
icons = true, -- set to false to use system default ( if you using a terminal does not have nerd/icon)
|
||||
-- Code action
|
||||
|
@ -72,6 +72,13 @@ require('navigator.lazyloader').load('lua-dev.nvim', 'folke/lua-dev.nvim')
|
||||
if _NgConfigValues.lsp_installer then
|
||||
require('navigator.lazyloader').load('nvim-lsp-installer', 'williamboman/nvim-lsp-installer')
|
||||
end
|
||||
|
||||
|
||||
if _NgConfigValues.mason then
|
||||
require('navigator.lazyloader').load('mason.nvim', 'williamboman/mason.nvim')
|
||||
require('navigator.lazyloader').load('mason-lspconfig.nvim', 'williamboman/mason-lspconfig.nvim')
|
||||
end
|
||||
|
||||
local ok, l = pcall(require, 'lua-dev')
|
||||
if ok and l then
|
||||
luadev = l.setup(luadevcfg)
|
||||
@ -372,6 +379,7 @@ local servers = {
|
||||
|
||||
local lsp_installer_servers = {}
|
||||
local has_lspinst = false
|
||||
local has_mason = false
|
||||
|
||||
if config.lsp_installer == true then
|
||||
has_lspinst, _ = pcall(require, 'nvim-lsp-installer')
|
||||
@ -384,6 +392,19 @@ if config.lsp_installer == true then
|
||||
end
|
||||
log(lsp_installer_servers)
|
||||
end
|
||||
|
||||
if config.mason == true then
|
||||
has_mason, _ = pcall(require, 'mason-lspconfig')
|
||||
if has_mason then
|
||||
local srvs=require'mason-lspconfig'.get_installed_servers()
|
||||
log('lsp_installered servers', srvs)
|
||||
if #srvs > 0 then
|
||||
lsp_installer_servers = srvs
|
||||
end
|
||||
end
|
||||
log(lsp_installer_servers)
|
||||
end
|
||||
|
||||
if config.lsp.disable_lsp == 'all' then
|
||||
config.lsp.disable_lsp = servers
|
||||
end
|
||||
@ -713,6 +734,35 @@ local function lsp_startup(ft, retry, user_lsp_opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
if has_mason and _NgConfigValues.mason then
|
||||
local servers = require'mason-lspconfig'.get_installed_servers()
|
||||
if not vim.tbl_contains(servers, lspconfig[lspclient].name) then
|
||||
log('mason server not installed', lspconfig[lspclient].name)
|
||||
return
|
||||
end
|
||||
local pkg_name = require "mason-lspconfig.mappings.server".lspconfig_to_package[lspconfig[lspclient].name]
|
||||
local pkg = require "mason-registry".get_package(pkg_name)
|
||||
|
||||
|
||||
log('lsp installer server config ' .. lspconfig[lspclient].name, pkg)
|
||||
if pkg then
|
||||
local path = pkg:get_install_path()
|
||||
if not path then
|
||||
-- for some reason lspinstaller does not install the binary, check default PATH
|
||||
log('lsp installer does not install the lsp in its path, fallback')
|
||||
return load_cfg(ft, lspclient, cfg, loaded)
|
||||
end
|
||||
|
||||
cfg.cmd = cfg.cmd or {}
|
||||
cfg.cmd[1] = path .. path_sep .. pkg.name
|
||||
if vfn.executable(cfg.cmd[1]) == 0 then
|
||||
log('failed to find cmd', cfg.cmd[1])
|
||||
else
|
||||
log('cmd installed', cfg.cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if vfn.executable(cfg.cmd[1]) == 0 then
|
||||
log('lsp server not installed in path ' .. lspclient .. vim.inspect(cfg.cmd), vim.lsp.log_levels.WARN)
|
||||
|
Loading…
Reference in New Issue
Block a user