JoosepAlviste / nvim-ts-context-commentstring

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
MIT License
1.18k stars 35 forks source link

Configure plugin via global variable #90

Closed Slotos closed 8 months ago

Slotos commented 1 year ago

This change allows setting vim.g.ts_context_commentstring_config somewhere in, for example, ~/.config/nvim/plugin/ts_commentstring_config.lua and have the plugin just work without any need to explicitly set it up.

The configuration is read when config.lua is loaded, e.g. on the first require('ts_context_commentstring.config').

Slotos commented 12 months ago

Type hints are a single @as annotation away. The great thing about annotations is that neovim startup process doesn’t freak out if they point at something unknown, whereas setup routine breaks if the plugin is not present.

Neovim's initialization process is a well documented routine - https://neovim.io/doc/user/starting.html#initialization. If you set the global variable in your local configuration, it precedes plugin loading.

The setup function is quite standard

It's definitely not. The name to require is decided by the plugin author. It's all about the folder and file names in lua directory - just as arbitrary.

Anyways, https://mrcjkb.dev/posts/2023-08-22-setup.html explains it better than I could. There's no need to call setup, and even then I made sure to keep it working.