From bf681ede72b08453709e562c2b5201ae5d4a205c Mon Sep 17 00:00:00 2001 From: David O'Trakoun Date: Mon, 23 Sep 2024 23:05:49 -0400 Subject: [PATCH] disable more nvim-lsp tsserver related, bring back prettier via efm instead of coc-prettier --- nvim/lua/dko/plugins/colorscheme.lua | 6 ++-- nvim/lua/dko/plugins/fixes.lua | 2 +- nvim/lua/dko/plugins/init.lua | 43 ++++++++++++----------- nvim/lua/dko/plugins/lsp.lua | 39 ++++++++++----------- nvim/lua/dko/plugins/markdown.lua | 2 +- nvim/lua/dko/plugins/telescope.lua | 5 ++- nvim/lua/dko/settings.lua | 4 +-- nvim/lua/dko/utils/format/javascript.lua | 44 +++++++++++------------- 8 files changed, 74 insertions(+), 71 deletions(-) diff --git a/nvim/lua/dko/plugins/colorscheme.lua b/nvim/lua/dko/plugins/colorscheme.lua index c06c1b03..dcd5997b 100644 --- a/nvim/lua/dko/plugins/colorscheme.lua +++ b/nvim/lua/dko/plugins/colorscheme.lua @@ -1,3 +1,5 @@ +local dkosettings = require("dko.settings") + return { { "davidosomething/vim-colors-meh", @@ -15,8 +17,8 @@ return { lazy = false, priority = 1000, init = function() - require("dko.settings").set("colors.dark", "meh") - require("dko.settings").set("colors.light", "komau") + dkosettings.set("colors.dark", "meh") + dkosettings.set("colors.light", "komau") end, config = function() vim.cmd.colorscheme("meh") diff --git a/nvim/lua/dko/plugins/fixes.lua b/nvim/lua/dko/plugins/fixes.lua index 4b48632e..2c682c6c 100644 --- a/nvim/lua/dko/plugins/fixes.lua +++ b/nvim/lua/dko/plugins/fixes.lua @@ -5,7 +5,7 @@ return { -- Disable cursorline when moving, for various perf reasons { - "yamatsum/nvim-cursorline", -- replaces delphinus/auto-cursorline.nvim", + "yamatsum/nvim-cursorline", -- replaces delphinus/auto-cursorline.nvim cond = #vim.api.nvim_list_uis() > 0, config = function() require("nvim-cursorline").setup({ diff --git a/nvim/lua/dko/plugins/init.lua b/nvim/lua/dko/plugins/init.lua index 6ef7d8fe..1bab66dd 100644 --- a/nvim/lua/dko/plugins/init.lua +++ b/nvim/lua/dko/plugins/init.lua @@ -1,4 +1,5 @@ local dkosettings = require("dko.settings") +local dkomappings = require("dko.mappings") local uis = vim.api.nvim_list_uis() local has_ui = #uis > 0 @@ -11,7 +12,8 @@ return { buffer = { suffix = "", options = {} }, -- using cybu comment = { suffix = "c", options = {} }, conflict = { suffix = "x", options = {} }, - -- don't want diagnostic float focus, have in mappings.lua + -- don't want diagnostic float focus, have in mappings.lua with coc + -- support too diagnostic = { suffix = "", options = {} }, file = { suffix = "f", options = {} }, indent = { suffix = "", options = {} }, -- confusing @@ -48,6 +50,8 @@ return { event = "VeryLazy", }, + -- Show diagnostic as virtual text at EOL + -- https://github.com/rachartier/tiny-inline-diagnostic.nvim -- { -- "rachartier/tiny-inline-diagnostic.nvim", -- -- event = "VeryLazy", @@ -100,7 +104,7 @@ return { "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim", }, - keys = vim.tbl_values(require("dko.mappings").cybu), + keys = vim.tbl_values(dkomappings.cybu), config = function() require("cybu").setup({ display_time = 500, @@ -123,7 +127,7 @@ return { "help", }, }) - require("dko.mappings").bind_cybu() + dkomappings.bind_cybu() end, }, @@ -133,7 +137,7 @@ return { { "troydm/zoomwintab.vim", cond = has_ui, - keys = require("dko.mappings").zoomwintab, + keys = dkomappings.zoomwintab, cmd = { "ZoomWinTabIn", "ZoomWinTabOut", @@ -153,13 +157,14 @@ return { }, }, + -- hjkl or w for picker -- https://github.com/yorickpeterse/nvim-window { "yorickpeterse/nvim-window", cond = has_ui, config = function() require("nvim-window").setup({}) - require("dko.mappings").bind_nvim_window() + dkomappings.bind_nvim_window() end, }, @@ -176,7 +181,7 @@ return { { "akinsho/toggleterm.nvim", - keys = require("dko.mappings").toggleterm_all_keys, + keys = dkomappings.toggleterm_all_keys, cmd = "ToggleTerm", cond = has_ui, config = function() @@ -188,7 +193,7 @@ return { -- the buffer terminal with the floating terminal open_mapping = nil, }) - require("dko.mappings").bind_toggleterm() + dkomappings.bind_toggleterm() end, }, @@ -212,7 +217,7 @@ return { cond = has_ui, config = function() require("gitsigns").setup({ - on_attach = require("dko.mappings").bind_gitsigns, + on_attach = dkomappings.bind_gitsigns, preview_config = { border = dkosettings.get("border"), }, @@ -241,11 +246,11 @@ return { -- https://github.com/axieax/urlview.nvim { "axieax/urlview.nvim", - keys = vim.tbl_values(require("dko.mappings").urlview), + keys = vim.tbl_values(dkomappings.urlview), cmd = "UrlView", cond = has_ui, config = function() - require("dko.mappings").bind_urlview() + dkomappings.bind_urlview() end, }, @@ -412,12 +417,10 @@ return { ) return end - require("Comment").setup( - require("dko.mappings").with_commentnvim_mappings({ - -- add treesitter support, want tsx/jsx in particular - pre_hook = tscc_integration.create_pre_hook(), - }) - ) + require("Comment").setup(dkomappings.with_commentnvim_mappings({ + -- add treesitter support, want tsx/jsx in particular + pre_hook = tscc_integration.create_pre_hook(), + })) end, }, @@ -428,13 +431,13 @@ return { "nvim-treesitter/nvim-treesitter", }, event = { "BufReadPost", "BufNewFile" }, - keys = require("dko.mappings").trees, + keys = dkomappings.trees, config = function() require("treesj").setup({ use_default_keymaps = false, max_join_length = 255, }) - require("dko.mappings").bind_treesj() + dkomappings.bind_treesj() end, }, @@ -455,7 +458,7 @@ return { "mattn/vim-textobj-url", }, config = function() - require("dko.mappings").bind_textobj() + dkomappings.bind_textobj() end, }, @@ -464,7 +467,7 @@ return { cond = has_ui, config = function() require("various-textobjs").setup({ useDefaultKeymaps = false }) - require("dko.mappings").bind_nvim_various_textobjs() + dkomappings.bind_nvim_various_textobjs() end, }, } diff --git a/nvim/lua/dko/plugins/lsp.lua b/nvim/lua/dko/plugins/lsp.lua index a9acbb26..2614c18f 100644 --- a/nvim/lua/dko/plugins/lsp.lua +++ b/nvim/lua/dko/plugins/lsp.lua @@ -23,7 +23,6 @@ return { vim.g.coc_global_extensions = { "coc-eslint", "coc-json", - "coc-prettier", "coc-tsserver", } end, @@ -65,6 +64,7 @@ return { -- https://github.com/aznhe21/actions-preview.nvim { "aznhe21/actions-preview.nvim", + enabled = dkosettings.get("lsp.code_action") == "actions-preview", dependencies = { "nvim-telescope/telescope.nvim", }, @@ -75,15 +75,14 @@ return { -- https://www.reddit.com/r/neovim/comments/1eaxity/rachartiertinycodeactionnvim_a_simple_way_to_run/ { "rachartier/tiny-code-action.nvim", + enabled = dkosettings.get("lsp.code_action") == "tiny-code-action", dependencies = { { "nvim-lua/plenary.nvim" }, { "nvim-telescope/telescope.nvim" }, }, event = "LspAttach", config = function() - require("tiny-code-action").setup({ - lsp_timeout = 4000, - }) + require("tiny-code-action").setup({ lsp_timeout = 4000 }) end, }, @@ -120,7 +119,7 @@ return { config = function() -- border on :LspInfo window require("lspconfig.ui.windows").default_options.border = - require("dko.settings").get("border") + dkosettings.get("border") end, }, @@ -146,22 +145,20 @@ return { -- end, -- }, - { - "davidosomething/format-ts-errors.nvim", -- extracted ts error formatter - dev = true, - lazy = true, - }, + -- { + -- "davidosomething/format-ts-errors.nvim", -- extracted ts error formatter + -- dev = true, + -- lazy = true, + -- }, -- https://github.com/marilari88/twoslash-queries.nvim - { - "marilari88/twoslash-queries.nvim", - cond = has_ui, - config = function() - require("twoslash-queries").setup({ - multi_line = true, - }) - end, - }, + -- { + -- "marilari88/twoslash-queries.nvim", + -- cond = has_ui, + -- config = function() + -- require("twoslash-queries").setup({ multi_line = true }) + -- end, + -- }, { "hrsh7th/cmp-nvim-lsp", -- provides some capabilities @@ -184,8 +181,8 @@ return { -- @TODO move these somewhere else "b0o/schemastore.nvim", -- wait for schemastore for jsonls - "davidosomething/format-ts-errors.nvim", -- extracted ts error formatter - "marilari88/twoslash-queries.nvim", -- ts_ls comment with ^? comment + -- "davidosomething/format-ts-errors.nvim", -- extracted ts error formatter + -- "marilari88/twoslash-queries.nvim", -- ts_ls comment with ^? comment }, config = function() local lspconfig = require("lspconfig") diff --git a/nvim/lua/dko/plugins/markdown.lua b/nvim/lua/dko/plugins/markdown.lua index 958991ee..30ef3ca9 100644 --- a/nvim/lua/dko/plugins/markdown.lua +++ b/nvim/lua/dko/plugins/markdown.lua @@ -46,7 +46,7 @@ return { -- local markview = require("markview") -- local presets = require("markview.presets") -- markview.setup({ - -- -- headings color bg only, no icon no conceal content + -- -- headings color bg only. no icon no conceal content -- headings = presets.headings.simple, -- list_items = { enable = false }, -- tables = { block_decorator = false }, diff --git a/nvim/lua/dko/plugins/telescope.lua b/nvim/lua/dko/plugins/telescope.lua index 79b6285b..428f6f89 100644 --- a/nvim/lua/dko/plugins/telescope.lua +++ b/nvim/lua/dko/plugins/telescope.lua @@ -2,13 +2,16 @@ local uis = vim.api.nvim_list_uis() local has_ui = #uis > 0 return { + + -- find nerd font glyphs + -- https://github.com/2KAbhishek/nerdy.nvim { "2kabhishek/nerdy.nvim", + cmd = "Nerdy", dependencies = { "stevearc/dressing.nvim", "nvim-telescope/telescope.nvim", }, - cmd = "Nerdy", }, { diff --git a/nvim/lua/dko/settings.lua b/nvim/lua/dko/settings.lua index 012b805e..3633b846 100644 --- a/nvim/lua/dko/settings.lua +++ b/nvim/lua/dko/settings.lua @@ -27,8 +27,8 @@ local settings = { lsp = { -- Which code action UI should we try first? -- The alternative will be tried second - --code_action = "tiny-code-action", - code_action = "actions-preview", + code_action = "tiny-code-action", + -- code_action = "actions-preview", }, } diff --git a/nvim/lua/dko/utils/format/javascript.lua b/nvim/lua/dko/utils/format/javascript.lua index 99d03537..3b06dc71 100644 --- a/nvim/lua/dko/utils/format/javascript.lua +++ b/nvim/lua/dko/utils/format/javascript.lua @@ -1,34 +1,40 @@ local dkosettings = require("dko.settings") local dkonode = require("dko.utils.node") -function format_with_coc(notify) +local function format_with_coc(notify) local eslint_only = vim.b.has_eslint_plugin_prettier notify( eslint_only and { "coc-eslint with eslint-plugin-prettier" } or { "coc-eslint" } ) vim.cmd.call("CocAction('runCommand', 'eslint.executeAutofix')") - vim.cmd.sleep(eslint_only and "250m" or "1m") - - if not eslint_only then - notify({ "coc-prettier" }) - vim.cmd.call("CocAction('runCommand', 'prettier.formatFile')") - vim.cmd.sleep("250m") - end + vim.cmd.sleep(eslint_only and "100m" or "1m") end -function format_with_lsp(notify) +local function format_with_lsp(notify) local eslint_only = vim.b.has_eslint_plugin_prettier - - -- eslint-lsp - vim.b.has_eslint = vim.b.has_eslint - or #vim.lsp.get_clients({ bufnr = 0, name = "eslint" }) > 0 - if vim.b.has_eslint then + if #vim.lsp.get_clients({ bufnr = 0, name = "eslint" }) > 0 then vim.cmd.EslintFixAll() notify(eslint_only and { "eslint-plugin-prettier" } or { "eslint" }) + return + end + notify("eslint-lsp not found") +end + +return function(notify) + if vim.b.has_eslint_plugin_prettier == nil then + vim.b.has_eslint_plugin_prettier = dkonode.has_eslint_plugin("prettier") end - if not eslint_only then + -- Run eslint via coc or nvim-lsp eslint-lsp + if dkosettings.get("coc.enabled") then + format_with_coc(notify) + else + format_with_lsp(notify) + end + + -- Finally, run prettier via efm + if not vim.b.has_eslint_plugin_prettier then local did_efm_format = require("dko.utils.format.efm").format({ pipeline = "javascript" }) if not did_efm_format then @@ -38,11 +44,3 @@ function format_with_lsp(notify) end end end - -return function(notify) - if vim.b.has_eslint_plugin_prettier == nil then - vim.b.has_eslint_plugin_prettier = dkonode.has_eslint_plugin("prettier") - end - return dkosettings.get("coc.enabled") and format_with_coc(notify) - or format_with_lsp(notify) -end