From 3be72c24bccfbf66e7e6afe602315500a4e9f4ea Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 25 Feb 2024 21:01:25 +0545 Subject: [PATCH] comments(nvim): add tsserver variable annotation --- config/nvim/lua/config/autocmds.lua | 14 ++-- config/nvim/lua/config/keymaps.lua | 22 +++++- .../nvim/lua/plugins/extras/lang/ansible.lua | 9 +-- .../lua/plugins/extras/lang/web/html-css.lua | 28 ++++++- .../extras/lang/web/typescript-extended.lua | 74 ++++++++++++------- .../lua/plugins/extras/linting/stylelint.lua | 35 --------- config/nvim/lua/plugins/lualine.lua | 30 ++++++++ 7 files changed, 134 insertions(+), 78 deletions(-) delete mode 100644 config/nvim/lua/plugins/extras/linting/stylelint.lua diff --git a/config/nvim/lua/config/autocmds.lua b/config/nvim/lua/config/autocmds.lua index 68e49811..06c3e841 100644 --- a/config/nvim/lua/config/autocmds.lua +++ b/config/nvim/lua/config/autocmds.lua @@ -96,12 +96,14 @@ ac({ "BufNewFile", "BufRead" }, { ac("ModeChanged", { pattern = "*", callback = function() - if - ((vim.v.event.old_mode == "s" and vim.v.event.new_mode == "n") or vim.v.event.old_mode == "i") - and require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] - and not require("luasnip").session.jump_active - then - require("luasnip").unlink_current() + if not vim.g.vscode then + if + ((vim.v.event.old_mode == "s" and vim.v.event.new_mode == "n") or vim.v.event.old_mode == "i") + and require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end end end, }) diff --git a/config/nvim/lua/config/keymaps.lua b/config/nvim/lua/config/keymaps.lua index 5356ac1d..5eeed383 100644 --- a/config/nvim/lua/config/keymaps.lua +++ b/config/nvim/lua/config/keymaps.lua @@ -17,7 +17,8 @@ map("n", "l", "") map("n", "ll", "Lazy", { desc = "Lazy" }) -- stylua: ignore start map("n", "ld", function() vim.fn.system({ "xdg-open", "https://lazyvim.org" }) end, { desc = "LazyVim Docs" }) -map("n", "lr", function() vim.fn.system({ "xdg-open", "https://github.com/LazyVim/LazyVim" }) end, { desc = "LazyVim Repo" }) +map("n", "lr", function() vim.fn.system({ "xdg-open", "https://github.com/LazyVim/LazyVim" }) end, + { desc = "LazyVim Repo" }) map("n", "lx", "LazyExtras", { desc = "Extras" }) map("n", "lc", function() Util.news.changelog() end, { desc = "LazyVim Changelog" }) map("n", "lu", function() require("lazy").update() end, { desc = "Lazy Update" }) @@ -91,6 +92,25 @@ map("n", "[/", "?\\S\\zs\\s*╭zt", { desc = "Prev block comment" }) -- Plugin Info map("n", "cif", "LazyFormatInfo", { desc = "Formatting" }) map("n", "cic", "ConformInfo", { desc = "Conform" }) +local linters = function() + local linters_attached = require("lint").linters_by_ft[vim.bo.filetype] + local buf_linters = {} + + if not linters_attached then + vim.notify("No linters attached", vim.log.levels.WARN, { title = "Linter" }) + return + end + + for _, linter in pairs(linters_attached) do + table.insert(buf_linters, linter) + end + + local unique_client_names = table.concat(buf_linters, ", ") + local linters = string.format("%s", unique_client_names) + + vim.notify(linters, vim.log.levels.INFO, { title = "Linter" }) +end +map("n", "ciL", linters, { desc = "Lint" }) map("n", "cir", "LazyRoot", { desc = "Root" }) -- U for redo diff --git a/config/nvim/lua/plugins/extras/lang/ansible.lua b/config/nvim/lua/plugins/extras/lang/ansible.lua index 2a8a9445..c110579b 100644 --- a/config/nvim/lua/plugins/extras/lang/ansible.lua +++ b/config/nvim/lua/plugins/extras/lang/ansible.lua @@ -1,12 +1,5 @@ return { - { - "nvim-treesitter/nvim-treesitter", - opts = function(_, opts) - if type(opts.ensure_installed) == "table" then - vim.list_extend(opts.ensure_installed, { "yaml" }) - end - end, - }, + { import = "lazyvim.plugins.extras.lang.yaml" }, { "williamboman/mason.nvim", opts = function(_, opts) diff --git a/config/nvim/lua/plugins/extras/lang/web/html-css.lua b/config/nvim/lua/plugins/extras/lang/web/html-css.lua index 3e39b51b..cee8ac18 100644 --- a/config/nvim/lua/plugins/extras/lang/web/html-css.lua +++ b/config/nvim/lua/plugins/extras/lang/web/html-css.lua @@ -49,14 +49,38 @@ return { "cssmodules-language-server", "css-lsp", "htmlhint", + "stylelint", }) end, }, { "mfussenegger/nvim-lint", opts = function(_, opts) - opts.linters_by_ft.html = opts.linters_by_ft.html or {} - table.insert(opts.linters_by_ft.html, "htmlhint") + local stylelint = "stylelint" + + local function add_linters(tbl) + for ft, linters in pairs(tbl) do + if opts.linters_by_ft[ft] == nil then + opts.linters_by_ft[ft] = linters + else + vim.list_extend(opts.linters_by_ft[ft], linters) + end + end + end + + add_linters({ + ["html"] = { "htmlhint" }, + ["css"] = { stylelint }, + ["scss"] = { stylelint }, + ["less"] = { stylelint }, + ["sugarss"] = { stylelint }, + ["vue"] = { stylelint }, + ["wxss"] = { stylelint }, + ["javascript"] = { stylelint }, + ["javascriptreact"] = { stylelint }, + ["typescript"] = { stylelint }, + ["typescriptreact"] = { stylelint }, + }) return opts end, }, diff --git a/config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua b/config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua index 6767e802..8c481e17 100644 --- a/config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua +++ b/config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua @@ -1,14 +1,5 @@ -local source_action = function(name) - return function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { string.format("source.%s.ts", name) }, - diagnostics = {}, - }, - }) - end -end +local ts_server_activated = true -- Change this variable to false if you want to use typescript-tools instead of lspconfig tsserver implementation +local ft = { "typescript", "typescriptreact", "javascript", "javascriptreact" } local inlayHints = { includeInlayParameterNameHints = "all", @@ -21,17 +12,16 @@ local inlayHints = { includeInlayEnumMemberValueHints = true, } -local function denoConfigExists() - local configs = { "deno.json", "deno.jsonc" } - local root = require("lazyvim.util.root").get() - - for _, config in ipairs(configs) do - if vim.fn.filereadable(root .. "/" .. config) == 1 then - return true - end +local source_action = function(name) + return function() + vim.lsp.buf.code_action({ + apply = true, + context = { + only = { string.format("source.%s.ts", name) }, + diagnostics = {}, + }, + }) end - - return false end return { @@ -49,6 +39,7 @@ return { opts = { servers = { tsserver = { + enabled = ts_server_activated, init_options = { preferences = { disableSuggestions = true, @@ -82,13 +73,44 @@ return { }, denols = {}, }, - setup = { - tsserver = function(_, opts) - -- Disable tsserver if denols is present - return denoConfigExists() - end, + }, + }, + { + "pmizio/typescript-tools.nvim", + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + enabled = not ts_server_activated, + ft = ft, + opts = { + cmd = { "typescript-language-server", "--stdio" }, + settings = { + code_lens = "all", + expose_as_code_action = "all", + tsserver_plugins = { + "@styled/typescript-styled-plugin", + }, + tsserver_file_preferences = { + completions = { + completeFunctionCalls = true, + }, + init_options = { + preferences = { + disableSuggestions = true, + }, + }, + includeInlayParameterNameHints = "all", + includeInlayEnumMemberValueHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayVariableTypeHints = true, + }, }, }, + keys = { + { "co", ft = ft, "TSToolsOrganizeImports", desc = "Organize Imports" }, + { "cR", ft = ft, "TSToolsRemoveUnusedImports", desc = "Remove Unused Imports" }, + { "cM", ft = ft, "TSToolsAddMissingImports", desc = "Add Missing Imports" }, + }, }, { "nvim-treesitter/nvim-treesitter", diff --git a/config/nvim/lua/plugins/extras/linting/stylelint.lua b/config/nvim/lua/plugins/extras/linting/stylelint.lua deleted file mode 100644 index c8c430ed..00000000 --- a/config/nvim/lua/plugins/extras/linting/stylelint.lua +++ /dev/null @@ -1,35 +0,0 @@ -local stylelint = "stylelint" - -return { - { - "williamboman/mason.nvim", - opts = function(_, opts) - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { stylelint }) - end, - }, - { - "mfussenegger/nvim-lint", - opts = function(_, opts) - local function add_linters(tbl) - for ft, linters in pairs(tbl) do - if opts.linters_by_ft[ft] == nil then - opts.linters_by_ft[ft] = linters - else - vim.list_extend(opts.linters_by_ft[ft], linters) - end - end - end - - add_linters({ - ["html"] = { "stylelint" }, - ["css"] = { "stylelint" }, - ["scss"] = { "stylelint" }, - ["sass"] = { "stylelint" }, - ["less"] = { "stylelint" }, - }) - - return opts - end, - }, -} diff --git a/config/nvim/lua/plugins/lualine.lua b/config/nvim/lua/plugins/lualine.lua index a10b9def..7f5e4300 100644 --- a/config/nvim/lua/plugins/lualine.lua +++ b/config/nvim/lua/plugins/lualine.lua @@ -1,3 +1,30 @@ +local lsp = function() + local buf_clients = vim.lsp.get_clients({ bufnr = 0 }) + if #buf_clients == 0 then + return "" + else + return " " + end +end + +local formatter = function() + local formatters = require("conform").list_formatters(0) + if #formatters == 0 then + return "" + else + return "󰛖 " + end +end + +local linter = function() + local linters = require("lint").linters_by_ft[vim.bo.filetype] + if #linters == 0 then + return "" + else + return "󱉶 " + end +end + return { "nvim-lualine/lualine.nvim", opts = function(_, opts) @@ -5,6 +32,9 @@ return { opts.options.section_separators = { left = "", right = "" } table.remove(opts.sections.lualine_x, 1) + table.insert(opts.sections.lualine_x, 2, lsp) + table.insert(opts.sections.lualine_x, 2, formatter) + table.insert(opts.sections.lualine_x, 2, linter) opts.sections.lualine_a = { { "mode", icon = "" } } opts.sections.lualine_y = { { "progress", icon = "", separator = " ", padding = { left = 1, right = 1 } } } opts.sections.lualine_z = { { "location", icon = "", padding = { left = 1, right = 1 } } }