From 54c2bb07828c8e11bfa8e26f5931060ac3402358 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Tue, 14 Dec 2021 18:04:23 -0500 Subject: [PATCH] add comments add comments --- init.lua | 1 + lua/user/comment.lua | 22 ++++++++++++++++++++++ lua/user/plugins.lua | 2 ++ lua/user/treesitter.lua | 8 ++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 lua/user/comment.lua diff --git a/init.lua b/init.lua index ff1e2e2..f1c864d 100644 --- a/init.lua +++ b/init.lua @@ -7,3 +7,4 @@ require "user.lsp" require "user.telescope" require "user.treesitter" require "user.autopairs" +require "user.comment" diff --git a/lua/user/comment.lua b/lua/user/comment.lua new file mode 100644 index 0000000..2fa4a56 --- /dev/null +++ b/lua/user/comment.lua @@ -0,0 +1,22 @@ +local status_ok, comment = pcall(require, "Comment") +if not status_ok then + return +end + +comment.setup { + pre_hook = function(ctx) + 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, +} diff --git a/lua/user/plugins.lua b/lua/user/plugins.lua index 74fcb73..3e2c87c 100644 --- a/lua/user/plugins.lua +++ b/lua/user/plugins.lua @@ -45,6 +45,7 @@ return packer.startup(function(use) use "nvim-lua/popup.nvim" -- An implementation of the Popup API from vim in Neovim use "nvim-lua/plenary.nvim" -- Useful lua functions used ny lots of plugins use "windwp/nvim-autopairs" -- Autopairs, integrates with both cmp and treesitter + use "numToStr/Comment.nvim" -- Easily comment stuff -- Colorschemes -- use "lunarvim/colorschemes" -- A bunch of colorschemes you can try out @@ -75,6 +76,7 @@ return packer.startup(function(use) "nvim-treesitter/nvim-treesitter", run = ":TSUpdate", } + use 'JoosepAlviste/nvim-ts-context-commentstring' -- Automatically set up your configuration after cloning packer.nvim -- Put this at the end after all plugins diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua index b5754d6..6f14cfc 100644 --- a/lua/user/treesitter.lua +++ b/lua/user/treesitter.lua @@ -8,12 +8,16 @@ configs.setup { sync_install = false, -- install languages synchronously (only applied to `ensure_installed`) ignore_install = { "" }, -- List of parsers to ignore installing autopairs = { - enable = true, - }, + enable = true, + }, highlight = { enable = true, -- false will disable the whole extension disable = { "" }, -- list of language that will be disabled additional_vim_regex_highlighting = true, }, indent = { enable = true, disable = { "yaml" } }, + context_commentstring = { + enable = true, + enable_autocmd = false, + }, }