feat(plugins): switch to Comment.nvim

This commit is contained in:
Matt Leong 2021-12-07 15:53:00 -08:00
parent 0ffbbf00d9
commit efb15a9c55
3 changed files with 33 additions and 2 deletions

View file

@ -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 = {}

View file

@ -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

View file

@ -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 {}))