setup: config lsp & nvim-lspconfig
- add registries to mason.nvim. - set a table for `Langs.lsp`. - extract `lua_ls` config into `after/lsp` directory.
This commit is contained in:
parent
1c8bed24cd
commit
17ab7642dd
|
|
@ -0,0 +1,38 @@
|
||||||
|
return {
|
||||||
|
on_init = function(client)
|
||||||
|
if client.workspace_folders then
|
||||||
|
local path = client.workspace_folders[1].name
|
||||||
|
if
|
||||||
|
path ~= vim.fn.stdpath 'config'
|
||||||
|
and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc'))
|
||||||
|
then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
|
||||||
|
runtime = {
|
||||||
|
version = 'LuaJIT',
|
||||||
|
path = {
|
||||||
|
'lua/?.lua',
|
||||||
|
'lua/?/init.lua',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
workspace = {
|
||||||
|
checkThirdParty = false,
|
||||||
|
library = {
|
||||||
|
vim.env.VIMRUNTIME,
|
||||||
|
},
|
||||||
|
-- -- NOTE: this is a lot slower and will cause issues when working on your own configuration.
|
||||||
|
-- -- See https://github.com/neovim/nvim-lspconfig/issues/3189
|
||||||
|
-- library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), {
|
||||||
|
-- '${3rd}/luv/library',
|
||||||
|
-- '${3rd}/busted/library',
|
||||||
|
-- }),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
settings = {
|
||||||
|
Lua = {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,32 @@ vim.g.have_nerd_font = false
|
||||||
-- Configs for Programming Languages
|
-- Configs for Programming Languages
|
||||||
-- like LSPs, Tree-sitters, Linters, Fromatters, Debuggers, etc.
|
-- like LSPs, Tree-sitters, Linters, Fromatters, Debuggers, etc.
|
||||||
Langs = {
|
Langs = {
|
||||||
|
lsp = {
|
||||||
|
'bashls',
|
||||||
|
'clangd',
|
||||||
|
'elmls',
|
||||||
|
'gopls',
|
||||||
|
'harper_ls',
|
||||||
|
'html',
|
||||||
|
'intelephense',
|
||||||
|
'just',
|
||||||
|
'laravel_ls',
|
||||||
|
'lua_ls',
|
||||||
|
'markdown_oxide',
|
||||||
|
'marksman',
|
||||||
|
'omnisharp',
|
||||||
|
'phpactor',
|
||||||
|
'pyrefly',
|
||||||
|
'roslyn_ls',
|
||||||
|
'stylua',
|
||||||
|
'superhtml',
|
||||||
|
'svelte',
|
||||||
|
'tailwindcss',
|
||||||
|
'ts_ls',
|
||||||
|
'zls',
|
||||||
|
-- 'fsautocomplete',
|
||||||
|
},
|
||||||
|
|
||||||
treesitter = {
|
treesitter = {
|
||||||
'bash',
|
'bash',
|
||||||
'c',
|
'c',
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,12 @@ return {
|
||||||
---@module 'mason.settings'
|
---@module 'mason.settings'
|
||||||
---@type MasonSettings
|
---@type MasonSettings
|
||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
opts = {},
|
opts = {
|
||||||
|
registries = {
|
||||||
|
'github:Crashdummyy/mason-registry',
|
||||||
|
'github:mason-org/mason-registry',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
-- Maps LSP server names between nvim-lspconfig and Mason package names.
|
-- Maps LSP server names between nvim-lspconfig and Mason package names.
|
||||||
'mason-org/mason-lspconfig.nvim',
|
'mason-org/mason-lspconfig.nvim',
|
||||||
|
|
@ -123,72 +128,51 @@ return {
|
||||||
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
||||||
-- See `:help lsp-config` for information about keys and how to configure
|
-- See `:help lsp-config` for information about keys and how to configure
|
||||||
---@type table<string, vim.lsp.Config>
|
---@type table<string, vim.lsp.Config>
|
||||||
local servers = {
|
-- local servers = {
|
||||||
-- clangd = {},
|
-- -- clangd = {},
|
||||||
-- gopls = {},
|
-- -- gopls = {},
|
||||||
-- pyright = {},
|
-- -- pyright = {},
|
||||||
-- rust_analyzer = {},
|
-- -- rust_analyzer = {},
|
||||||
|
-- --
|
||||||
|
-- -- Some languages (like typescript) have entire language plugins that can be useful:
|
||||||
|
-- -- https://github.com/pmizio/typescript-tools.nvim
|
||||||
|
-- --
|
||||||
|
-- -- But for many setups, the LSP (`ts_ls`) will work just fine
|
||||||
|
-- -- ts_ls = {},
|
||||||
--
|
--
|
||||||
-- Some languages (like typescript) have entire language plugins that can be useful:
|
-- stylua = {}, -- Used to format Lua code
|
||||||
-- https://github.com/pmizio/typescript-tools.nvim
|
|
||||||
--
|
--
|
||||||
-- But for many setups, the LSP (`ts_ls`) will work just fine
|
-- -- Special Lua Config, as recommended by neovim help docs
|
||||||
-- ts_ls = {},
|
-- lua_ls = {},
|
||||||
|
-- }
|
||||||
|
|
||||||
stylua = {}, -- Used to format Lua code
|
local servers = Langs.lsp
|
||||||
|
|
||||||
-- Special Lua Config, as recommended by neovim help docs
|
-- -- NOTE: I won't be using `mason-tool-installer` to auto-install tools for now.
|
||||||
lua_ls = {
|
-- --
|
||||||
on_init = function(client)
|
-- -- Ensure the servers and tools above are installed
|
||||||
if client.workspace_folders then
|
-- --
|
||||||
local path = client.workspace_folders[1].name
|
-- -- To check the current status of installed tools and/or manually install
|
||||||
if
|
-- -- other tools, you can run
|
||||||
path ~= vim.fn.stdpath 'config'
|
-- -- :Mason
|
||||||
and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc'))
|
-- --
|
||||||
then
|
-- -- You can press `g?` for help in this menu.
|
||||||
return
|
-- local ensure_installed = vim.tbl_keys(servers or {})
|
||||||
end
|
-- vim.list_extend(ensure_installed, {
|
||||||
end
|
-- -- You can add other tools here that you want Mason to install
|
||||||
|
-- })
|
||||||
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
|
|
||||||
runtime = {
|
|
||||||
version = 'LuaJIT',
|
|
||||||
path = { 'lua/?.lua', 'lua/?/init.lua' },
|
|
||||||
},
|
|
||||||
workspace = {
|
|
||||||
checkThirdParty = false,
|
|
||||||
-- NOTE: this is a lot slower and will cause issues when working on your own configuration.
|
|
||||||
-- See https://github.com/neovim/nvim-lspconfig/issues/3189
|
|
||||||
library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), {
|
|
||||||
'${3rd}/luv/library',
|
|
||||||
'${3rd}/busted/library',
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
settings = {
|
|
||||||
Lua = {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Ensure the servers and tools above are installed
|
|
||||||
--
|
--
|
||||||
-- To check the current status of installed tools and/or manually install
|
-- require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
||||||
-- other tools, you can run
|
|
||||||
-- :Mason
|
|
||||||
--
|
|
||||||
-- You can press `g?` for help in this menu.
|
|
||||||
local ensure_installed = vim.tbl_keys(servers or {})
|
|
||||||
vim.list_extend(ensure_installed, {
|
|
||||||
-- You can add other tools here that you want Mason to install
|
|
||||||
})
|
|
||||||
|
|
||||||
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
|
||||||
|
|
||||||
for name, server in pairs(servers) do
|
for name, server in pairs(servers) do
|
||||||
|
if string.match(name, '^%d+$') then
|
||||||
|
-- name is actually an index, and the server doesn't provide any additional config.
|
||||||
|
vim.lsp.enable(server)
|
||||||
|
else
|
||||||
|
-- name is an actual name, and the server provides additional config.
|
||||||
vim.lsp.config(name, server)
|
vim.lsp.config(name, server)
|
||||||
vim.lsp.enable(name)
|
vim.lsp.enable(name)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue