init
This commit is contained in:
31
lua/lsp/golangci_lint_ls.lua
Normal file
31
lua/lsp/golangci_lint_ls.lua
Normal file
@ -0,0 +1,31 @@
|
||||
local M = {
|
||||
filetypes = { 'go', 'gomod' },
|
||||
}
|
||||
|
||||
-- disable lsp if wrong version installed
|
||||
function M.enable()
|
||||
local enable = true
|
||||
|
||||
if
|
||||
pcall(function()
|
||||
vim
|
||||
.system({ 'golangci-lint', '--version' }, { text = true }, function(out)
|
||||
if out.code ~= 0 then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
if out.stdout:match ' 1%.%d+%.%d+' then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
end)
|
||||
:wait()
|
||||
end)
|
||||
then
|
||||
return enable
|
||||
else
|
||||
return false -- disable if golangci-lint isn't available
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
53
lua/lsp/init.lua
Normal file
53
lua/lsp/init.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
local servers = {
|
||||
ts_ls = { filetypes = { 'javascript', 'typescript', 'javascriptreact', 'typescriptreact' } },
|
||||
gopls = { filetypes = { 'go', 'gomod' } },
|
||||
rust_analyzer = {
|
||||
filetypes = { 'rust' },
|
||||
settings = {
|
||||
['rust-analyzer'] = {
|
||||
check = {
|
||||
command = 'clippy',
|
||||
extraArgs = {
|
||||
'--',
|
||||
'-Dclippy::correctness',
|
||||
'-Wclippy::complexity',
|
||||
'-Wclippy::pedantic',
|
||||
'-Wclippy::perf',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
golangci_lint_ls = require 'lsp.golangci_lint_ls',
|
||||
erlangls = { cmd = { '/home/fergusmolloy/.local/bin/erlang_ls' }, filetypes = { 'erlang' } },
|
||||
elixirls = { cmd = { 'elixir-ls' }, filetypes = { 'elixir' } },
|
||||
lua_ls = require 'lsp.lua_ls',
|
||||
}
|
||||
|
||||
local on_attach = require 'lsp.on_attach'
|
||||
local lspconfig = require 'lspconfig'
|
||||
|
||||
for server, config in pairs(servers) do
|
||||
if require('lsp.utils').check_ft(server, config) then
|
||||
if config['enable'] then
|
||||
if not config['enable']() then
|
||||
vim.notify('Disabling language server ' .. server, vim.log.levels.WARN)
|
||||
goto continue
|
||||
end
|
||||
end
|
||||
else
|
||||
goto continue
|
||||
end
|
||||
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
|
||||
config.on_attach = require 'lsp.on_attach'
|
||||
vim.lsp.enable(server)
|
||||
vim.lsp.config(server, config)
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
34
lua/lsp/lua_ls.lua
Normal file
34
lua/lsp/lua_ls.lua
Normal file
@ -0,0 +1,34 @@
|
||||
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 = {
|
||||
-- Tell the language server which version of Lua you're using
|
||||
-- (most likely LuaJIT in the case of Neovim)
|
||||
version = 'LuaJIT',
|
||||
},
|
||||
-- Make the server aware of Neovim runtime files
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
library = {
|
||||
vim.env.VIMRUNTIME,
|
||||
-- Depending on the usage, you might want to add additional paths here.
|
||||
-- "${3rd}/luv/library"
|
||||
-- "${3rd}/busted/library",
|
||||
},
|
||||
-- or pull in all of 'runtimepath'. 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.api.nvim_get_runtime_file("", true)
|
||||
},
|
||||
})
|
||||
end,
|
||||
settings = {
|
||||
Lua = {},
|
||||
},
|
||||
filetypes = { 'lua' },
|
||||
}
|
||||
29
lua/lsp/on_attach.lua
Normal file
29
lua/lsp/on_attach.lua
Normal file
@ -0,0 +1,29 @@
|
||||
return function(client, bufnr)
|
||||
require('nvim-navbuddy').attach(client, bufnr)
|
||||
|
||||
local nmap = function(keys, func, desc)
|
||||
if desc then
|
||||
desc = 'LSP: ' .. desc
|
||||
end
|
||||
|
||||
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||
end
|
||||
|
||||
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
||||
nmap('gi', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
|
||||
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[N]ame')
|
||||
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||
nmap('K', vim.lsp.buf.hover, 'Hover docs')
|
||||
|
||||
-- Lesser used LSP functionality
|
||||
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||
nmap('<leader>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, '[W]orkspace [L]ist Folders')
|
||||
|
||||
nmap('<leader>e', vim.diagnostic.open_float, 'Open floating diagnostics')
|
||||
nmap('<leader>q', vim.diagnostic.setloclist, 'Open diagnostics list')
|
||||
end
|
||||
15
lua/lsp/utils.lua
Normal file
15
lua/lsp/utils.lua
Normal file
@ -0,0 +1,15 @@
|
||||
local M = {}
|
||||
function M.check_ft(server, config)
|
||||
if config.filetypes == nil or next(config.filetypes) == nil then
|
||||
return true -- if no filetypes specified then enable
|
||||
else
|
||||
config.server = server
|
||||
for _, ft in ipairs(config.filetypes) do
|
||||
if vim.bo[0].filetype == ft then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
return M
|
||||
Reference in New Issue
Block a user