From 2c0b2f949356adef2359d38406bc06c265a64800 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Sun, 12 Dec 2021 11:12:54 -0500 Subject: [PATCH] Working on nvim lsp, and rearranged global gitconfig --- git/{.gitconfig => .config/git/config} | 0 macOS/.config/macOS/Brewfile | 3 +- .../.config/nvim/lua/config/lsp-installer.lua | 16 ++ nvim/.config/nvim/lua/config/lsp.lua | 198 ++++++++++++++++++ nvim/.config/nvim/lua/plugins.lua | 11 + nvim/.config/nvim/plugin/packer_compiled.lua | 42 ++-- 6 files changed, 253 insertions(+), 17 deletions(-) rename git/{.gitconfig => .config/git/config} (100%) create mode 100644 nvim/.config/nvim/lua/config/lsp-installer.lua create mode 100644 nvim/.config/nvim/lua/config/lsp.lua diff --git a/git/.gitconfig b/git/.config/git/config similarity index 100% rename from git/.gitconfig rename to git/.config/git/config diff --git a/macOS/.config/macOS/Brewfile b/macOS/.config/macOS/Brewfile index 3fb3758..aebcf27 100644 --- a/macOS/.config/macOS/Brewfile +++ b/macOS/.config/macOS/Brewfile @@ -6,10 +6,11 @@ tap "homebrew/cask-fonts" cask_args appdir: "~/Applications", require_sha: true # formula -brew "fd" +brew "fd" # required for some neovim plugins brew "git" brew "mas" brew "neovim" +brew "node" # required for some LSP servers in neovim brew "ripgrep" brew "stow" brew "swift-format" diff --git a/nvim/.config/nvim/lua/config/lsp-installer.lua b/nvim/.config/nvim/lua/config/lsp-installer.lua new file mode 100644 index 0000000..43dccc9 --- /dev/null +++ b/nvim/.config/nvim/lua/config/lsp-installer.lua @@ -0,0 +1,16 @@ +local lsp_installer = require("nvim-lsp-installer") + +-- Register a handler that will be called for all installed servers. +-- Alternatively, you may also register handlers on specific server instances instead (see example below). +lsp_installer.on_server_ready(function(server) + local opts = {} + + -- (optional) Customize the options passed to the server + -- if server.name == "tsserver" then + -- opts.root_dir = function() ... end + -- end + + -- This setup() function is exactly the same as lspconfig's setup function. + -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + server:setup(opts) +end) diff --git a/nvim/.config/nvim/lua/config/lsp.lua b/nvim/.config/nvim/lua/config/lsp.lua new file mode 100644 index 0000000..423c13e --- /dev/null +++ b/nvim/.config/nvim/lua/config/lsp.lua @@ -0,0 +1,198 @@ +local nvim_lsp = require("lspconfig") + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(bufnr) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + -- Mappings. + local opts = {noremap = true, silent = true} + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + -- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap("n", "wa", + "lua vim.lsp.buf.add_workspace_folder()", opts) + buf_set_keymap("n", "wr", + "lua vim.lsp.buf.remove_workspace_folder()", opts) + buf_set_keymap("n", "wl", + "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", + opts) + buf_set_keymap("n", "D", + "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) + buf_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", + opts) + buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) + buf_set_keymap("n", "e", + "lua vim.lsp.diagnostic.show_line_diagnostics()", + opts) + buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", + opts) + buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", + opts) + buf_set_keymap("n", "q", + "lua vim.lsp.diagnostic.set_loclist()", opts) + buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", + opts) + +end + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) + +local servers = { + "gopls", "bashls", "jedi_language_server", "dockerls", "terraformls", + "tsserver", "texlab", "yamlls", "jsonls" +} +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + settings = { + gopls = {analyses = {unusedparams = false}, staticcheck = true}, + json = { + format = {enabled = false}, + schemas = { + { + description = "ESLint config", + fileMatch = {".eslintrc.json", ".eslintrc"}, + url = "http://json.schemastore.org/eslintrc" + }, { + description = "Package config", + fileMatch = {"package.json"}, + url = "https://json.schemastore.org/package" + }, { + description = "Packer config", + fileMatch = {"packer.json"}, + url = "https://json.schemastore.org/packer" + }, { + description = "Renovate config", + fileMatch = { + "renovate.json", "renovate.json5", + ".github/renovate.json", ".github/renovate.json5", + ".renovaterc", ".renovaterc.json" + }, + url = "https://docs.renovatebot.com/renovate-schema" + }, { + description = "OpenApi config", + fileMatch = {"*api*.json"}, + url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json" + } + } + }, + redhat = {telemetry = {enabled = false}}, + texlab = { + auxDirectory = ".", + bibtexFormatter = "texlab", + build = { + args = { + "--keep-intermediates", "--keep-logs", "--synctex", "%f" + }, + executable = "tectonic", + forwardSearchAfter = false, + onSave = false + }, + chktex = {onEdit = false, onOpenAndSave = false}, + diagnosticsDelay = 300, + formatterLineLength = 80, + forwardSearch = {args = {}}, + latexFormatter = "latexindent", + latexindent = {modifyLineBreaks = false} + }, + yaml = { + schemaStore = { + enable = true, + url = "https://www.schemastore.org/api/json/catalog.json" + }, + schemas = { + kubernetes = "/*.yaml", + ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*.{yml,yaml}", + ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}", + ["http://json.schemastore.org/ansible-stable-2.9"] = "roles/tasks/*.{yml,yaml}", + ["http://json.schemastore.org/prettierrc"] = ".prettierrc.{yml,yaml}", + ["http://json.schemastore.org/kustomization"] = "kustomization.{yml,yaml}", + ["http://json.schemastore.org/ansible-playbook"] = "*play*.{yml,yaml}", + ["http://json.schemastore.org/chart"] = "Chart.{yml,yaml}", + ["https://json.schemastore.org/dependabot-v2"] = ".github/dependabot.{yml,yaml}", + ["https://json.schemastore.org/gitlab-ci"] = "*gitlab-ci*.{yml,yaml}", + ["https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json"] = "*api*.{yml,yaml}", + ["https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"] = "docker-compose.{yml,yaml}", + ["https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json"] = "*flow*.{yml,yaml}" + }, + format = {enabled = false}, + validate = false, -- TODO: conflicts between Kubernetes resources and kustomization.yaml + completion = true, + hover = true + } + }, + flags = {debounce_text_changes = 150} + } + require"lsp_signature".setup({ + bind = true, -- This is mandatory, otherwise border config won't get registered. + floating_window = true, -- show hint in a floating window, set to false for virtual text only mode + doc_lines = 2, -- Set to 0 for not showing doc + hint_prefix = "🐼 ", + -- use_lspsaga = false, -- set to true if you want to use lspsaga popup + handler_opts = { + border = "shadow" -- double, single, shadow, none + } + }) +end + +local sumneko_root_path = os.getenv("HOME") .. ".cache/lua-language-server" +local sumneko_binary = "/usr/bin/lua-language-server" +require"lspconfig".sumneko_lua.setup { + cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}, + capabilities = capabilities, + on_attach = on_attach, + settings = { + Lua = { + runtime = {version = "LuaJIT", path = vim.split(package.path, ";")}, + completion = {enable = true, callSnippet = "Both"}, + diagnostics = { + enable = true, + globals = {"vim", "describe"}, + disable = {"lowercase-global"} + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true, + [vim.fn.expand("/usr/share/awesome/lib")] = true + }, + -- adjust these two values if your performance is not optimal + maxPreload = 2000, + preloadFileSize = 1000 + }, + telemetry = {enable = false} + } + } +} +-- alternative to formatter but yamlfix is not working and I need this for respecting yamllint config +-- but yamlfix is messing up ansible files ... 😠 +-- require('lspconfig')['efm'].setup{ +-- filetypes = { 'json', 'yaml','lua' }, +-- init_options = {documentFormatting = true, codeAction = false}, +-- settings = { +-- rootMarkers = {".git/"}, +-- languages = { +-- lua = { +-- {formatCommand = "lua-format -i", formatStdin = true} +-- }, +-- yaml = { +-- {formatCommand = "yamlfix -", formatStdin = true} +-- }, +-- json = { +-- {formatCommand = "prettier", formatStdin = true} +-- } +-- } +-- } +-- } diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 25d468d..f5067ad 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -54,6 +54,17 @@ use { use "nvim-treesitter/nvim-treesitter-textobjects" +-- LSP +use { + "neovim/nvim-lspconfig", + config = get_config("lsp") +} +use { + "williamboman/nvim-lsp-installer", + config = get_config("lsp-installer") +} + + use {"folke/which-key.nvim", event = "VimEnter", config = get_config("which")} -- Theme diff --git a/nvim/.config/nvim/plugin/packer_compiled.lua b/nvim/.config/nvim/plugin/packer_compiled.lua index 1397318..2861c16 100644 --- a/nvim/.config/nvim/plugin/packer_compiled.lua +++ b/nvim/.config/nvim/plugin/packer_compiled.lua @@ -81,6 +81,16 @@ _G.packer_plugins = { path = "/Users/michael/.local/share/nvim/site/pack/packer/start/nightfox.nvim", url = "https://github.com/EdenEast/nightfox.nvim" }, + ["nvim-lsp-installer"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer", + url = "https://github.com/williamboman/nvim-lsp-installer" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, ["nvim-tree.lua"] = { config = { 'require("config/nvim-tree")' }, loaded = true, @@ -130,26 +140,26 @@ _G.packer_plugins = { } time([[Defining packer_plugins]], false) --- Config for: lualine.nvim -time([[Config for lualine.nvim]], true) -require("config/lualine") -time([[Config for lualine.nvim]], false) --- Config for: nightfox.nvim -time([[Config for nightfox.nvim]], true) -require("config/nightfox") -time([[Config for nightfox.nvim]], false) --- Config for: telescope.nvim -time([[Config for telescope.nvim]], true) -require("config/telescope") -time([[Config for telescope.nvim]], false) --- Config for: nvim-treesitter -time([[Config for nvim-treesitter]], true) -require("config/treesitter") -time([[Config for nvim-treesitter]], false) -- Config for: nvim-tree.lua time([[Config for nvim-tree.lua]], true) require("config/nvim-tree") time([[Config for nvim-tree.lua]], false) +-- Config for: lualine.nvim +time([[Config for lualine.nvim]], true) +require("config/lualine") +time([[Config for lualine.nvim]], false) +-- Config for: nvim-treesitter +time([[Config for nvim-treesitter]], true) +require("config/treesitter") +time([[Config for nvim-treesitter]], false) +-- Config for: telescope.nvim +time([[Config for telescope.nvim]], true) +require("config/telescope") +time([[Config for telescope.nvim]], false) +-- Config for: nightfox.nvim +time([[Config for nightfox.nvim]], true) +require("config/nightfox") +time([[Config for nightfox.nvim]], false) vim.cmd [[augroup packer_load_aucmds]] vim.cmd [[au!]] -- Event lazy-loads