Skip to content

Commit

Permalink
fix(nvim): Move LSP config after plugin installation, add note for fi…
Browse files Browse the repository at this point in the history
…rst-time open
  • Loading branch information
Ziwi01 committed May 6, 2023
1 parent f46b8c0 commit 2345e26
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Additionally, I setup the plugins below:
- [catpuccin/nvim](https://github.com/catppuccin/nvim) - Colorscheme
- [ggandor/leap.nvim](https://github.com/ggandor/leap.nvim) - Jump around the buffer like crazy

In LunarVIM there is an automatic LSP installer plugin - [Mason.nvim](https://github.com/williamboman/mason.nvim) which will install supported language servers and use them, when you open a specific filetype. This should work out of the box in most cases, however for Puppet I setup the LSP server manually, as it doesn't work with RVM by default. Also Ansible gets linter configuration override.
**NOTE**: In LunarVIM there is an automatic LSP installer plugin - [Mason.nvim](https://github.com/williamboman/mason.nvim) which will install supported language servers and use them, when you open a specific filetype. Unfortunately, Mason will perform an installation when opening any file, so after first provisioning, opening plain VIM (without specifying a file) will produce LSP errors. After opening any file, it will install required LSP servers and after VIM restart, it should work fine from now on.

### Other software

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO

- [ ] fix(neovim): Mason errors when opening VIM for the first time after new installation.
- [ ] fix(playbooks): Analyze shell commands and add missing changed_when/failed_when directives
- [ ] feat(neovim): Add Vimux keymaps (Telescope?), document usage.
- [ ] feat(neovim): Integrate DirDiff with Nvim Tree, introduce simple shortcuts/marks for diffing two directories.
Expand Down
178 changes: 85 additions & 93 deletions ansible/roles/config/files/lvim-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,99 +44,6 @@ lvim.builtin.treesitter.ensure_installed = {
lvim.builtin.treesitter.ignore_install = { "haskell" }
lvim.builtin.treesitter.highlight.enabled = true

-- Debug LSP servers

-- vim.lsp.set_log_level 'debug'
-- require('vim.lsp.log').set_format_func(vim.inspect)

-- generic LSP settings

-- ---@usage disable automatic installation of servers
-- lvim.lsp.automatic_servers_installation = false

-- ---configure a server manually. !!Requires `:LvimCacheReset` to take effect!!
-- ---see the full default list `:lua print(vim.inspect(lvim.lsp.automatic_configuration.skipped_servers))`
lvim.lsp.installer.setup.ensure_installed = { "pyright", "jsonls", "yamlls", "bashls", "puppet", "ansiblels", "marksman", "tflint", "terraformls", "azure_pipelines_ls", "dockerls" }

local puppet_opts = {
cmd = {
vim.env.HOME .. "/.rvm/rubies/default/bin/ruby",
vim.env.HOME .. "/.lsp/puppet-editor-services/puppet-languageserver",
"--stdio",
"--puppet-settings=--modulepath," .. vim.env.HOME .. "/projects/puppet", -- set this to the director(y/ies) you keep puppet modules
}
}
local ansible_opts = {
settings = {
ansibleLint = {
arguments = 'ansible-lint -c ~/.ansible-lint'
}
}
}
local marksman_opts = {}
local tflint_opts = {}
local terraformls_opts = {}

require("lvim.lsp.manager").setup("puppet", puppet_opts)
require("lvim.lsp.manager").setup("ansiblels", ansible_opts)
require("lvim.lsp.manager").setup("marksman", marksman_opts)
require("lvim.lsp.manager").setup("tflint", tflint_opts)
require("lvim.lsp.manager").setup("terraformls", terraformls_opts)

-- ---remove a server from the skipped list, e.g. eslint, or emmet_ls. !!Requires `:LvimCacheReset` to take effect!!
-- ---`:LvimInfo` lists which server(s) are skiipped for the current filetype
-- vim.tbl_map(function(server)
-- return server ~= "emmet_ls"
-- end, lvim.lsp.automatic_configuration.skipped_servers)

-- -- you can set a custom on_attach function that will be used for all the language servers
-- -- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
-- lvim.lsp.on_attach_callback = function(client, bufnr)
-- local function buf_set_option(...)
-- vim.api.nvim_buf_set_option(bufnr, ...)
-- end
-- --Enable completion triggered by <c-x><c-o>
-- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
-- end

-- -- set a formatter, this will override the language server formatting capabilities (if it exists)
local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
{ command = "black", filetypes = { "python" } },
{
command = "puppet-lint",
extra_args = { "--fix", "--no-autoloader_layout-check" },
filetypes = { "puppet" },
},
-- {
-- -- each formatter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration
-- command = "prettier",
-- ---@usage arguments to pass to the formatter
-- -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
-- extra_args = { "--print-with", "100" },
-- ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
-- filetypes = { "typescript", "typescriptreact" },
-- },
}

-- -- set additional linters
-- local linters = require "lvim.lsp.null-ls.linters"
-- linters.setup {
-- { command = "flake8", filetypes = { "python" } },
-- {
-- -- each linter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration
-- command = "shellcheck",
-- ---@usage arguments to pass to the formatter
-- -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
-- extra_args = { "--severity", "warning" },
-- },
-- {
-- command = "codespell",
-- ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
-- filetypes = { "javascript", "python" },
-- },
-- }

-- Additional Plugins
lvim.plugins = {
-- Diagnostics, references, telescope results, quickfix and location lists
Expand Down Expand Up @@ -403,3 +310,88 @@ vim.api.nvim_create_autocmd('BufReadPost', {
end
end,
})


-- Debug LSP servers

-- vim.lsp.set_log_level 'debug'
-- require('vim.lsp.log').set_format_func(vim.inspect)

-- generic LSP settings

-- ---@usage disable automatic installation of servers
-- lvim.lsp.automatic_servers_installation = false

lvim.lsp.installer.setup.ensure_installed = { "pyright", "jsonls", "yamlls", "bashls", "puppet", "ansiblels", "marksman", "tflint", "terraformls", "azure_pipelines_ls", "dockerls" }

local puppet_opts = {
cmd = {
vim.env.HOME .. "/.rvm/rubies/default/bin/ruby",
vim.env.HOME .. "/.lsp/puppet-editor-services/puppet-languageserver",
"--stdio",
"--puppet-settings=--modulepath," .. vim.env.HOME .. "/projects/puppet", -- set this to the director(y/ies) you keep puppet modules
}
}
local ansible_opts = {
settings = {
ansibleLint = {
arguments = 'ansible-lint -c ~/.ansible-lint'
}
}
}
local marksman_opts = {}
local tflint_opts = {}
local terraformls_opts = {}

require("lvim.lsp.manager").setup("puppet", puppet_opts)
require("lvim.lsp.manager").setup("ansiblels", ansible_opts)
require("lvim.lsp.manager").setup("marksman", marksman_opts)
require("lvim.lsp.manager").setup("tflint", tflint_opts)
require("lvim.lsp.manager").setup("terraformls", terraformls_opts)

-- ---configure a server manually. !!Requires `:LvimCacheReset` to take effect!!
-- ---see the full default list `:lua print(vim.inspect(lvim.lsp.automatic_configuration.skipped_servers))`

-- ---remove a server from the skipped list, e.g. eslint, or emmet_ls. !!Requires `:LvimCacheReset` to take effect!!
-- ---`:LvimInfo` lists which server(s) are skiipped for the current filetype
-- vim.tbl_map(function(server)
-- return server ~= "emmet_ls"
-- end, lvim.lsp.automatic_configuration.skipped_servers)

-- -- set a formatter, this will override the language server formatting capabilities (if it exists)
local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
{ command = "black", filetypes = { "python" } },
{
command = "puppet-lint",
extra_args = { "--fix", "--no-autoloader_layout-check" },
filetypes = { "puppet" },
},
-- {
-- -- each formatter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration
-- command = "prettier",
-- ---@usage arguments to pass to the formatter
-- -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
-- extra_args = { "--print-with", "100" },
-- ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
-- filetypes = { "typescript", "typescriptreact" },
-- },
}

-- -- set additional linters
-- local linters = require "lvim.lsp.null-ls.linters"
-- linters.setup {
-- { command = "flake8", filetypes = { "python" } },
-- {
-- -- each linter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration
-- command = "shellcheck",
-- ---@usage arguments to pass to the formatter
-- -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
-- extra_args = { "--severity", "warning" },
-- },
-- {
-- command = "codespell",
-- ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
-- filetypes = { "javascript", "python" },
-- },
-- }

0 comments on commit 2345e26

Please sign in to comment.