From 2f071b95c1995b8b67084e2726622998876a6a5a Mon Sep 17 00:00:00 2001 From: Nathan Knowler Date: Tue, 22 Feb 2022 06:05:46 -0600 Subject: [PATCH] [neovim] remove PHP lsp settings + use different installer --- .config/nvim/lua/keymap.lua | 2 + .config/nvim/lua/lsp-config.lua | 213 ++++++++++++-------------------- .config/nvim/lua/plugins.lua | 28 ++++- 3 files changed, 103 insertions(+), 140 deletions(-) diff --git a/.config/nvim/lua/keymap.lua b/.config/nvim/lua/keymap.lua index 661912d..85bd835 100644 --- a/.config/nvim/lua/keymap.lua +++ b/.config/nvim/lua/keymap.lua @@ -26,3 +26,5 @@ map('n', 'gzn', 'lua require\'neuron/cmd\'.new_edit(require\'neuron\'.confi --find your notes, click enter to create the note if there are not notes that match map('n', 'gzz', 'lua require\'neuron/telescope\'.find_zettels()') + +map('n', 'r', 'lua require("telescope").extensions.live_grep_raw.live_grep_raw()') diff --git a/.config/nvim/lua/lsp-config.lua b/.config/nvim/lua/lsp-config.lua index de92174..169c1d5 100644 --- a/.config/nvim/lua/lsp-config.lua +++ b/.config/nvim/lua/lsp-config.lua @@ -1,38 +1,24 @@ -local lspinstall = require'lspinstall' -lspinstall.setup() - -local lsp = require'lspconfig' +local lspconfig = require('lspconfig') +local lsp_installer = require('nvim-lsp-installer') +local null_ls = require("null-ls") local autocmd = require'utils'.autocmd -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true - -local textConfig = { - filetypes = {'text', 'markdown', 'vimwiki', 'tex'}, +local servers = { + 'tsserver', + 'denols', + 'cssls', + 'sumneko_lua', } -local null_ls = require("null-ls") -null_ls.config({ - sources = { - --null_ls.builtins.code_actions.gitsigns, - null_ls.builtins.hover.dictionary.with(textConfig), - null_ls.builtins.diagnostics.write_good.with(textConfig), - null_ls.builtins.diagnostics.proselint.with(textConfig), - null_ls.builtins.hover.dictionary.with(textConfig), - --null_ls.builtins.diagnostics.markdownlint.with(textConfig), - null_ls.builtins.diagnostics.misspell.with(textConfig), - null_ls.builtins.formatting.prettier, - null_ls.builtins.formatting.phpcbf.with({ - extra_args = {"--standard=PSR12"}, - }), - null_ls.builtins.diagnostics.phpcs.with({ - extra_args = { - "--standard=PSR12", - "--runtime-set", "testVersion", "5.6-", - }, - }), - }, -}) +for _, name in pairs(servers) do + local server_is_found, server = lsp_installer.get_server(name) + if server_is_found then + if not server:is_installed() then + print("Installing " .. name) + server:install() + end + end +end local function on_attach(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end @@ -65,119 +51,74 @@ local function on_attach(client, bufnr) buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) end -local function setup_servers() - for _, server in pairs(lspinstall.installed_servers()) do - local config = {on_attach = on_attach} +lsp_installer.on_server_ready(function(server) + local default_opts = { + on_attach = on_attach, + } - if server == "json" then - config.settings = { - json = { - schemas = require('schemastore').json.schemas(), - }, - } - end - - if server == "typescript" then - --config = typescript - --config.filetypes = {"javascript", "javascriptreact", "javascript.jsx"} - config.init_options = require("nvim-lsp-ts-utils").init_options - config.on_attach = function(client, bufnr) - client.resolved_capabilities.document_formatting = false - on_attach = function(client, bufnr) - local ts_utils = require("nvim-lsp-ts-utils") - - -- defaults - ts_utils.setup({ - debug = true, - disable_commands = false, - enable_import_on_completion = false, - - enable_formatting = true, - formatter = 'prettier_d_slim', - - -- import all - import_all_timeout = 5000, -- ms - -- lower numbers = higher priority - import_all_priorities = { - same_file = 1, -- add to existing import statement - local_files = 2, -- git files or files with relative path markers - buffer_content = 3, -- loaded buffer content - buffers = 4, -- loaded buffer names - }, - import_all_scan_buffers = 100, - import_all_select_source = false, - - -- filter diagnostics - filter_out_diagnostics_by_severity = {}, - filter_out_diagnostics_by_code = {}, - - -- inlay hints - auto_inlay_hints = true, - inlay_hints_highlight = "Comment", - - -- update imports on file move - update_imports_on_move = false, - require_confirmation_on_move = false, - watch_dir = nil, - }) + local server_opts = { + ['tsserver'] = function() + --If this is Deno then bail out. + if lspconfig.util.root_pattern('deno.json')('.') then + default_opts.filetypes = {} + end - -- required to fix code action ranges and filter diagnostics - ts_utils.setup_client(client) + default_opts.root_dir = lspconfig.util.root_pattern('package.json') - local opts = { silent = true } - vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", ":TSLspOrganize", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", ":TSLspRenameFile", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gI", ":TSLspImportAll", opts) - end + default_opts.on_attach = function(client, bufnr) + client.resolved_capabilities.document_formatting = false + on_attach(client, bufnr) end - end - - if server == "lua" then - config = { - on_attach = on_attach, - settings = { - Lua = { - diagnostics = { - globals = {'vim'}, - } - } - } + default_opts.settings = { + format = { + enable = false, + }, } - end - - if server == "php" then - config = { - on_attach = function(client, bufnr) - client.resolved_capabilities.document_formatting = false - on_attach(client, bufnr) - end, - init_options = { + end, + ['denols'] = function() + --If this is Node then bail out. + if lspconfig.util.root_pattern('package.json')('.') then + default_opts.filetypes = {} + end + end, + ['jsonls'] = function () + default_opts.init_options = { documentFormatting = false, + } + default_opts.settings = { + json = { + schemas = require('schemastore').json.schemas(), }, - settings = { + init_options = { documentFormatting = false, - intelephense = { - format = { - enable = false, - }, - environment = { - phpVersion = "5.6" - }, - stubs = { "apache", "bcmath", "bz2", "calendar", "com_dotnet", "Core", "ctype", "curl", "date", "dba", "dom", "enchant", "exif", "FFI", "fileinfo", "filter", "fpm", "ftp", "gd", "gettext", "gmp", "hash", "iconv", "imap", "intl", "json", "ldap", "libxml", "mbstring", "meta", "mysqli", "oci8", "odbc", "openssl", "pcntl", "pcre", "PDO", "pdo_ibm", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "phpunit", "pgsql", "Phar", "posix", "pspell", "readline", "Reflection", "session", "shmop", "SimpleXML", "snmp", "soap", "sockets", "sodium", "SPL", "sqlite3", "standard", "superglobals", "sysvmsg", "sysvsem", "sysvshm", "tidy", "tokenizer", "wordpress", "xml", "xmlreader", "xmlrpc", "xmlwriter", "xsl", "Zend OPcache", "zip", "zlib" } + provideFormatter = false, + }, + format = { + enable = false, + }, + } + end, + ['sumneko_lua'] = function () + default_opts.settings = { + Lua = { + diagnostics = { + globals = {'vim'}, }, }, } - end - - lsp[server].setup(config) - end - - lsp["null-ls"].setup({on_attach = on_attach}) -end - -setup_servers() - -lspinstall.post_install_hook = function () - setup_servers() - vim.cmd("bufdo e") -end + end, + } + + server:setup( + server_opts[server.name] and server_opts[server.name]() or default_opts + ) +end) + +null_ls.setup({ + on_attach = on_attach, + sources = { + null_ls.builtins.formatting.prettier.with({ + filetypes = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact'}, + }), + }, +}) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index b483815..b13eaf1 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -1,3 +1,10 @@ +-- Install Packer if not installed +local fn = vim.fn +local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' +if fn.empty(fn.glob(install_path)) > 0 then + packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) +end + return require'packer'.startup(function (use) --Packer use 'wbthomason/packer.nvim' @@ -87,8 +94,11 @@ return require'packer'.startup(function (use) 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/popup.nvim', - 'nvim-lua/plenary.nvim' - } + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope-live-grep-raw.nvim', + 'nvim-telescope/telescope-dap.nvim', + }, + config = function () require'telescope'.load_extension('dap') end } use { @@ -106,7 +116,9 @@ return require'packer'.startup(function (use) --LSP use { 'neovim/nvim-lspconfig', - requires = {'kabouzeid/nvim-lspinstall'}, + requires = { + 'williamboman/nvim-lsp-installer', + }, config = function () require'lsp-config' end } @@ -186,10 +198,18 @@ return require'packer'.startup(function (use) use 'mattn/emmet-vim' - use 'github/copilot.vim' + --use 'github/copilot.vim' use 'jose-elias-alvarez/nvim-lsp-ts-utils' use 'jose-elias-alvarez/null-ls.nvim' use 'b0o/schemastore.nvim' + use 'windwp/nvim-spectre' + + use 'mfussenegger/nvim-dap' + + -- If bootstrapping, setup plugins. + if packer_bootstrap then + require('packer').sync() + end end) -- 2.51.2