GithubHelp home page GithubHelp logo

joosepalviste / nvim-ts-context-commentstring Goto Github PK

View Code? Open in Web Editor NEW
1.1K 1.1K 34.0 2.43 MB

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.

License: MIT License

Lua 96.90% Shell 3.10%
lua neovim neovim-plugin plugin tree-sitter treesitter

nvim-ts-context-commentstring's Introduction

Hi there ๐Ÿ‘‹

I'm Joosep, a full-stack developer from Estonia with an MSc in Computer Science from Uppsala University. Currently focusing more on front-end development.

Tech I'm comfortable with:

  • TypeScript TypeScript logo ๏ฝœ React React logo ๏ฝœ React Native React Native logo ๏ฝœ Vue Vue logo
  • Node.js Node.js logo ๏ฝœ Nest.js Nest.js logo
  • Python Python logo ๏ฝœ Django Django logo
  • GraphQL GraphQL logo ๏ฝœ Docker Docker logo

Some articles I've written:

ko-fi

nvim-ts-context-commentstring's People

Contributors

aaaaargzombies avatar andyrichardson avatar arthur-mountain avatar calops avatar dkirchhof avatar echasnovski avatar elianiva avatar felixnorden avatar gbprod avatar hood avatar jasonrhansen avatar jonjes avatar joosepalviste avatar josemarluedke avatar kyazdani42 avatar lilibyte avatar mortezadadgar avatar mrtnvgr avatar pbnj avatar peterhpchen avatar reegnz avatar rishabh672003 avatar seanbreckenridge avatar shiradofu avatar slotos avatar vladdoster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nvim-ts-context-commentstring's Issues

Can't get the plugin to work

I can't seem to get this plugin to work. This is my minimal config (not sure if nvim-lspconfig is necessary but I included it just in case):

call plug#begin('~/.config/nvim/packages/')
Plug 'neovim/nvim-lspconfig'
Plug 'kabouzeid/nvim-lspinstall'
Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' }
call plug#end()

lua << EOF
require('lspinstall').setup()
local servers = require('lspinstall').installed_servers()
for _, server in pairs(servers) do
  require'lspconfig'[server].setup({})
end

require('nvim-treesitter.configs').setup {
  ensure_installed = 'maintained',
  highlight = {
    enable = true,
  },
  context_commentstring = {
    enable = true
  }
}
EOF

Here's a file that I've tested the plugin on:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Test</title>
    <style>
      h1 {
        color: red;
      }
    </style>
  </head>
  <body>
    <script>
      console.log("hello");
    </script>
  </body>
</html>

On every line in the file, :echo &commentstring outputs <!--%s-->.

:TSInstallInfo says that html, javascript and css are installed.

Configurations for `commentary` and `kommentary` are not working

I tried to make commentary and kommentary plugins work with nvim-ts-context-commentstring using the configs described in the README of this repo, but it seems that commentstring is not updated each time I use the comment plugin.
Only nvim-comment plugin worked, the other two plugins work when enable_autocmd = true

Avoid needlessly calculating commentstring

Currently, this plugin is using CursorHold to trigger re-calculation of commentstring. This causes many unnecessary calculations that we could, in theory, avoid. We could try to only trigger this logic when the user inputs the mapping for commenting (e.g., gcc).

We could create our own mappings which would first update the commentstring and then trigger the commenting logic.

Toggling comment of a first line of JSX in a block does not work

If I comment out twice in tsx, it will behave strangely.

CleanShot 2021-06-03 at 00 59 55@2x
require("kommentary.config").configure_language("typescriptreact", {
    hook_function = function()
       pre_comment_hook = require('ts_context_commentstring.internal').update_commentstring()
    end,
    prefer_single_line_comments = true,
})

The issue is that if you comment the first line (only the first line) in any JSX block, then there will be a syntax error. For example, this is not valid JS/JSX:

const App = () => (
  {/* <div> */}
    <p>Hello world</p>
  </div>
)

Now, treesitter thinks that the first line of JSX with the comment is an object.

But I don't think that it's super high priority for now. I probably won't be dealing with it any time soon.

Initial issue from here: #10 (comment)

Comments inside <script> tags use <!-- -->

Treesitter parsers html and javascript are installed; the module is loaded:

TSConfigInfo (modules)

context_commentstring = {                                                                         
      disable = {},                                                                                   
      enable = true,                                                                                  
      enable_autocmd = false,                                                                         
      loaded = true,                                                                                  
      module_path = "ts_context_commentstring.internal"                                               
}

