Skip to content

Commit

Permalink
refactor-lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheavni committed Apr 18, 2024
1 parent 234f4c2 commit c759f63
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 142 deletions.
80 changes: 4 additions & 76 deletions .config/nvim/lua/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,15 @@ local M = {
'neovim/nvim-lspconfig',
event = { 'BufReadPre', 'BufNewFile' },
opts = {
inlay_hints = { enabled = true },
setup = {
tsserver = function(_, opts)
require('typescript').setup {
server = opts,
}
return true
end,

helm_ls = function()
local configs = require 'lspconfig.configs'
local util = require 'lspconfig.util'

if not configs.helm_ls then
configs.helm_ls = {
default_config = {
cmd = { 'helm_ls', 'serve' },
filetypes = { 'helm', 'gotmpl' },
root_dir = function(fname)
return util.root_pattern 'Chart.yaml'(fname)
end,
},
}
end
end,
docker_compose_language_service = function() end,
},
},
}

M.init = require('user.lsp.config').init

M.config = function()
require('user.lsp.config').setup()
-- local function setup(server)
-- local server_opts = vim.tbl_deep_extend('force', {
-- capabilities = vim.deepcopy(capabilities),
-- }, servers[server] or {})
--
-- if opts.setup[server] then
-- if opts.setup[server](server, server_opts) then
-- return
-- end
-- elseif opts.setup['*'] then
-- if opts.setup['*'](server, server_opts) then
-- return
-- end
-- end
-- require('lspconfig')[server].setup(server_opts)
-- end

-- get all the servers that are available thourgh mason-lspconfig
-- local have_mason, mlsp = pcall(require, 'mason-lspconfig')
-- local all_mslp_servers = {}
-- if have_mason then
-- all_mslp_servers = vim.tbl_keys(require('mason-lspconfig.mappings.server').lspconfig_to_package)
-- end
--
-- local ensure_installed = {} ---@type string[]
-- for server, server_opts in pairs(servers) do
-- if server_opts then
-- server_opts = server_opts == true and {} or server_opts
-- -- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
-- if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then
-- setup(server)
-- else
-- ensure_installed[#ensure_installed + 1] = server
-- end
-- end
-- end
--
-- if have_mason then
-- mlsp.setup { ensure_installed = ensure_installed, handlers = { setup } }
-- end
end
M.config = require('user.lsp.config').setup

M.dependencies = {
'nvimtools/none-ls.nvim',
Expand Down Expand Up @@ -152,10 +86,7 @@ M.dependencies = {
}

local language_specific_plugins = {
{
'mfussenegger/nvim-jdtls',
ft = { 'java' },
},
{ 'mfussenegger/nvim-jdtls', ft = 'java' },
{
'jose-elias-alvarez/typescript.nvim',
ft = { 'typescript', 'typescriptreact', 'typescript.tsx', 'javascript' },
Expand All @@ -180,7 +111,7 @@ local language_specific_plugins = {
},
{
'someone-stole-my-name/yaml-companion.nvim',
ft = { 'yaml' },
ft = 'yaml',
config = function()
local nnoremap = require('user.utils').nnoremap
nnoremap('<leader>cc', ":lua require('yaml-companion').open_ui_select()<cr>", true)
Expand All @@ -191,10 +122,7 @@ local language_specific_plugins = {
})
end,
},
{
'b0o/SchemaStore.nvim',
ft = { 'yaml' },
},
{ 'b0o/SchemaStore.nvim', ft = 'yaml' },
}

return {
Expand Down
22 changes: 5 additions & 17 deletions .config/nvim/lua/user/lsp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ M.setup_capabilities = function()
------------------
-- Capabilities --
------------------
M.capabilities = vim.tbl_deep_extend(
'force',
{},
vim.lsp.protocol.make_client_capabilities(),
-- TODO: fix cmp capabilities
has_cmp and cmp_nvim_lsp.default_capabilities() or {},
M.capabilities or {}
)
local cmp_default_capabilities = require('cmp_nvim_lsp').default_capabilities()

M.capabilities = vim.tbl_deep_extend('force', vim.lsp.protocol.make_client_capabilities(), cmp_default_capabilities, M.capabilities or {}, {})
end

M.diagnostics = function()
Expand All @@ -62,13 +57,6 @@ M.diagnostics = function()
}
end

M.get_mason_lspconfig = function()
local have_mason, _ = pcall(require, 'mason-lspconfig')
if have_mason then
M.all_mason_lsp_servers = vim.tbl_keys(require('mason-lspconfig.mappings.server').lspconfig_to_package)
end
end

M.init = function()
local start_ls = function()
_G.tmp_write { should_delete = false, new = false }
Expand Down Expand Up @@ -99,8 +87,8 @@ M.setup = function()
-- set up diagnostics configuration
M.diagnostics()

-- get all the servers that are available thourgh mason-lspconfig
M.get_mason_lspconfig()
-- set up mason to install lsp servers
require('mason-lspconfig').setup { automatic_installation = true }

-- setup lsp servers
require('user.lsp.servers').setup()
Expand Down
22 changes: 7 additions & 15 deletions .config/nvim/lua/user/lsp/on-attach.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,20 @@ local default_on_attach = function(client, bufnr)
command = 'silent! lua vim.lsp.buf.clear_references()',
})
end
-- local diagnostic_pop = augroup 'DiagnosticPop'
-- autocmd('CursorHold', {
-- buffer = bufnr,
-- group = diagnostic_pop,
-- callback = function()
-- vim.diagnostic.open_float(nil, {
-- focusable = false,
-- close_events = { 'BufLeave', 'CursorMoved', 'InsertEnter', 'FocusLost' },
-- border = 'rounded',
-- source = 'always',
-- prefix = ' ',
-- scope = 'cursor',
-- })
-- end,
-- })

