From efb15a9c5537116b3817093899f0c77eacc2d33d Mon Sep 17 00:00:00 2001 From: Matt Leong Date: Tue, 7 Dec 2021 15:53:00 -0800 Subject: [PATCH] feat(plugins): switch to Comment.nvim --- lua/cosmic/config/examples/config.lua | 3 +++ lua/cosmic/core/pluginsInit.lua | 6 ++++-- lua/cosmic/plugins/comments/init.lua | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 lua/cosmic/plugins/comments/init.lua diff --git a/lua/cosmic/config/examples/config.lua b/lua/cosmic/config/examples/config.lua index 36d7cd9..2c4ca12 100644 --- a/lua/cosmic/config/examples/config.lua +++ b/lua/cosmic/config/examples/config.lua @@ -71,6 +71,9 @@ config.lsp = { -- See https://github.com/rmagatti/auto-session#%EF%B8%8F-configuration config.auto_session = {} +-- https://github.com/numToStr/Comment.nvim#configuration-optional +config.comments = {} + -- See https://github.com/folke/todo-comments.nvim#%EF%B8%8F-configuration config.todo_comments = {} diff --git a/lua/cosmic/core/pluginsInit.lua b/lua/cosmic/core/pluginsInit.lua index 8afbcfd..b44991a 100644 --- a/lua/cosmic/core/pluginsInit.lua +++ b/lua/cosmic/core/pluginsInit.lua @@ -225,9 +225,11 @@ return packer.startup(function() -- comments and stuff use({ - 'b3nj5m1n/kommentary', + 'numToStr/Comment.nvim', + config = function() + require('cosmic.plugins.comments') + end, event = 'BufWinEnter', - disable = vim.tbl_contains(user_plugins.disable, 'kommentary'), }) -- todo highlights diff --git a/lua/cosmic/plugins/comments/init.lua b/lua/cosmic/plugins/comments/init.lua new file mode 100644 index 0000000..6baafa1 --- /dev/null +++ b/lua/cosmic/plugins/comments/init.lua @@ -0,0 +1,26 @@ +local config = require('cosmic.config') + +require('Comment').setup(vim.tbl_deep_extend('force', { + pre_hook = function(ctx) + -- Only calculate commentstring for tsx filetypes + if vim.bo.filetype == 'typescriptreact' then + local U = require('Comment.utils') + + -- Detemine whether to use linewise or blockwise commentstring + local type = ctx.ctype == U.ctype.line and '__default' or '__multiline' + + -- Determine the location where to calculate commentstring from + local location = nil + if ctx.ctype == U.ctype.block then + location = require('ts_context_commentstring.utils').get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require('ts_context_commentstring.utils').get_visual_start_location() + end + + return require('ts_context_commentstring.internal').calculate_commentstring({ + key = type, + location = location, + }) + end + end, +}, config.comments or {}))