Demo

index.html after commenting:

<!DOCTYPE html>
<html lang="en">
  <script>
    <!-- console.log("foo"); -->
  </script>
</html>

Config

packer:

use 'JoosepAlviste/nvim-ts-context-commentstring'
use {
  'b3nj5m1n/kommentary',
  config = require("config.kommentary").config,
}

config/kommentary.lua:

local M = {}

function M.config()
  require('kommentary.config').configure_language('default', {
    prefer_single_line_comments = true,
  })

  local langs = require("kommentary.config").config -- all default supported langs
  for lang, _ in pairs(langs) do
    require('kommentary.config').configure_language(lang, {
        single_line_comment_string = 'auto',
        multi_line_comment_strings = 'auto',
        hook_function = function()
          require('ts_context_commentstring.internal').update_commentstring()
        end,
      })
  end
end

return M

config.nvim-treesitter.lua:

return function()
  require("nvim-treesitter.configs").setup {
    ensure_installed = {
      "html", "javascript",
    },
    context_commentstring = {
      enable = true,
      enable_autocmd = false, -- required for kommentary
    }
  }
end

Configure without tree-sitter

Thank you for creating this project! I am wondering if it is possible to configure it for languages that do not have Tree-sitter support. As someone who works with various programming languages, I have found that not all projects are compatible with Tree-sitter. Therefore, it would be incredibly helpful if this project could be configured to work with other languages as well.

If this is not currently possible, I completely understand. However, if it is feasible, I would greatly appreciate any guidance or resources you could provide to help me configure this.

Thank you again for your dedication to this project. I look forward to hearing back from you.

Best regards

Custom commentstring not working with Prolog

use {'JoosepAlviste/nvim-ts-context-commentstring',
	config = function()
		require'nvim-treesitter.configs'.setup {
			context_commentstring = {
				enable = true,
				config = {
					prolog = {
						__default = "%% %s",
					},
					vue = {
						__default = "/* %s  */",
						html = "<!-- %s -->",
						javascript = "// %s",
						script = "// %s",
						css = "/* %s */",
						comment = "<!-- %s -->",
					},
				}
			}
		}
	end 
}

So I have an autocmd that changes all *.pl file to be prolog, but my custom commentstring is not applied am I doing something wrong ?

echo &commentstring = #%s

Edit: It seems to be setting the commenstring but as soon as I press gcc it changes to the commentstring ... (see video)

Svelte commenting not working

Hey,

I know this plugin as built-in support for Svelte files but for some reason it is not using the right comment string for me on my svelte project. I am using 'b3nj5m1n/kommentary' plugin for commenting along. I have a config for JSX and it works fine though. Not sure what I am doing wrong as I could not find much info online on solving my issue so raising this issue here.
svelte-comment-error

Here is my config -
Treesitter - https://github.com/gitneeraj/dotfiles/blob/develop/nvim.lua/lua/modules/treesitter/init.lua
kommentary - https://github.com/gitneeraj/dotfiles/blob/develop/nvim.lua/lua/modules/commentString/init.lua

Any help much appreciated!

Cheers & Peace!

ts_context_commentstring.integrations.comment_nvim module not found

Environment

  • macOS catalina 10.15.7
  • Neovim NVIM v0.8.0-1210-gd367ed9b2

Question Description

Thank you very much for the plugin. I encountered a "ts_context_commentstring.integrations.comment_nvim not found" error during use, but I can find the module in the source code of the nvim-ts-context-commentstring plugin

image
image
image
image

Top-level jsx elements cannot be uncommented

comment-issue.mov

Problem

Commenting inner jsx elements works fine, but when doing it on the top-level element it only works the first time - every subsequent toggling just uses the default // comment.

Possible source

Did some digging - the function

function M.get_node_at_cursor_start_of_line(only_languages, winnr)

