feat(plugins): utilize ts_context_commentstring for all filetypes

This commit is contained in:
Matt Leong 2021-12-20 15:44:25 -08:00
parent 74a287d897
commit a957874880
2 changed files with 12 additions and 19 deletions

View file

@ -2,25 +2,17 @@ local config = require('cosmic.config')
require('Comment').setup(vim.tbl_deep_extend('force', { require('Comment').setup(vim.tbl_deep_extend('force', {
pre_hook = function(ctx) pre_hook = function(ctx)
-- Only calculate commentstring for tsx filetypes local U = require('Comment.utils')
if vim.bo.filetype == 'typescriptreact' then local location = nil
local U = require('Comment.utils') if ctx.ctype == U.ctype.block then
location = require('ts_context_commentstring.utils').get_cursor_location()
-- Detemine whether to use linewise or blockwise commentstring elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
local type = ctx.ctype == U.ctype.line and '__default' or '__multiline' location = require('ts_context_commentstring.utils').get_visual_start_location()
-- 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
return require('ts_context_commentstring.internal').calculate_commentstring({
key = ctx.ctype == U.ctype.line and '__default' or '__multiline',
location = location,
})
end, end,
}, config.comments or {})) }, config.comments or {}))

View file

@ -27,6 +27,7 @@ local defaults = {
}, },
context_commentstring = { context_commentstring = {
enable = true, enable = true,
enable_autocmd = false,
}, },
refactor = { refactor = {
highlight_definitions = { enable = true }, highlight_definitions = { enable = true },