From a9578748806171a34f718da476d60ff7e45ecc30 Mon Sep 17 00:00:00 2001 From: Matt Leong Date: Mon, 20 Dec 2021 15:44:25 -0800 Subject: [PATCH] feat(plugins): utilize ts_context_commentstring for all filetypes --- lua/cosmic/plugins/comments/init.lua | 30 ++++++++++---------------- lua/cosmic/plugins/treesitter/init.lua | 1 + 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/lua/cosmic/plugins/comments/init.lua b/lua/cosmic/plugins/comments/init.lua index 6baafa1..ce4120b 100644 --- a/lua/cosmic/plugins/comments/init.lua +++ b/lua/cosmic/plugins/comments/init.lua @@ -2,25 +2,17 @@ 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, - }) + local U = require('Comment.utils') + 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 = ctx.ctype == U.ctype.line and '__default' or '__multiline', + location = location, + }) end, }, config.comments or {})) diff --git a/lua/cosmic/plugins/treesitter/init.lua b/lua/cosmic/plugins/treesitter/init.lua index b3ff7f0..6b2007e 100644 --- a/lua/cosmic/plugins/treesitter/init.lua +++ b/lua/cosmic/plugins/treesitter/init.lua @@ -27,6 +27,7 @@ local defaults = { }, context_commentstring = { enable = true, + enable_autocmd = false, }, refactor = { highlight_definitions = { enable = true },