returns a <node jsx_opening_element> the first time and it correctly comments it out with {/* %s */}. When trying to uncomment, however, it returns a <node object>, possibly because it recognizes the { as the start of an object.
Hope this helps!

OptionSet autocmd not called by update_commentstring

I'm not sure if this is a bug in neovim or this plugin, but the following behavior is observed:

:au OptionSet commentstring :echo "Commentstring changed"
:lua vim.api.nvim_buf_set_option(0, 'commentstring', '-- %s')
" Outputs "Commentstring changed"
:lua require('ts_context_commentstring.internal').update_commentstring()
" Does not output nothing

How do I set commentstrings for c?

Would it be possible to set a commentstring for C? I use mini.comment with the update_commentstring function set up in the pre-hook. However, this does not allow me to set any commentstring through after/ftplugin/c.vim as this plugin overrides it whenever I do the comment.

I tried this, but it doesn't work:

        context_commentstring = {
          enable = true,
          enable_autocmd = false,
          config = {
            c = "//%s",
          },
        },

Can I set newlines in commentstrings?

I want my block comments for lua to be like this:

--[[
some commented-out text or code
--]]

So I thought it would be easy to just do something like this:

require("nvim-treesitter.config").setup{
    ...
    context_commentstring = {
	...
        config = {
            lua = {
                __default = "-- %s",
                __multiline = "--[[\n%s\n]]"
            },
        },
    },
}

but when commenting a block of code with Comment.nvim the newlines are replaced by spaces.

Am I doing something wrong, or is it just not possible to have newlines in a commentstring.

This is a link to the specific code in my dotfiles repo.

Can't make it work with Vue, Comment.nvim and lazy.nvim

Hey @JoosepAlviste!
Thanks for this great plugin, but I can't make work with Vue.
When I enter gcc, I always get <!-- --> comment regardless of location of my cursor:
Screenshot 2023-04-16 at 16 18 21

My init.lua config:

-- Set <space> as the leader key
-- See `:help mapleader`
--  NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

-- Install package manager
--    https://github.com/folke/lazy.nvim
--    `:help lazy.nvim.txt` for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system {
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable', -- latest stable release
    lazypath,
  }
end
vim.opt.rtp:prepend(lazypath)

-- NOTE: Here is where you install your plugins.
--  You can configure plugins using the `config` key.
--
--  You can also configure plugins after the setup call,
--    as they will be available in your neovim runtime.
require('lazy').setup({
  { -- Theme inspired by Atom
    'navarasu/onedark.nvim',
    cond = vim.g.vscode == nil,
    priority = 1000,
    config = function()
      vim.cmd.colorscheme 'onedark'
    end,
  },

  { -- Highlight, edit, and navigate code
    'nvim-treesitter/nvim-treesitter',
    dependencies = {
      'nvim-treesitter/nvim-treesitter-textobjects',
    },
    build = ":TSUpdate",
  },

  -- "gc" to comment visual regions/lines
  {
    'numToStr/Comment.nvim',
    opts = function() return { pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook() } end,
    dependencies = { 'JoosepAlviste/nvim-ts-context-commentstring' },
  },


  -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
  --       These are some example plugins that I've included in the kickstart repository.
  --       Uncomment any of the lines below to enable them.
  -- require 'kickstart.plugins.autoformat',
  -- require 'kickstart.plugins.debug',
  -- NOTE: The import below automatically adds your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
  --    You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
  --    up-to-date with whatever is in the kickstart repo.
  --
  --    For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
  --
  --    An additional note is that if you only copied in the `init.lua`, you can just comment this line
  --    to get rid of the warning telling you that there are not plugins in `lua/custom/plugins/`.
  { import = 'custom.plugins' },
}, {})

-- [[ Setting options ]]
-- See `:help vim.o`

vim.o.breakindent = true -- Enable break indent
vim.o.clipboard = 'unnamedplus' -- Use the OS clipboard by default
vim.o.encoding = 'utf-8'
vim.o.ff = 'unix' -- Unix end of file
vim.o.hlsearch = true -- Set highlight on search
vim.o.ignorecase = true -- Search case insensitive...
vim.o.smartcase = true  -- ... but only when it does not begin with upper case
vim.o.incsearch = true -- Shows the match while typing
vim.o.noswapfile = true -- No swp files
vim.o.shiftwidth = 2 -- Number of spaces inserted for indentation
vim.o.softtabstop = 2 -- Number of columns that will be added when you hit Tab in insert mode
vim.o.splitright = true -- Puts new vsplit windows to the right of the current
vim.o.splitbelow = true -- Puts new split windows to the bottom of the current
vim.o.undofile = true -- Save undo history

if vim.g.vscode == nil then
  vim.o.autoindent = true
  vim.o.expandtab = true -- Insert space characters whenever the tab key is pressed
  vim.o.mouse = 'a' -- Enable mouse mode
  vim.o.number = true -- Make line numbers default
  vim.o.relativenumber = true
  vim.o.tabstop = 2 -- Number of columns a tab counts for
  vim.o.termguicolors = true
end

-- Decrease update time
vim.o.updatetime = 250
vim.o.timeout = true
vim.o.timeoutlen = 300

-- Delete all trailing whitespaces on save
if vim.g.vscode == nil then
  vim.o.showbreak = "\\ \\ \\"
  vim.api.nvim_create_autocmd("BufWritePre", {
      pattern = { "*" },
      command = ":%s/\\s\\+$//e",
  })
end


-- [[ Basic Keymaps ]]

-- Keymaps for better default experience
-- See `:help vim.keymap.set()`
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })

