diff --git a/init.plugins.vim b/init.plugins.vim index 60a0792..42610ac 100644 --- a/init.plugins.vim +++ b/init.plugins.vim @@ -51,6 +51,15 @@ Plug '~/nvim-paper-tonic' " https://github.com/neovim/nvim-lspconfig/wiki Plug 'neovim/nvim-lspconfig' "}}} +" #plenary.nvim {{{ + " https://github.com/nvim-lua/plenary.nvim + " required for null-ls + Plug 'nvim-lua/plenary.nvim' + "}}} +" #null-ls.nvim {{{ + " https://github.com/jose-elias-alvarez/null-ls.nvim + Plug 'jose-elias-alvarez/null-ls.nvim' + "}}} " #nvim-cmp {{{ " https://github.com/hrsh7th/nvim-cmp/ " completion @@ -318,7 +327,8 @@ runtime macros/matchit.vim lua < :lua vim.lsp.buf.formatting_seq_sync({}, 1000)]] - vim.cmd [[augroup END]] - end -end -require "lspconfig".efm.setup { - init_options = {documentFormatting = true}, - on_attach = on_attach_efm, - filetypes = {"javascript", "json", "sh", "python", "lua"}, - root_dir = function(fname) - return util.root_pattern("tsconfig.json")(fname) or - util.root_pattern(".eslintrc.js", ".git")(fname); - end, - settings = { - rootMarkers = {".eslintrc.js", ".git/"}, - languages = { - javascript = {eslint}, - json = {jq, fixjson}, - python = {flake8, black}, - sh = {shellcheck}, - lua = {luaformat} - } - } -} - - diff --git a/lua/init-lspconfig.lua b/lua/init-lspconfig.lua index 26a324a..4803b76 100644 --- a/lua/init-lspconfig.lua +++ b/lua/init-lspconfig.lua @@ -5,24 +5,39 @@ local nvim_lsp = require('lspconfig') local servers = { -- npm i -g bash-language-server -- TODO - don't run for sh files but have something else instead - shellcheck? + -- no formatting support 'bashls', + -- npm i -g vscode-langservers-extracted + -- no formatting support 'cssls', + -- npm install -g intelephense + -- suports formatting 'intelephense', + -- https://phpactor.readthedocs.io/en/master/usage/standalone.html 'phpactor', + -- npm install -g pyright + -- static type checker 'pyright', + -- https://github.com/neovim/nvim-lspconfig/wiki -- 'tailwindcss', -- npm install -g typescript typescript-language-server + -- supports formatting 'tsserver', + -- npm install -g vim-language-server + -- no formatting support 'vimls', - -- npm install -g vls - 'vuels', + + -- vue + -- use vetur + 'yamlls', + -- no formatting support } -- Use an on_attach function to only map the following keys @@ -36,33 +51,33 @@ local on_attach = function(client, bufnr) -- Mappings. local opts = { noremap=true, silent=true } -- See `:help vim.lsp.*` for documentation on any of the below functions - 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', '[d', 'lua vim.diagnostic.goto_prev({float = {...}})', opts) + buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next({float = {...}})', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'gl', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', 'gl', 'lua vim.diagnostic.open_float(buffer, {{opts}, scope="line", pos=17})', opts) buf_set_keymap('n', 'gh', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) buf_set_keymap('n', 'T', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'l', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'l', 'lua vim.diagnostic.setloclist()', opts) + buf_set_keymap('n', 'q', 'lua vim.diagnostic.setqflist()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + -- buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', 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) if client.name == 'tsserver' or client.name == 'intelephense' then - print(client.name .. ' - disabling formatting') client.resolved_capabilities.document_formatting = false; end if client.resolved_capabilities.document_formatting then vim.cmd [[augroup lsp_formatting]] vim.cmd [[autocmd!]] - vim.cmd [[autocmd BufWritePre :lua vim.lsp.buf.formatting_seq_sync({}, 1000)]] + vim.cmd [[autocmd BufWritePre :lua vim.lsp.buf.formatting_seq_sync({}, 3000)]] vim.cmd [[augroup END]] end end @@ -81,18 +96,31 @@ for _, lsp in ipairs(servers) do } end --- npm i -g stylelint-lsp -nvim_lsp.stylelint_lsp.setup { - on_attach = on_attach, - capabilities = capabilities, - flags = { - debounce_text_changes = 150, - }, - filetypes = {'css', 'scss', 'less'}, - settings = { - stylelintplus = { - autoFixOnSave = true, - autoFixOnFormat = true, - } - } +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") + +require'lspconfig'.sumneko_lua.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, } diff --git a/lua/init-null-ls.lua b/lua/init-null-ls.lua new file mode 100644 index 0000000..08ce508 --- /dev/null +++ b/lua/init-null-ls.lua @@ -0,0 +1,68 @@ +local null_ls = require("null-ls") + +local sources = { + -- -- prettier - using perttierd instead + -- null_ls.builtins.formatting.prettier.with({ + -- extra_filetypes = { "php" }, + -- prefer_local = "node_modules/.bin", + -- }), + -- -- prettierd with php + -- null_ls.builtins.formatting.prettierd.with({ + -- extra_filetypes = { "php" }, + -- }), + -- prettierd without php (use phpcbf instead) + null_ls.builtins.formatting.prettierd, + + -- phpcs - standards wordpress + null_ls.builtins.diagnostics.phpcs.with({ + condition = function(utils) + return utils.root_has_file({ "vendor/bin/phpcs" }) + end, + command = "vendor/bin/phpcs", + args = { "--standard=WordPress", "--report=json", "-s", "-" }, + }), + -- phpcbf - standards wordpress + null_ls.builtins.formatting.phpcbf.with({ + condition = function(utils) + return utils.root_has_file({ "vendor/bin/phpcbf" }) + end, + command = "vendor/bin/phpcbf", + args = { "--standard=WordPress", "-" }, + }), + + -- phpcs + null_ls.builtins.diagnostics.phpcs.with({ + condition = function(utils) + return not utils.root_has_file({ "vendor/bin/phpcs" }) + end, + }), + -- phpcbf + null_ls.builtins.formatting.phpcbf.with({ + condition = function(utils) + return not utils.root_has_file({ "vendor/bin/phpcbf" }) + end, + }), + + -- black + null_ls.builtins.formatting.black, + -- shellcheck, + null_ls.builtins.diagnostics.shellcheck, + -- flake8 + null_ls.builtins.diagnostics.flake8, + -- luaFormatter + null_ls.builtins.formatting.lua_format, +} + +null_ls.setup({ + sources = sources, + on_attach = function(client) + if client.resolved_capabilities.document_formatting then + vim.cmd([[ + augroup lsp_formatting + autocmd! * + autocmd BufWritePre :lua vim.lsp.buf.formatting_seq_sync({}, 3000) + augroup END + ]]) + end + end, +})