----------------------------------
-- Enable tag jump based on LSP --
----------------------------------
if client.server_capabilities.goto_definition then
vim.api.nvim_set_option_value('tagfunc', 'v:lua.vim.lsp.tagfunc', { buf = bufnr })
end

-----------------
-- Inlay Hints --
-----------------
if client.server_capabilities.inlayHintProvider then
vim.lsp.inlay_hint.enable(bufnr, true)
end
end

local minimal_on_attach = function(_, bufnr)
Expand Down
102 changes: 68 additions & 34 deletions .config/nvim/lua/user/lsp/servers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,53 @@ local M = {}
M.setup = function()
local on_attaches = require 'user.lsp.on-attach'
local default_on_attach = on_attaches.default
local capabilities = require('user.lsp.config').capabilities
local configs = require 'lspconfig.configs'
local util = require 'lspconfig.util'

require('lspconfig')['ansiblels'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['bashls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['cssls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['cssmodules_ls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['dockerls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['docker_compose_language_service'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['groovyls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['html'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['jsonls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
settings = {
json = {
trace = {
Expand All @@ -49,6 +62,7 @@ M.setup = function()

require('lspconfig')['pyright'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
settings = {
organizeimports = {
provider = 'isort',
Expand All @@ -58,6 +72,7 @@ M.setup = function()

require('lspconfig')['lua_ls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
settings = {
Lua = {
runtime = {
Expand Down Expand Up @@ -90,63 +105,81 @@ M.setup = function()
default_on_attach(c, b)
c.server_capabilities.semanticTokensProvider = {}
end,
}

require('lspconfig')['tsserver'].setup {
settings = {
preferences = {
allowRenameOfImportPath = true,
disableSuggestions = false,
importModuleSpecifierEnding = 'auto',
importModuleSpecifierPreference = 'non-relative',
includeCompletionsForImportStatements = true,
includeCompletionsForModuleExports = true,
quotePreference = 'single',
},
-- specify some or all of the following settings if you want to adjust the default behavior
javascript = {
inlayHints = {
includeInlayEnumMemberValueHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all';
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayVariableTypeHints = true,
capabilities = capabilities,
}

require('typescript').setup {
server = {
settings = {
preferences = {
allowRenameOfImportPath = true,
disableSuggestions = false,
importModuleSpecifierEnding = 'auto',
importModuleSpecifierPreference = 'non-relative',
includeCompletionsForImportStatements = true,
includeCompletionsForModuleExports = true,
quotePreference = 'single',
},
},
typescript = {
inlayHints = {
includeInlayEnumMemberValueHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all';
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayVariableTypeHints = true,
-- specify some or all of the following settings if you want to adjust the default behavior
javascript = {
inlayHints = {
includeInlayEnumMemberValueHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all';
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayVariableTypeHints = true,
},
},
typescript = {
inlayHints = {
includeInlayEnumMemberValueHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all';
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayVariableTypeHints = true,
},
},
},
on_attach = default_on_attach,
capabilities = capabilities,
},
on_attach = default_on_attach,
}

require('lspconfig')['vimls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

require('lspconfig')['jdtls'].setup {
on_attach = function(c, b)
require('jdtls').setup_dap()
default_on_attach(c, b)
end,
capabilities = capabilities,
settings = {
filetypes = { 'kotlin', 'java' },
workspace = { checkThirdParty = false },
},
}

if not configs.helm_ls then
configs.helm_ls = {
default_config = {
cmd = { 'helm_ls', 'serve' },
filetypes = { 'helm', 'gotmpl' },
root_dir = function(fname)
return util.root_pattern 'Chart.yaml'(fname)
end,
},
}
end
require('lspconfig')['helm_ls'].setup {
on_attach = default_on_attach,
capabilities = capabilities,
}

local yaml_cfg = require('yaml-companion').setup {
Expand All @@ -167,6 +200,7 @@ M.setup = function()
end
default_on_attach(c, b)
end,
capabilities = capabilities,
},
}
require('lspconfig')['yamlls'].setup(yaml_cfg)
Expand Down

0 comments on commit c759f63

Please sign in to comment.