-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })

-- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
  callback = function()
    vim.highlight.on_yank()
  end,
  group = highlight_group,
  pattern = '*',
})

-- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter`
require'nvim-treesitter.configs'.setup {
  context_commentstring = {
    enable = true,
    enable_autocmd = false,
  },

  -- Add languages to be installed here that you want installed for treesitter
  ensure_installed = { 'go', 'lua',  'tsx', 'typescript', 'vimdoc', 'vue', 'vim' },
}

NVIM v0.9.0

Would be great if you can help me ๐Ÿ™

[Feature Request] Support Astro

Astro is a web framework. It has its own file type .astro.

https://astro.build/

It can be set up by the following:

require'nvim-treesitter.configs'.setup {
  context_commentstring = {
    enable = true,
    config = {
      astro = '<!-- %s -->'
    }
  }
}

Can you support it by default? I would love to send a pull request for this change if you need it.

trouble getting this to work with jsx

This is my config:

  {
    'nvim-treesitter/nvim-treesitter',
    dependencies = {
      'JoosepAlviste/nvim-ts-context-commentstring',
    },

    build = function()
      pcall(require('nvim-treesitter.install').update { with_sync = true })
    end,

    config = function()
      require('nvim-treesitter.configs').setup {
        ensure_installed = {
          'json', 'query', 'tsx', 'yaml', 'c', 'html', 'javascript', 'lua', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'vimdoc', 'vim', 'regex', 'bash', 'css', 'scss',
        },

        -- Install parsers synchronously (only applied to `ensure_installed`)
        sync_install = false,

        -- Automatically install missing parsers when entering buffer
        -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
        auto_install = false,

        highlight = {
          enable = true,

          ------------------------------------------------------------------------------
          -- !!! THIS IS WHAT MAKES MARKDOWN HEADINGS H1 ABLE TO BE DIFFERENT COLORS: !!
          ------------------------------------------------------------------------------
          disable = { "markdown" },

          additional_vim_regex_highlighting = false,

        },

        context_commentstring = {
          enable = true,
        },

      }
    end
  },

Is there something I am missing?

Error in javascript file

no matter where I am in a javascript file, the following error constantly pops up:

Error detected while processing CursorHold Autocommands for "<buffer=48>":
E5108: Error executing lua ...-commentstring/lua/ts_context_commentstring/internal.lua:72: attempt to index local 'language_tree' (a nil value)

BREAKING CHANGES

The comments of this issue will include all breaking changes together with migration guides.

Please open a separate issue if there are any issues following the migration guides. I'd like to keep this thread clean so that it would be easy to find information for everyone.

tsx is not properly commenting

Minimal reproducible full config

packer.lua

  use {
    'nvim-treesitter/nvim-treesitter',
    run = ':TSUpdate'
  }
....
  use {
    'numToStr/Comment.nvim',
    requires = {
      -- jx/tsx comment support
      'JoosepAlviste/nvim-ts-context-commentstring'
    }
  }

treesitter.lua

require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all"
  ensure_installed = { "vimdoc", "javascript", "typescript", "lua", "rust", "java"},

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,

  highlight = {
    -- `false` will disable the whole extension
    enable = true,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
  -- https://github.com/JoosepAlviste/nvim-ts-context-commentstring#commentnvim
  context_commentstring = {
    enable = true,
    enable_autocmd = false,
  }
}

comment.lua

require('Comment').setup {
  pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
}

Description

Hi,

I am trying to make comments work in tsx files, but they end up being commented with forward slashes:
image

I am using Comment.nvim and its integration with nvim-ts-context-commentstring

When I run :lua print(require('ts_context_commentstring.internal').calculate_commentstring()) I get nil:

I hope you can point my issue given the config shown above

Steps to reproduce

Setup neovim with the config provided above

Expected behavior

I expect typescript files to be commented properly

Actual behavior

tsx is being commented with two forward slashes

Additional context

No response

Handle injected languages with language tree

It seems like we could improve the logic for injected languages by using language tree to query the language for the current node. For example, if the cursor is inside an HTML node (which is injected into another language), then we could set commentstring to <!-- %s -->.

The only configuration we would need would be the commentstring for each language:

local conf = {
  css = '/* %s */',
  html = '<!-- %s -->',
  javascript = '// %s',
  -- ...
}

Then, injected languages should automatically work in all cases.

However, I'm not sure how JSX style comments would work since JSX isn't an injected language.

Idea from this Reddit comment: https://www.reddit.com/r/neovim/comments/md5mym/treesitter_plugin_for_dynamically_setting/gs82lbv?utm_source=share&utm_medium=web2x&context=3

does not work correctly for vim inside lua

I am using nvim 0.6.0 release. I have installed nvim-treesitter (lua, viml parsers are installed), commentary.vim, and this plugin.

This is my config for treesitter:

require("nvim-treesitter.configs").setup({
  ensure_installed = {"python", "cpp", "lua", "vim"},
  ignore_install = {}, -- List of parsers to ignore installing
  highlight = {
    enable = true, -- false will disable the whole extension
    disable = {}, -- list of language that will be disabled
  },
  context_commentstring = {
    enable = true,
    -- enable_autocmd = false,
   config = {
      vim = '" %s',
    }
  }
})

When commenting viml inside lua, my test code is:

    vim.cmd([[
      hi link LspReferenceRead Visual
      hi link LspReferenceText Visual
      hi link LspReferenceWrite Visual
      augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]])

the comment string is still --, not ", is this supported or am I doing it wrong?

Wrong commentstring inside JSX spread element

The commentstring for a spread element inside of a JSX block is the default JSX {/* */} comment.

For example, if I have the following JSX element

<div {...{
    id: "testo"
}}/>

and attempt to comment toggle the id attribute line using terrortylor/nvim-comment, I get

<div {...{
    {/* id: "testo" */}
}}/>

which is not valid JSX.

Instead, I should get a normal JavaScript style comment.

<div {...{
    // id: "testo"
}}/>

Error when nvim-treesitter is added as opt package in packer

Hi, thanks for the awesome plugin. Neovim shows an error when nvim-treesitter is made an optional package in packer.nvim.

Here's the error message
image

Relevant Packer config
image

Treesitter config

vim.cmd[[packadd nvim-treesitter]]

local ts_config = require('nvim-treesitter.configs')

ts_config.setup({
  -- ensure_installed = 'maintained',
  highlight = { enable = true },
  incremental_selection = { enable = true },
  indent = { enable = true },

  context_commentstring = { enable = true },

})

[Feature request]ย disabling per filetype

I would really like to disable this only in certain filetypes. The reason for this is because for example in C, I would like to be able to toggle between the two commentstrings on the go.

How to setup comment strings with neovim treesitter and commentstring?

I've been trying to figure out how to setup commentstring for a php file.

I'm trying Treesitterplayground to get information, but have no luck setting up correct comment style.

What is the procedure to find out that info?

image

plugins:

Plug 'tpope/vim-commentary'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}  
Plug 'nvim-treesitter/playground'
Plug 'JoosepAlviste/nvim-ts-context-commentstring'

treesitter config:

if (has("nvim"))
lua <<EOF
require'nvim-treesitter.configs'.setup {
  ensure_installed ={ "javascript", "json", "css", "php", "html", "python", "bash", "regex", "ruby", "yaml", "jsonc", "tsx", "lua", "vue" }, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
  highlight = {
    enable = true,
  },
  indent = {
    enable = false
  },
  context_commentstring = {
    enable = true,
    config = {
    php = {
      element = "XXXX %s ",
      start_tag = "YYYYYYY %s zzz",
      attribute = "ZZZZZZz %s zzz",
      html = "111111 %s zzz"
    }
    }
  },
  playground = {
    enable = true,
    disable = {},
    updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
    persist_queries = false, -- Whether the query persists across vim sessions
    keybindings = {
      toggle_query_editor = 'o',
      toggle_hl_groups = 'i',
      toggle_injected_languages = 't',
      toggle_anonymous_nodes = 'a',
      toggle_language_display = 'I',
      focus_language = 'f',
      unfocus_language = 'F',
      update = 'R',
      goto_node = '<cr>',
      show_help = '?',
    },
  }
}
EOF
endif

Unable To Multiline Comment `typescriptreact` Through Comment.nvim

I have followed the setup guide using Comment.nvim

Comment.nvim

local status_ok, comment = pcall(require, "Comment")
if not status_ok then
  return
end

comment.setup {
    pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook()
}

Treesitter.nvim

local status_ok, configs = pcall(require, "nvim-treesitter.configs")
if not status_ok then
	return
end

configs.setup({
	ensure_installed = "all", -- one of "all", "maintained", or list of languages.
	sync_install = false, -- install languages synchronously
	ignore_install = { "" }, -- List of parsers to ignore installing
	highlight = {
		enable = true, --  false will disable whole extension
		disable = { "" },
		additional_vim_regex_highlighting = true,
	},
	indent = { enable = true, disable = { "yaml" } },
	autopairs = {
		enable = true,
	},
	context_commentstring = {
		enable = true,
		enable_autocmd = false,
	},
})

From everything I have been reading, this is really all that is needed to get going with the plugin. However when I try to do any Visual Line comments i'll get // and Visual Block comments give me a /* */, so it appears to be missing the curly braces. I have also configured Tree Sitter to pick up the context_commentstring, but still not working.

It seems like it won't accept the tsx nodes at all, even if I modify the config option of context_commentstring to include tsx.

I am not sure what I can provide to help diagnose the issue, but happy to upon request.

Option 'commentstring' is empty in .swift file

lazy-lock.json

{
  "LazyVim": { "branch": "main", "commit": "3b4c27e6a66fea8a248523f6ba95b51e4f66702f" },
  "LuaSnip": { "branch": "master", "commit": "a83e4b1ba7edc6fecdad09e39753a7d5eee1d01c" },
  "SchemaStore.nvim": { "branch": "main", "commit": "2d0b27ad28443cb700835b0d6a404ffe7f29c731" },
  "alpha-nvim": { "branch": "main", "commit": "1838ae926e8d49fe5330d1498ee8289ae2c340bc" },
  "bufferline.nvim": { "branch": "main", "commit": "32d74d5d044f7cc89892d4781a83d55ee4ed552a" },
  "catppuccin": { "branch": "main", "commit": "c9cc5a997f1dae3f35b4bdd62f35958fee363ab4" },
  "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
  "cmp-nvim-lsp": { "branch": "main", "commit": "0e6b2ed705ddcff9738ec4ea838141654f12eeef" },
  "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
  "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
  "dressing.nvim": { "branch": "master", "commit": "f19cbd56f7f8cad212c58a7285d09c5d9c273896" },
  "flit.nvim": { "branch": "main", "commit": "f60e4b3d49bb5a5e97cfffe66f2e671eb422078e" },
  "friendly-snippets": { "branch": "main", "commit": "8875cccf779160303bf2bed7d422717676f214fd" },
  "gitsigns.nvim": { "branch": "main", "commit": "f868d82a36f7f7f5e110eb0a9659993984f59875" },
  "indent-blankline.nvim": { "branch": "master", "commit": "ceaf730b13e332cd76600d9795722413c236c684" },
  "lazy.nvim": { "branch": "main", "commit": "ebdd0499551765e6a7aba220cc8ae4e0cdb6be69" },
  "leap.nvim": { "branch": "main", "commit": "be918a8e6aa00a6cfa7270d4bfcc11b2f80d6902" },
  "lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" },
  "mason-lspconfig.nvim": { "branch": "main", "commit": "f0ce33f4794a2364eb08d09d09380e8b04ec5e6a" },
  "mason.nvim": { "branch": "main", "commit": "7d7efc738e08fc5bee822857db45cb6103f0b0c1" },
  "mini.ai": { "branch": "main", "commit": "44d7df1340b16b16b27b67fba07028cb57f45408" },
  "mini.bufremove": { "branch": "main", "commit": "14805473144fffbd019d07e51bed2d176e065ee9" },
  "mini.comment": { "branch": "main", "commit": "877acea5b2a32ff55f808fc0ebe9aa898648318c" },
  "mini.indentscope": { "branch": "main", "commit": "f60e9b51a6214c73a170ffc5445ce91560981031" },
  "neo-tree.nvim": { "branch": "v2.x", "commit": "8c89efb93b8383666a6f989762c2f610f5f2c930" },
  "neoconf.nvim": { "branch": "main", "commit": "279c27f418f35397fe5b913d9d61d529cc038493" },
  "neodev.nvim": { "branch": "main", "commit": "f270d279fd314e9a41f4a7f727cf8b4dd680dc7f" },
  "noice.nvim": { "branch": "main", "commit": "7e358170cea2314d9768b3f63616e8fad186195e" },
  "nui.nvim": { "branch": "main", "commit": "2b2732528e4a79eb8542568bd51d25f710395bd6" },
  "null-ls.nvim": { "branch": "main", "commit": "4b055d84be42c90a7240785d3c83340d259d3d46" },
  "nvim-cmp": { "branch": "main", "commit": "b43bfaf3229d6b39d8baaa567b13c6be0623bf12" },
  "nvim-lspconfig": { "branch": "master", "commit": "9166622781a39a829878d1fd24c174529d996838" },
  "nvim-navic": { "branch": "master", "commit": "15704c607569d6c5cfeab486d3ef9459645a70ce" },
  "nvim-notify": { "branch": "master", "commit": "ea9c8ce7a37f2238f934e087c255758659948e0f" },
  "nvim-spectre": { "branch": "master", "commit": "1abe23ec9b7bc3082164f4cb842d521ef70e080e" },
  "nvim-surround": { "branch": "main", "commit": "211eaad7c6d01ef4ac02cba9052b3082ec232101" },
  "nvim-treesitter": { "branch": "master", "commit": "905877e75f91790b693e8154ccfc10e3d4fc05a3" },
  "nvim-treesitter-textobjects": { "branch": "master", "commit": "95b76b95eff25e1e64f363938cd853852355d70a" },
  "nvim-ts-context-commentstring": { "branch": "main", "commit": "0bf8fbc2ca8f8cdb6efbd0a9e32740d7a991e4c3" },
  "nvim-web-devicons": { "branch": "master", "commit": "2a125024a137677930efcfdf720f205504c97268" },
  "persistence.nvim": { "branch": "main", "commit": "4b8051c01f696d8849a5cb8afa9767be8db16e40" },
  "plenary.nvim": { "branch": "master", "commit": "52544825d6b8be677eb395983515ad5e30ae1f2e" },
  "tailwindcss-colorizer-cmp.nvim": { "branch": "main", "commit": "65565c62963579897d28390dbd1ba8fb15ba545f" },
  "telescope.nvim": { "branch": "master", "commit": "6d3fbffe426794296a77bb0b37b6ae0f4f14f807" },
  "todo-comments.nvim": { "branch": "main", "commit": "09b0b17d824d2d56f02ff15967e8a2499a89c731" },
  "tokyonight.nvim": { "branch": "main", "commit": "cd5156f4b4a6c4c337a46deb0c0bd37319920833" },
  "trouble.nvim": { "branch": "main", "commit": "324c977cfeacb8498ca9ba1c74cc35bd18858a8d" },
  "typescript.nvim": { "branch": "main", "commit": "f66d4472606cb24615dfb7dbc6557e779d177624" },
  "undotree": { "branch": "master", "commit": "485f01efde4e22cb1ce547b9e8c9238f36566f21" },
  "vim-illuminate": { "branch": "master", "commit": "a2907275a6899c570d16e95b9db5fd921c167502" },
  "vim-repeat": { "branch": "master", "commit": "24afe922e6a05891756ecf331f39a1f6743d3d5a" },
  "vim-ripgrep": { "branch": "master", "commit": "2bb2425387b449a0cd65a54ceb85e123d7a320b8" },
  "vim-startuptime": { "branch": "master", "commit": "8eed46917c5c4882b295729ce053265c2a74ac4d" },
  "which-key.nvim": { "branch": "main", "commit": "e271c28118998c93a14d189af3395812a1aa646c" }
}

Description

gcc on a line in a .swift file shows error "option 'commentstring' is empty"

I'm using lazyvim.org Neovim which comes with mini.comment. Is swift not supported? I'm sure I'm missing something stupid.

Steps to reproduce

:e somefile.swift
gcc to comment line

Expected behavior

comment line

Actual behavior

option 'commentstring' is empty

Additional context

No response

Vue comment not working properly

Minimal reproducible full config

-- Your configuration here

Description

I found a weird issue. If a vue file contains a empty <style> block, commenting will not work properly. Like this:
image
You can see all the comments start with //.

If I remove the empty <style> block or write some styles in the block, it will work fine. Like this:
image
You can see the <style> block was removed, and the comments in <template> and <script> work fine.

image
When I write some styles in <style> block, it works also.

Steps to reproduce

See above

Expected behavior

See above

Actual behavior

See above

Additional context

No response

This plugin doesn't set the `comments` var.

From :h comments

                                          'comments' 'com' E524 E525
  'comments' 'com'        string  (default
                                  "s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-")
                          local to buffer
          A comma-separated list of strings that can start a comment line.  See
          format-comments.  See option-backslash about using backslashes to
          insert a space.

                                          'commentstring' 'cms' E537
  'commentstring' 'cms'   string  (default "")
                          local to buffer
          A template for a comment.  The "%s" in the value is replaced with the
          comment text.  Currently only used to add markers for folding, see
          fold-marker.

This plugin should also set the comments var. That way OG plugins like https://github.com/glts/vim-textobj-comment will also work.

Block mode commenting not working with Comment.nvim

I added the config mentioned in the readme for Comment.nvim, all seems to work good except block uncommenting.

Please see the following capture:

Screen.Recording.mp4

Should I add a special post_hook or something?

mini.comment integration pre hook - require("ts_context_commentstring.internal").update_commentstring() requires 1 argument

I'm trying to set the pre hook for mini.comment per the instructions on the wiki for Integrations. My LSP is telling me that require("ts_context_commentstring.internal").update_commentstring()

requires 1 argument(s) but instead it is receiving 0.

Ignoring that warning doesn't cause any error messages when loading my plugins, but it does not seem to update the comment string as expected (it leaves it unchanged).

I'm using the LazyVim distribution, so it may be some plugin configuration issue on my end. But I just wanted to double check that wiki Integration page is still correct for mini.comment before asking for help on the LazyVim discussion board.

Allow configuring tree traversal start location

Original issue / problem: numToStr/Comment.nvim#10 (comment)

Add a way to customize the location where the treesitter tree traversal is started (currently only on the first non-blank char on the cursor's line). This would make it possible to comment something like this in JSX when running gciW:

<View /* style={styles.foobar} */ />

I think that it would make sense if update_commentstring would accept the position as an argument. If nothing passed in, then the cursor start of line, but if there is some location passed in, then we can use that one. For example, the Comment.nvim integration can use getpos("'<") to get the visual selection start location instead of the cursor location. Or if there's no visual selection, then for the above example use the cursor location (or motion start location somehow?).

Confused on how to integrate this with lua inside init.vim

Hello, so for some capability issues I have in my init.vim snippets like this:

function! FilePath() abort
    " stuff
endfunction

lua <<EOF
-- more stuff
EOF

However, whenever I try to comment stuff inside the lua snippets I get the commentstring to still be \"%s. Is there anyway, I can use this plugin to handle this situation. I'm frankly a bit confused.

Context comments are not working for tsx files

Problem

For tsx files context comment string are commenting jsx element as "//":

export const Test = () => {
  return (
    <div>
      // <h1>What's up</h1>
    </div>
  );
};

jsx files are working fine with context commenting:

export const Test = () => {
  return (
    <div>
      {/* <h1>What's up</h1> */}
    </div>
  );
};

I am using nvim-ts-context-commentstring with numToStr/Comment.nvim integration.

module 'ts-context-com mentstring.integrations.comment_nvim' not found:

Minimal reproducible full config

{
    "nvim-treesitter/nvim-treesitter",
     lazy = true,
     event = "BufRead",
     dependencies = {
       "p00f/nvim-ts-rainbow",
       "JoosepAlviste/nvim-ts-context-commentstring",
     },
     config = function()
      require("configs.ui.treesitter")
   end,
},
{
  "numToStr/Comment.nvim",
   keys = { { "gc", mode = { "n", "v" }, "gcc"}, { "gb", mode = { "n", "v" } } },
   lazy = true,
  config = function()
    require("Comment").setup {
       pre_hook = require("ts-context-commentstring.integrations.comment_nvim").create_pre_hook(),
   }
end,
},

Description

how to correct setup ?

Steps to reproduce

try goggle it and not any match of my issue

Expected behavior

i just wanna comment jsx file

Actual behavior

.

Additional context

No response

[Question] Plugin to load server by context

Many thanks for this great plugin.

I was wondering if this plugin is possible, it should also be also possible to load lsp servers per treessiter context.
For example, in tsx, if we are in the markup we should be able to load the HTML and emmet servers, likewise inside
some CSS, or even if we are in an attribute of the tag, like the string in the class attribute, load the tailwind server.

I know this is not the scope of this plugin but because you are kind of doing something similar I was wondering if this would be at all possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.